public void InitilaiseConverters()
 {
     _basicRequest = new ItkDispatchRequest()
     {
         Authentication = new Authentication()
         {
             Password = "******",
             UserName = "******"
         },
         PatientDetails = new PatientDetails()
         {
             DateOfBirth = new DateTime(1980, 1, 1),
             Forename    = "PatientForename",
             Surname     = "PatientSurname",
             Gender      = "Male",
             GpPractice  = new GpPractice()
             {
                 Address = new Address()
                 {
                     StreetAddressLine1 = "1 test lane",
                     PostalCode         = "TS1 6TH"
                 },
                 Name      = "Test GP Practice",
                 Ods       = "RA286",
                 Telephone = "02380555555"
             },
             HomeAddress = new Address()
             {
                 StreetAddressLine1 = "1 home lane",
                 PostalCode         = "HS1 6HH"
             },
             ServiceAddressPostcode = "SV10 6YY",
             TelephoneNumber        = "02380666666"
         },
         ServiceDetails = new ServiceDetails()
         {
             Id       = "1234",
             Name     = "TestSurgery",
             PostCode = "TT22 5TT"
         },
         CaseDetails = new CaseDetails()
         {
             DispositionCode = "Dx123",
             DispositionName = "Test Disposition"
         }
     };
     //AppDomain.CurrentDomain.GetAssemblies();
     _config = new MapperConfiguration(cfg =>
     {
         cfg.AddProfile(new FromItkDispatchRequestToSubmitHaScToService());
         cfg.AddProfile(new FromItkDispatchRequestToSubmitEncounterToServiceRequest());
     });
     _mapper = _config.CreateMapper();
 }
예제 #2
0
        public async Task <ItkDispatchResponse> SendItkMessage(ItkDispatchRequest request)
        {
            _logger.Info(string.Format("Request received of JourneyId {0} and external ref {1}", request.CaseDetails.JourneyId, request.CaseDetails.ExternalReference));

            request.CaseDetails.ExternalReference = _patientReferenceService.BuildReference(request.CaseDetails);

            var messageExists = _messageService.MessageAlreadyExists(request.CaseDetails.JourneyId, JsonConvert.SerializeObject(request));

            if (messageExists)
            {
                _logger.Error(string.Format("Duplicate Case sent of JourneyId {0} and external ref {1}", request.CaseDetails.JourneyId, request.CaseDetails.ExternalReference));

                return(_itkDispatchResponseBuilder.Build(new DuplicateMessageException(request.CaseDetails.ExternalReference)));
            }

            var submitHaSCToService = AutoMapperWebConfiguration.Mapper.Map <ItkDispatchRequest, SubmitHaSCToService>(request);

#if DEBUG
            var xsSubmit = new XmlSerializer(typeof(SubmitHaSCToService));
            using (var sww = new StringWriter())
            {
                using (var writer = XmlWriter.Create(sww))
                {
                    xsSubmit.Serialize(writer, submitHaSCToService);
                    var xml = sww.ToString();
                }
            }
#endif
            SubmitHaSCToServiceResponse itkResponse;

            try {
                itkResponse = await _itkDispatcher.SubmitHaSCToServiceAsync(submitHaSCToService);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Send to ESB error for journeyId {0} and external Ref {1}", request.CaseDetails.JourneyId, request.CaseDetails.ExternalReference), ex);

                return(_itkDispatchResponseBuilder.Build(ex));
            }

            var response = _itkDispatchResponseBuilder.Build(itkResponse, request.CaseDetails.ExternalReference);

            if (response.IsSuccessStatusCode)
            {
                _messageService.StoreMessage(request.CaseDetails.JourneyId, JsonConvert.SerializeObject(request));
            }

            return(response);
        }
        public void Map_ITKDispatchRequest_To_SubmitEncounterToServiceRequest_informant_notspecified()
        {
            var dispatchRequest = new ItkDispatchRequest()
            {
                PatientDetails = new PatientDetails()
                {
                    Informant = new InformantDetails()
                    {
                        Type     = InformantType.NotSpecified,
                        Forename = "someone",
                        Surname  = "else"
                    }
                }
            };

            var result = _mapper.Map <ItkDispatchRequest, SubmitEncounterToServiceRequest>(dispatchRequest);

            Assert.AreEqual(informantType.NotSpecified, result.PatientDetails.InformantType);
            Assert.AreEqual(string.Format("{0} {1}", dispatchRequest.PatientDetails.Informant.Forename, dispatchRequest.PatientDetails.Informant.Surname), result.PatientDetails.InformantName);
        }
        public void Map_ITKDispatchRequest_To_SubmitEncounterToServiceRequest()
        {
            var dispatchRequest = new ItkDispatchRequest()
            {
                Authentication = new Authentication()
                {
                    Password = "******",
                    UserName = "******"
                },
                PatientDetails = new PatientDetails()
                {
                    DateOfBirth = new DateTime(1980, 11, 30),
                    Forename    = TEST_PATIENT_FORENAME,
                    Surname     = TEST_PATIENT_SURNAME,
                    Gender      = "Female",
                    AgeGroup    = "Adult",
                    GpPractice  = new GpPractice()
                    {
                        Address = new Address()
                        {
                            StreetAddressLine1 = TEST_GP_STREETADDRESS,
                            PostalCode         = TEST_GP_POSTCODE
                        },
                        Name      = "Test GP Practice",
                        Ods       = TEST_GP_ODS_CODE,
                        Telephone = TEST_GP_TELEPHONE
                    },
                    CurrentAddress = new Address()
                    {
                        StreetAddressLine1 = TEST_PATIENT_CURRENT_STREETADDRESS,
                        PostalCode         = TEST_PATIENT_CURRENT_POSTCODE
                    },
                    HomeAddress = new Address()
                    {
                        StreetAddressLine1 = TEST_PATIENT_HOME_STREETADDRESS,
                        PostalCode         = TEST_PATIENT_HOME_POSTCODE
                    },
                    ServiceAddressPostcode = "SV10 6YY",
                    TelephoneNumber        = TEST_PHONE_NUMBER
                },
                ServiceDetails = new ServiceDetails()
                {
                    Id       = DOS_SERVICE_ID.ToString(),
                    Name     = "TestSurgery",
                    PostCode = "TT22 5TT",
                    OdsCode  = TEST_SERVICE_ODS_CODE
                },
                CaseDetails = new CaseDetails()
                {
                    ExternalReference    = TEST_EXTERNAL_REF,
                    DispositionCode      = TEST_DX_CODE,
                    DispositionName      = TEST_DX_NAME,
                    StartingPathwayTitle = TEST_CONDITION,
                    StartingPathwayId    = TEST_CONDITIONID,
                    StartingPathwayType  = TEST_CONDITIONTYPE,
                    SetVariables         = TestSetVariables
                }
            };

            var result = _mapper.Map <ItkDispatchRequest, SubmitEncounterToServiceRequest>(dispatchRequest);

            Assert.IsNotNull(result);
            Assert.IsNotNull(result.PatientDetails);
            Assert.IsNotNull(result.ServiceDetails);

            Assert.AreEqual(result.PatientDetails.TelephoneNumber, TEST_PHONE_NUMBER);
            Assert.AreEqual(result.PatientDetails.Forename, TEST_PATIENT_FORENAME);
            Assert.AreEqual(result.PatientDetails.Surname, TEST_PATIENT_SURNAME);
            Assert.AreEqual(result.PatientDetails.Gender, gender.Female);
            Assert.AreEqual(result.PatientDetails.AgeGroup, "Adult");
            Assert.AreEqual(result.PatientDetails.DateOfBirth.Item, "1980-11-30");

            Assert.AreEqual(result.PatientDetails.InformantType, informantType.Self);

            Assert.AreEqual(result.PatientDetails.CurrentAddress.PostalCode, TEST_PATIENT_CURRENT_POSTCODE);
            Assert.AreEqual(result.PatientDetails.CurrentAddress.StreetAddressLine1, TEST_PATIENT_CURRENT_STREETADDRESS);

            Assert.AreEqual(result.PatientDetails.HomeAddress.PostalCode, TEST_PATIENT_HOME_POSTCODE);
            Assert.AreEqual(result.PatientDetails.HomeAddress.StreetAddressLine1, TEST_PATIENT_HOME_STREETADDRESS);

            Assert.AreEqual(result.PatientDetails.GpPractice.Address.PostalCode, TEST_GP_POSTCODE);
            Assert.AreEqual(result.PatientDetails.GpPractice.Address.StreetAddressLine1, TEST_GP_STREETADDRESS);

            Assert.AreEqual(result.PatientDetails.GpPractice.Telephone, TEST_GP_TELEPHONE);
            Assert.AreEqual(result.PatientDetails.GpPractice.ODS, TEST_GP_ODS_CODE);

            Assert.AreEqual(result.ServiceDetails.id, DOS_SERVICE_ID);
            Assert.AreEqual(result.ServiceDetails.odsCode, TEST_SERVICE_ODS_CODE);

            Assert.AreEqual(result.CaseDetails.ExternalReference, TEST_EXTERNAL_REF);
            Assert.AreEqual(result.CaseDetails.DispositionCode, TEST_DX_CODE);
            Assert.AreEqual(result.CaseDetails.DispositionName, TEST_DX_NAME);
            Assert.AreEqual(result.CaseDetails.conditionTitle, TEST_CONDITION);
            Assert.AreEqual(result.CaseDetails.conditionId, TEST_CONDITIONID);
            Assert.AreEqual(result.CaseDetails.conditionType, TEST_CONDITIONTYPE);
            Assert.AreEqual(result.CaseDetails.UnstructuredData, JsonConvert.SerializeObject(TestSetVariables));
        }