/// <summary>
        /// Gets the patient record.
        /// </summary>
        /// <param name="hdid">The patient id.</param>
        /// <returns>The patient model.</returns>
        public async System.Threading.Tasks.Task <Patient> GetPatient(string hdid)
        {
            // Create request
            HCIM_IN_GetDemographics request = this.CreateRequest(hdid);

            // Perform the request
            HCIM_IN_GetDemographicsResponse1 reply = await this.getDemographicsClient.HCIM_IN_GetDemographicsAsync(request).ConfigureAwait(true);

            // Verify that the reply contains a result
            string responseCode = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.queryAck.queryResponseCode.code;

            if (responseCode.Contains("BCHCIM.GD.0.0013", System.StringComparison.InvariantCulture))
            {
                HCIM_IN_GetDemographicsResponseIdentifiedPerson retrievedPerson = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.subject[0].target;

                // Extract the subject names
                List <string> givenNameList = new List <string>();
                List <string> lastNameList  = new List <string>();
                for (int i = 0; i < retrievedPerson.identifiedPerson.name[0].Items.Length; i++)
                {
                    ENXP name = retrievedPerson.identifiedPerson.name[0].Items[i];

                    if (name.GetType() == typeof(engiven))
                    {
                        givenNameList.Add(name.Text[0]);
                    }
                    else if (name.GetType() == typeof(enfamily))
                    {
                        lastNameList.Add(name.Text[0]);
                    }
                }

                string delimiter  = " ";
                string givenNames = givenNameList.Aggregate((i, j) => i + delimiter + j);
                string lastNames  = lastNameList.Aggregate((i, j) => i + delimiter + j);
                string phn        = ((II)retrievedPerson.identifiedPerson.id.GetValue(0)).extension;
                // For now, add the return message to the reply
                return(new Patient(hdid, phn, givenNames, lastNames));
            }
            else
            {
                this.logger.LogInformation("Client Registry did not return a person. Returned message code: " + responseCode);
                return(new Patient());
            }
        }
示例#2
0
        public async Task ShouldGetPatient()
        {
            // Setup
            string   hdid                 = "EXTRIOYFPNX35TWEBUAJ3DNFDFXSYTBC6J4M76GYE3HC5ER2NKWQ";
            string   expectedPhn          = "0009735353315";
            string   expectedResponseCode = "BCHCIM.GD.0.0013";
            string   expectedFirstName    = "John";
            string   expectedLastName     = "Doe";
            DateTime expectedBirthDate    = DateTime.ParseExact("20001231", "yyyyMMdd", CultureInfo.InvariantCulture);


            HCIM_IN_GetDemographicsResponseIdentifiedPerson identifiedPerson =
                new HCIM_IN_GetDemographicsResponseIdentifiedPerson()
            {
                identifiedPerson = new HCIM_IN_GetDemographicsResponsePerson()
                {
                    id = new II[]
                    {
                        new II()
                        {
                            extension = expectedPhn
                        }
                    },
                    name = new PN[]
                    {
                        new PN()
                        {
                            Items = new ENXP[] {
                                new engiven()
                                {
                                    Text = new string[] { expectedFirstName }
                                },
                                new enfamily()
                                {
                                    Text = new string[] { expectedLastName }
                                }
                            }
                        }
                    },
                    birthTime = new TS()
                    {
                        value = "20001231"
                    }
                }
            };

            Mock <IClientRegistriesDelegate> clientRegistriesDelegateMock = new Mock <IClientRegistriesDelegate>();

            clientRegistriesDelegateMock.Setup(s => s.GetDemographicsAsync(It.IsAny <HCIM_IN_GetDemographicsRequest>())).ReturnsAsync(
                new HCIM_IN_GetDemographicsResponse1()
            {
                HCIM_IN_GetDemographicsResponse = new HCIM_IN_GetDemographicsResponse()
                {
                    controlActProcess = new HCIM_IN_GetDemographicsResponseQUQI_MT120001ControlActProcess()
                    {
                        queryAck = new HCIM_MT_QueryResponseQueryAck()
                        {
                            queryResponseCode = new CS()
                            {
                                code = expectedResponseCode
                            },
                        },
                        subject = new HCIM_IN_GetDemographicsResponseQUQI_MT120001Subject2[]
                        {
                            new HCIM_IN_GetDemographicsResponseQUQI_MT120001Subject2()
                            {
                                target = identifiedPerson
                            }
                        }
                    }
                }
            }
                );

            IPatientService service = new SoapPatientService(
                new Mock <ILogger <SoapPatientService> >().Object,
                clientRegistriesDelegateMock.Object
                );

            // Act
            RequestResult <Patient> actual = await service.GetPatient(hdid);

            // Verify
            Assert.Equal(expectedPhn, actual.ResourcePayload.PersonalHealthNumber);
            Assert.Equal(expectedFirstName, actual.ResourcePayload.FirstName);
            Assert.Equal(expectedLastName, actual.ResourcePayload.LastName);
            Assert.Equal(expectedBirthDate, actual.ResourcePayload.Birthdate);
        }
        private RequestResult <PatientModel> ParseResponse(HCIM_IN_GetDemographicsResponse1 reply)
        {
            using (Source.StartActivity("ParsePatientResponse"))
            {
                this.logger.LogDebug($"Parsing patient response... {JsonSerializer.Serialize(reply)}");

                // Verify that the reply contains a result
                string responseCode = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.queryAck.queryResponseCode.code;
                if (!responseCode.Contains("BCHCIM.GD.0.0013", StringComparison.InvariantCulture))
                {
                    PatientModel emptyPatient = new PatientModel();
                    this.logger.LogWarning($"Client Registry did not return a person. Returned message code: {responseCode}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(emptyPatient)}");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry did not return a person", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                HCIM_IN_GetDemographicsResponseIdentifiedPerson retrievedPerson = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.subject[0].target;

                // If the deceased indicator is set and true, return an empty person.
                bool deceasedInd = retrievedPerson.identifiedPerson.deceasedInd?.value ?? false;
                if (deceasedInd)
                {
                    PatientModel emptyPatient = new PatientModel();
                    this.logger.LogWarning($"Client Registry returned a person with the deceasedIndicator set to true. No PHN was populated. {deceasedInd}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(emptyPatient)}");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry returned a person with the deceasedIndicator set to true", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                PN?nameSection = retrievedPerson.identifiedPerson.name.Where(x => x.use.Any(u => u == cs_EntityNameUse.C)).FirstOrDefault();

                if (nameSection == null)
                {
                    this.logger.LogWarning($"Client Registry returned a person with an invalid name.");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.ActionRequired,
                        ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.InvalidName),
                    });
                }

                // Extract the subject names
                List <string> givenNameList = new List <string>();
                List <string> lastNameList  = new List <string>();
                for (int i = 0; i < nameSection.Items.Length; i++)
                {
                    ENXP name = nameSection.Items[i];

                    if (name.GetType() == typeof(engiven) && (name.qualifier == null || !name.qualifier.Contains(cs_EntityNamePartQualifier.CL)))
                    {
                        givenNameList.Add(name.Text[0]);
                    }
                    else if (name.GetType() == typeof(enfamily) && (name.qualifier == null || !name.qualifier.Contains(cs_EntityNamePartQualifier.CL)))
                    {
                        lastNameList.Add(name.Text[0]);
                    }
                }

                string   delimiter  = " ";
                string   givenNames = givenNameList.Aggregate((i, j) => i + delimiter + j);
                string   lastNames  = lastNameList.Aggregate((i, j) => i + delimiter + j);
                string?  dobStr     = ((TS)retrievedPerson.identifiedPerson.birthTime).value; // yyyyMMdd
                DateTime dob        = DateTime.ParseExact(dobStr, "yyyyMMdd", CultureInfo.InvariantCulture);
                string   genderCode = retrievedPerson.identifiedPerson.administrativeGenderCode.code;
                string   gender     = "NotSpecified";
                if (genderCode == "F")
                {
                    gender = "Female";
                }
                else if (genderCode == "M")
                {
                    gender = "Male";
                }

                PatientModel patient = new PatientModel()
                {
                    FirstName = givenNames, LastName = lastNames, Birthdate = dob, Gender = gender, EmailAddress = string.Empty
                };

                II?    identifiedPersonId   = (II?)retrievedPerson.identifiedPerson.id.GetValue(0);
                string?personIdentifierType = identifiedPersonId?.root;
                string personIdentifier     = identifiedPersonId?.extension ?? string.Empty;
                if (personIdentifierType == OIDType.HDID.ToString())
                {
                    patient.HdId = personIdentifier;
                }
                else if (personIdentifierType == OIDType.PHN.ToString())
                {
                    patient.PersonalHealthNumber = personIdentifier;
                }
                else
                {
                    this.logger.LogWarning($"Client Registry returned a person with a person identifier not recognized. No PHN or HDID was populated.");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.ActionRequired,
                        ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.NoHdId),
                    });
                }

                II?    subjectId             = (II?)retrievedPerson.id.GetValue(0);
                string?subjectIdentifierType = subjectId?.root;
                string subjectIdentifier     = subjectId?.extension ?? string.Empty;
                if (subjectIdentifierType == OIDType.HDID.ToString())
                {
                    patient.HdId = subjectIdentifier;
                }
                else if (personIdentifierType == OIDType.PHN.ToString())
                {
                    patient.PersonalHealthNumber = subjectIdentifier;
                }
                else
                {
                    this.logger.LogWarning($"Client Registry returned a person with a subject identifier not recognized. No PHN or HDID was populated.");
                    return(new RequestResult <PatientModel>()
                    {
                        ResultStatus = ResultType.ActionRequired,
                        ResultError = ErrorTranslator.ActionRequired(ErrorMessages.InvalidServicesCard, ActionType.NoHdId),
                    });
                }

                return(new RequestResult <PatientModel>()
                {
                    ResultStatus = ResultType.Success,
                    ResourcePayload = patient,
                });
            }
        }
示例#4
0
        public async Task ShouldGetDemographics()
        {
            // Setup
            string   expectedHdId         = "EXTRIOYFPNX35TWEBUAJ3DNFDFXSYTBC6J4M76GYE3HC5ER2NKWQ";
            string   expectedPhn          = "0009735353315";
            string   expectedResponseCode = "BCHCIM.GD.0.0013";
            string   expectedFirstName    = "Jane";
            string   expectedLastName     = "Doe";
            string   expectedGender       = "Female";
            DateTime expectedBirthDate    = DateTime.ParseExact("20001231", "yyyyMMdd", CultureInfo.InvariantCulture);


            HCIM_IN_GetDemographicsResponseIdentifiedPerson subjectTarget =
                new HCIM_IN_GetDemographicsResponseIdentifiedPerson()
            {
                id = new II[]
                {
                    new II()
                    {
                        root      = "2.16.840.1.113883.3.51.1.1.6",
                        extension = expectedHdId
                    }
                },
                identifiedPerson = new HCIM_IN_GetDemographicsResponsePerson()
                {
                    id = new II[]
                    {
                        new II()
                        {
                            root      = "2.16.840.1.113883.3.51.1.1.6.1",
                            extension = expectedPhn
                        }
                    },
                    name = new PN[]
                    {
                        new PN()
                        {
                            Items = new ENXP[] {
                                new engiven()
                                {
                                    Text = new string[] { expectedFirstName }
                                },
                                new enfamily()
                                {
                                    Text = new string[] { expectedLastName }
                                },
                            }
                        }
                    },
                    birthTime = new TS()
                    {
                        value = "20001231"
                    },
                    administrativeGenderCode = new CE()
                    {
                        code = "F"
                    }
                }
            };

            Mock <QUPA_AR101102_PortType> clientMock = new Mock <QUPA_AR101102_PortType>();

            clientMock.Setup(x => x.HCIM_IN_GetDemographicsAsync(It.IsAny <HCIM_IN_GetDemographicsRequest>())).ReturnsAsync(
                new HCIM_IN_GetDemographicsResponse1()
            {
                HCIM_IN_GetDemographicsResponse = new HCIM_IN_GetDemographicsResponse()
                {
                    controlActProcess = new HCIM_IN_GetDemographicsResponseQUQI_MT120001ControlActProcess()
                    {
                        queryAck = new HCIM_MT_QueryResponseQueryAck()
                        {
                            queryResponseCode = new CS()
                            {
                                code = expectedResponseCode
                            },
                        },
                        subject = new HCIM_IN_GetDemographicsResponseQUQI_MT120001Subject2[]
                        {
                            new HCIM_IN_GetDemographicsResponseQUQI_MT120001Subject2()
                            {
                                target = subjectTarget
                            }
                        }
                    }
                }
            }
                );
            using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
            IClientRegistriesDelegate patientDelegate = new ClientRegistriesDelegate(
                loggerFactory.CreateLogger <ClientRegistriesDelegate>(),
                clientMock.Object);


            // Act
            RequestResult <PatientModel> actual = await patientDelegate.GetDemographicsByHDIDAsync(expectedHdId);

            // Verify
            Assert.Equal(ResultType.Success, actual.ResultStatus);
            Assert.Equal(expectedHdId, actual.ResourcePayload.HdId);
            Assert.Equal(expectedPhn, actual.ResourcePayload.PersonalHealthNumber);
            Assert.Equal(expectedFirstName, actual.ResourcePayload.FirstName);
            Assert.Equal(expectedLastName, actual.ResourcePayload.LastName);
            Assert.Equal(expectedBirthDate, actual.ResourcePayload.Birthdate);
            Assert.Equal(expectedGender, actual.ResourcePayload.Gender);
        }
示例#5
0
        /// <summary>
        /// Gets the patient record.
        /// </summary>
        /// <param name="hdid">The patient id.</param>
        /// <returns>The patient model.</returns>
        public async System.Threading.Tasks.Task <RequestResult <Patient> > GetPatient(string hdid)
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();
            this.logger.LogTrace($"Getting patient... {hdid}");
            Patient patient;

            // Create request
            HCIM_IN_GetDemographicsRequest request = this.CreateRequest(hdid);

            // Perform the request
            try
            {
                HCIM_IN_GetDemographicsResponse1 reply = await this.clientRegistriesDelegate.GetDemographicsAsync(request).ConfigureAwait(true);

                // Verify that the reply contains a result
                string responseCode = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.queryAck.queryResponseCode.code;
                if (!responseCode.Contains("BCHCIM.GD.0.0013", StringComparison.InvariantCulture))
                {
                    patient = new Patient();
                    this.logger.LogWarning($"Client Registry did not return a person. Returned message code: {responseCode}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(patient)}");
                    return(new RequestResult <Patient>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry did not return a person", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                HCIM_IN_GetDemographicsResponseIdentifiedPerson retrievedPerson = reply.HCIM_IN_GetDemographicsResponse.controlActProcess.subject[0].target;

                // If the deceased indicator is set and true, return an empty person.
                bool deceasedInd = retrievedPerson.identifiedPerson.deceasedInd?.value == true;
                if (deceasedInd)
                {
                    patient = new Patient();
                    this.logger.LogWarning($"Client Registry returned a person with the deceasedIndicator set to true. No PHN was populated. {deceasedInd}");
                    this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(patient)}");
                    return(new RequestResult <Patient>()
                    {
                        ResultStatus = ResultType.Error,
                        ResultError = new RequestResultError()
                        {
                            ResultMessage = "Client Registry returned a person with the deceasedIndicator set to true", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                        },
                    });
                }

                // Extract the subject names
                List <string> givenNameList = new List <string>();
                List <string> lastNameList  = new List <string>();
                for (int i = 0; i < retrievedPerson.identifiedPerson.name[0].Items.Length; i++)
                {
                    ENXP name = retrievedPerson.identifiedPerson.name[0].Items[i];

                    if (name.GetType() == typeof(engiven))
                    {
                        givenNameList.Add(name.Text[0]);
                    }
                    else if (name.GetType() == typeof(enfamily))
                    {
                        lastNameList.Add(name.Text[0]);
                    }
                }

                string   delimiter  = " ";
                string   givenNames = givenNameList.Aggregate((i, j) => i + delimiter + j);
                string   lastNames  = lastNameList.Aggregate((i, j) => i + delimiter + j);
                string   phn        = ((II)retrievedPerson.identifiedPerson.id.GetValue(0) !).extension;
                string?  dobStr     = ((TS)retrievedPerson.identifiedPerson.birthTime).value; // yyyyMMdd
                DateTime dob        = DateTime.ParseExact(dobStr, "yyyyMMdd", CultureInfo.InvariantCulture);
                patient = new Patient(hdid, phn, givenNames, lastNames, dob, string.Empty);

                timer.Stop();
                this.logger.LogDebug($"Finished getting patient. {JsonSerializer.Serialize(patient)} Time Elapsed: {timer.Elapsed}");
                return(new RequestResult <Patient>()
                {
                    ResultStatus = ResultType.Success,
                    ResourcePayload = patient,
                });
            }
            catch (CommunicationException e)
            {
                this.logger.LogError(e.ToString());
                return(new RequestResult <Patient>()
                {
                    ResultStatus = ResultType.Error,
                    ResultError = new RequestResultError()
                    {
                        ResultMessage = "Communication Exception when trying to retrieve the PHN", ErrorCode = ErrorTranslator.ServiceError(ErrorType.CommunicationExternal, ServiceType.ClientRegistries)
                    },
                });
            }
        }