use of org.hl7.fhir.dstu2.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);
}
use of org.hl7.fhir.dstu2.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);
}
use of org.hl7.fhir.dstu2.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;
}
use of org.hl7.fhir.dstu2.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();
}
use of org.hl7.fhir.dstu2.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");
}
Aggregations