use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Patient in project integration-adaptor-111 by nhsconnect.
the class PatientMapper method mapPatient.
public Patient mapPatient(POCDMT000002UK01PatientRole patientRole) {
Patient fhirPatient = new Patient();
fhirPatient.setIdElement(resourceUtil.newRandomUuid());
fhirPatient.setIdentifier(getNhsNumbers(patientRole));
fhirPatient.setActive(true);
if (patientRole.isSetPatient()) {
POCDMT000002UK01Patient itkPatient = patientRole.getPatient();
fhirPatient.setName(getNames(itkPatient));
fhirPatient.setAddress(getAddresses(patientRole));
fhirPatient.setTelecom(getContactPoints(patientRole));
fhirPatient.addGeneralPractitioner(getGeneralPractioner(patientRole));
if (itkPatient.sizeOfLanguageCommunicationArray() > 0) {
Stream.of(itkPatient.getLanguageCommunicationArray()).map(this::getLanguageCommunicationCode).forEach(fhirPatient::setLanguage);
}
fhirPatient.setContact(getContactComponents(itkPatient));
fhirPatient.setExtension(getExtensions(itkPatient));
if (itkPatient.isSetBirthTime()) {
fhirPatient.setBirthDate(periodMapper.mapPeriod(itkPatient.getBirthTime()).getStart());
}
if (itkPatient.isSetAdministrativeGenderCode()) {
fhirPatient.setGender(GenderMapper.getGenderFromCode(itkPatient.getAdministrativeGenderCode().getCode()));
}
if (itkPatient.isSetMaritalStatusCode()) {
if (itkPatient.getMaritalStatusCode().isSetCode()) {
MaritalStatus.fromCode(itkPatient.getMaritalStatusCode().getCode()).ifPresent(maritalStatus -> {
Coding coding = new Coding();
if (!StringUtils.isBlank(maritalStatus.getCode())) {
coding.setCode(maritalStatus.getCode());
}
if (!StringUtils.isBlank(maritalStatus.getDisplay())) {
coding.setDisplay(maritalStatus.getDisplay());
}
if (!StringUtils.isBlank(maritalStatus.getSystem())) {
coding.setSystem(maritalStatus.getSystem());
}
if (coding.hasDisplay() || coding.hasSystem() || coding.hasCode()) {
fhirPatient.setMaritalStatus(new CodeableConcept(coding));
}
});
}
}
}
return fhirPatient;
}
use of uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Patient in project integration-adaptor-111 by nhsconnect.
the class PatientMapperTest method shouldMapPatient.
@Test
@SuppressWarnings("MagicNumber")
public void shouldMapPatient() {
POCDMT000002UK01PatientRole patientRole = mock(POCDMT000002UK01PatientRole.class);
POCDMT000002UK01Patient itkPatient = mock(POCDMT000002UK01Patient.class);
when(patientRole.isSetPatient()).thenReturn(true);
when(patientRole.getPatient()).thenReturn(itkPatient);
when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
when(resourceUtil.createReference(organization)).thenReturn(new Reference(organization));
mockNames(itkPatient);
mockAddress(patientRole);
mockIdentifier(patientRole);
mockContactPoint(patientRole);
mockGeneralPractitioner(patientRole);
mockLanguage(itkPatient);
mockGuardian(itkPatient);
mockExtensions(itkPatient);
mockBirthTime(itkPatient);
mockBirthPlace(itkPatient);
mockGender(itkPatient);
mockMaritalStatus(itkPatient);
Patient fhirPatient = patientMapper.mapPatient(patientRole);
assertThat(fhirPatient.getIdElement().getValue()).isEqualTo(RANDOM_UUID);
assertThat(fhirPatient.getActive()).isEqualTo(true);
assertThat(fhirPatient.getNameFirstRep()).isEqualTo(humanName);
assertThat(fhirPatient.getAddressFirstRep()).isEqualTo(address);
assertThat(fhirPatient.getTelecomFirstRep()).isEqualTo(contactPoint);
assertThat(fhirPatient.getGeneralPractitionerFirstRep().getResource()).isEqualTo(organization);
assertThat(fhirPatient.getLanguage()).isEqualTo("EN");
assertThat(fhirPatient.getContactFirstRep()).isEqualTo(contactComponent);
assertThat(fhirPatient.getExtension().size()).isEqualTo(3);
assertThat(fhirPatient.getBirthDate()).isEqualTo(date);
assertThat(fhirPatient.getGender().toCode()).isEqualTo("unknown");
assertThat(fhirPatient.getMaritalStatus().getCoding().get(0).getDisplay()).isEqualTo("Married");
assertThat(fhirPatient.getMaritalStatus().getCoding().get(0).getSystem()).isEqualTo("http://hl7.org/fhir/v3/MaritalStatus");
assertThat(fhirPatient.getMaritalStatus().getCoding().get(0).getCode()).isEqualTo("M");
verifyNhsNumber(fhirPatient);
}
Aggregations