Search in sources :

Example 36 with HumanName

use of org.hl7.fhir.r5.model.HumanName in project integration-adaptor-111 by nhsconnect.

the class PractitionerMapperTest method shouldMapPractitionerForAssignedAuthor.

@Test
public void shouldMapPractitionerForAssignedAuthor() {
    POCDMT000002UK01AssignedAuthor associatedEntity = POCDMT000002UK01AssignedAuthor.Factory.newInstance();
    associatedEntity.setAssignedPerson(createPerson());
    associatedEntity.setTelecomArray(createTelecomArray());
    associatedEntity.setAddrArray(createAddrArray());
    when(humanNameMapper.mapHumanName(ArgumentMatchers.any())).thenReturn(humanName);
    when(contactPointMapper.mapContactPoint(ArgumentMatchers.any())).thenReturn(contactPoint);
    when(addressMapper.mapAddress(ArgumentMatchers.any())).thenReturn(address);
    when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
    Practitioner practitioner = practitionerMapper.mapPractitioner(associatedEntity);
    assertThat(practitioner.getIdElement().getValue()).isEqualTo(RANDOM_UUID);
    assertThat(practitioner.getActive()).isEqualTo(true);
    assertThat(practitioner.getNameFirstRep()).isEqualTo(humanName);
    assertThat(practitioner.getTelecomFirstRep()).isEqualTo(contactPoint);
    assertThat(practitioner.getAddressFirstRep()).isEqualTo(address);
}
Also used : POCDMT000002UK01AssignedAuthor(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01AssignedAuthor) Practitioner(org.hl7.fhir.dstu3.model.Practitioner) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Example 37 with HumanName

use of org.hl7.fhir.r5.model.HumanName in project integration-adaptor-111 by nhsconnect.

the class HumanNameMapperTest method shouldMapHumanName.

@Test
public void shouldMapHumanName() {
    PN pn = PN.Factory.newInstance();
    pn.addNewGiven().set(XmlString.Factory.newValue(GIVEN));
    pn.addNewPrefix().set(XmlString.Factory.newValue(PREFIX));
    pn.addNewSuffix().set(XmlString.Factory.newValue(SUFFIX));
    pn.addNewFamily().set(XmlString.Factory.newValue(FAMILY));
    pn.addNewValidTime();
    when(periodMapper.mapPeriod(ArgumentMatchers.any())).thenReturn(period);
    when(nodeUtil.hasSubNodes(any())).thenReturn(true);
    when(itkPersonName.getGivenArray()).thenReturn(pn.getGivenArray());
    when(nodeUtil.getNodeValueString(pn.getGivenArray(0))).thenReturn(GIVEN);
    when(itkPersonName.getPrefixArray()).thenReturn(pn.getPrefixArray());
    when(nodeUtil.getNodeValueString(pn.getPrefixArray(0))).thenReturn(PREFIX);
    when(itkPersonName.getSuffixArray()).thenReturn(pn.getSuffixArray());
    when(nodeUtil.getNodeValueString(pn.getSuffixArray(0))).thenReturn(SUFFIX);
    when(itkPersonName.sizeOfFamilyArray()).thenReturn(1);
    when(itkPersonName.getFamilyArray(0)).thenReturn(pn.getFamilyArray(0));
    when(nodeUtil.getNodeValueString(pn.getFamilyArray(0))).thenReturn(FAMILY);
    when(itkPersonName.isSetValidTime()).thenReturn(true);
    HumanName humanName = humanNameMapper.mapHumanName(itkPersonName);
    assertThat(humanName.getGivenAsSingleString()).isEqualTo(GIVEN);
    assertThat(humanName.getPrefixAsSingleString()).isEqualTo(PREFIX);
    assertThat(humanName.getSuffixAsSingleString()).isEqualTo(SUFFIX);
    assertThat(humanName.getFamily()).isEqualTo(FAMILY);
    assertThat(humanName.getPeriod()).isEqualTo(period);
    assertThat(humanName.getUse()).isEqualTo(OFFICIAL);
}
Also used : HumanName(org.hl7.fhir.dstu3.model.HumanName) PN(uk.nhs.connect.iucds.cda.ucr.PN) Test(org.junit.jupiter.api.Test)

Example 38 with HumanName

use of org.hl7.fhir.r5.model.HumanName in project integration-adaptor-111 by nhsconnect.

the class HumanNameMapper method mapHumanName.

public HumanName mapHumanName(PN itkPersonName) {
    HumanName humanName = new HumanName();
    if (!nodeUtil.hasSubNodes(itkPersonName)) {
        return humanName.setText(nodeUtil.getNodeValueString(itkPersonName));
    }
    Stream.of(itkPersonName.getGivenArray()).map(nodeUtil::getNodeValueString).forEach(humanName::addGiven);
    Stream.of(itkPersonName.getPrefixArray()).map(nodeUtil::getNodeValueString).forEach(humanName::addPrefix);
    Stream.of(itkPersonName.getSuffixArray()).map(nodeUtil::getNodeValueString).forEach(humanName::addSuffix);
    if (itkPersonName.sizeOfFamilyArray() >= 1) {
        humanName.setFamily(nodeUtil.getNodeValueString(itkPersonName.getFamilyArray(0)));
    }
    if (itkPersonName.isSetValidTime()) {
        humanName.setPeriod(periodMapper.mapPeriod(itkPersonName.getValidTime()));
    }
    humanName.setUse(OFFICIAL);
    return humanName;
}
Also used : HumanName(org.hl7.fhir.dstu3.model.HumanName)

Example 39 with HumanName

use of org.hl7.fhir.r5.model.HumanName in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method displayHumanName.

public static String displayHumanName(HumanName name) {
    StringBuilder s = new StringBuilder();
    if (name.hasText())
        s.append(name.getText());
    else {
        for (StringType p : name.getGiven()) {
            s.append(p.getValue());
            s.append(" ");
        }
        for (StringType p : name.getFamily()) {
            s.append(p.getValue());
            s.append(" ");
        }
    }
    if (name.hasUse() && name.getUse() != NameUse.USUAL)
        s.append("(" + name.getUse().toString() + ")");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.dstu2.model.StringType)

Example 40 with HumanName

use of org.hl7.fhir.r5.model.HumanName in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return;
    Base e = ew.getBase();
    if (e instanceof StringType)
        x.addText(((StringType) e).getValue());
    else if (e instanceof CodeType)
        x.addText(((CodeType) e).getValue());
    else if (e instanceof IdType)
        x.addText(((IdType) e).getValue());
    else if (e instanceof Extension)
        x.addText("Extensions: Todo");
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType)
        x.addText(((DateTimeType) e).toHumanDisplay());
    else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.dstu2.model.DateType)
        x.addText(((org.hl7.fhir.dstu2.model.DateType) e).toHumanDisplay());
    else if (e instanceof Enumeration) {
        Object ev = ((Enumeration<?>) e).getValue();
        // todo: look up a display name if there is one
        x.addText(ev == null ? "" : ev.toString());
    } else if (e instanceof BooleanType)
        x.addText(((BooleanType) e).getValue().toString());
    else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x);
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
    } else if (e instanceof org.hl7.fhir.dstu2.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu2.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu2.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu2.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
    } else if (e instanceof UriType) {
        renderUri((UriType) e, x);
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
    } else if (e instanceof Range) {
        renderRange((Range) e, x);
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.addText("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.addText(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        XhtmlNode c = x;
        ResourceWithReference tr = null;
        if (r.hasReferenceElement()) {
            tr = resolveReference(res, r.getReference());
            if (!r.getReference().startsWith("#")) {
                if (tr != null && tr.getReference() != null)
                    c = x.addTag("a").attribute("href", tr.getReference());
                else
                    c = x.addTag("a").attribute("href", r.getReference());
            }
        }
        // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
        if (r.hasDisplayElement()) {
            c.addText(r.getDisplay());
            if (tr != null) {
                c.addText(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
        } else {
            c.addText(r.getReference());
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof ElementDefinition) {
        x.addText("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
}
Also used : Meta(org.hl7.fhir.dstu2.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu2.model.Address) StringType(org.hl7.fhir.dstu2.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu2.model.Attachment) UriType(org.hl7.fhir.dstu2.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu2.model.HumanName) ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) Identifier(org.hl7.fhir.dstu2.model.Identifier) Coding(org.hl7.fhir.dstu2.model.Coding) Narrative(org.hl7.fhir.dstu2.model.Narrative) SampledData(org.hl7.fhir.dstu2.model.SampledData) Ratio(org.hl7.fhir.dstu2.model.Ratio) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) InstantType(org.hl7.fhir.dstu2.model.InstantType) Enumeration(org.hl7.fhir.dstu2.model.Enumeration) Reference(org.hl7.fhir.dstu2.model.Reference) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Quantity(org.hl7.fhir.dstu2.model.Quantity) Period(org.hl7.fhir.dstu2.model.Period) Range(org.hl7.fhir.dstu2.model.Range) Base(org.hl7.fhir.dstu2.model.Base) Annotation(org.hl7.fhir.dstu2.model.Annotation) IdType(org.hl7.fhir.dstu2.model.IdType) Extension(org.hl7.fhir.dstu2.model.Extension) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) CodeType(org.hl7.fhir.dstu2.model.CodeType) EventTiming(org.hl7.fhir.dstu2.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu2.model.Timing) Base64BinaryType(org.hl7.fhir.dstu2.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu2.model.CodeableConcept)

Aggregations

HumanName (org.hl7.fhir.r4.model.HumanName)84 HumanName (org.hl7.fhir.dstu3.model.HumanName)37 Patient (org.hl7.fhir.r4.model.Patient)37 Test (org.junit.jupiter.api.Test)29 ArrayList (java.util.ArrayList)27 Patient (org.hl7.fhir.dstu3.model.Patient)27 Test (org.junit.Test)26 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)23 Address (org.hl7.fhir.r4.model.Address)20 Identifier (org.hl7.fhir.r4.model.Identifier)20 PersonName (org.openmrs.PersonName)17 CamelSpringBootTest (org.apache.camel.test.spring.junit5.CamelSpringBootTest)16 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 GET (javax.ws.rs.GET)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)15 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)15 NotImplementedException (org.apache.commons.lang3.NotImplementedException)14 StringType (org.hl7.fhir.r4.model.StringType)14 Date (java.util.Date)13