Search in sources :

Example 61 with Period

use of org.hl7.fhir.r4.model.Period in project integration-adaptor-111 by nhsconnect.

the class ContactPointMapperTest method shouldMapContactPointPhone.

@Test
public void shouldMapContactPointPhone() {
    TEL tel = TEL.Factory.newInstance();
    tel.setValue(TEL_NUMBER);
    tel.setUse(singletonList(USE_ITK_HOME));
    tel.addNewUseablePeriod();
    when(periodMapper.mapPeriod(ArgumentMatchers.any())).thenReturn(period);
    ContactPoint contactPoint = contactPointMapper.mapContactPoint(tel);
    assertThat(contactPoint.getValue()).isEqualTo(TEL_NUMBER);
    assertThat(contactPoint.getUse()).isEqualTo(HOME);
    assertThat(contactPoint.getPeriod()).isEqualTo(period);
    assertThat(contactPoint.getSystem()).isEqualTo(PHONE);
}
Also used : ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) TEL(uk.nhs.connect.iucds.cda.ucr.TEL) Test(org.junit.jupiter.api.Test)

Example 62 with Period

use of org.hl7.fhir.r4.model.Period in project org.hl7.fhir.core by hapifhir.

the class CCDAConverter method processAllergyProblemAct.

protected void processAllergyProblemAct(ListResource list, Element concern) throws Exception {
    cda.checkTemplateId(concern, "2.16.840.1.113883.10.20.22.4.30");
    // Allergy Problem Act - this is a concern - we treat the concern as information about it's place in the list
    checkNoNegationOrNullFlavor(concern, "Allergy Problem Act");
    checkNoSubject(concern, "Allergy Problem Act");
    // SHALL contain exactly one [1..1] Allergy - intolerance Observation
    for (Element entry : cda.getChildren(concern, "entryRelationship")) {
        Element obs = cda.getChild(entry, "observation");
        cda.checkTemplateId(obs, "2.16.840.1.113883.10.20.22.4.7");
        checkNoNegationOrNullFlavor(obs, "Allergy - intolerance Observation");
        checkNoSubject(obs, "Allergy Problem Act");
        AllergyIntolerance ai = new AllergyIntolerance();
        ListEntryComponent item = addItemToList(list, ai);
        // SHALL contain at least one [1..*] id (CONF:7472).
        for (Element e : cda.getChildren(concern, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] statusCode, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.80.68 HITSPProblemStatus DYNAMIC (CONF:7485)
        // the status code is about the concern (e.g. the entry in the list)
        // possible values: active, suspended, aborted, completed, with an effective time
        String s = cda.getStatus(concern);
        item.setFlag(Factory.newCodeableConcept(s, "http://hl7.org/fhir/v3/ActStatus", s));
        if (// only on this condition?
        s.equals("aborted"))
            item.setDeleted(true);
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7498)
        Period p = convert.makePeriodFromIVL(cda.getChild(concern, "effectiveTime"));
        item.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/list-period", p, false));
        if (p.getEnd() != null)
            item.setDate(p.getEnd());
        else
            item.setDate(p.getStart());
        // SHALL contain at least one [1..*] id (CONF:7382)
        for (Element e : cda.getChildren(obs, "id")) ai.getIdentifier().add(convert.makeIdentifierFromII(e));
        // SHALL contain exactly one [1..1] effectiveTime (CONF:7387)
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergyintolerance-period", convert.makePeriodFromIVL(cda.getChild(obs, "effectiveTime")), false));
        // SHALL contain exactly one [1..1] value with @xsi:type="CD" (CONF:7390)
        CodeableConcept type = convert.makeCodeableConceptFromCD(cda.getChild(obs, "value"));
        // This value SHALL contain @code, which SHALL be selected from ValueSet 2.16.840.1.113883.3.88.12.3221.6.2 Allergy/Adverse Event Type
        String ss = type.getCoding().get(0).getCode();
        if (ss.equals("416098002") || ss.equals("414285001"))
            ai.setType(AllergyIntoleranceType.ALLERGY);
        else if (ss.equals("59037007") || ss.equals("235719002"))
            ai.setType(AllergyIntoleranceType.INTOLERANCE);
        ai.getExtension().add(Factory.newExtension("http://www.healthintersections.com.au/fhir/extensions/allergy-category", type, false));
        // SHOULD contain zero or one [0..1] participant (CONF:7402) such that it
        // ......This playingEntity SHALL contain exactly one [1..1] code
        ai.setCode(convert.makeCodeableConceptFromCD(cda.getDescendent(obs, "participant/participantRole/playingEntity/code")));
        // SHOULD contain zero or more [0..*] entryRelationship (CONF:7447) such that it SHALL contain exactly one [1..1] Reaction Observation (templateId:2.16.840.1.113883.10.20.22.4.9) (CONF:7450).
        for (Element e : cda.getChildren(obs, "entryRelationship")) {
            Element child = cda.getChild(e, "observation");
            if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.28") && ai.getClinicalStatus() == null) {
                // SHALL contain exactly one [1..1] value with @xsi:type="CE", where the @code SHALL be selected from ValueSet Problem Status Value Set 2.16.840.1.113883.3.88.12.80.68 DYNAMIC (CONF:7322).
                // 55561003  SNOMED CT  Active
                // 73425007  SNOMED CT  Inactive
                // 413322009  SNOMED CT  Resolved
                String sc = cda.getChild(child, "value").getAttribute("code");
                if (sc.equals("55561003")) {
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE);
                    ai.setVerificationStatus(AllergyIntoleranceVerificationStatus.CONFIRMED);
                } else
                    ai.setClinicalStatus(AllergyIntoleranceClinicalStatus.RESOLVED);
            } else if (cda.hasTemplateId(child, "2.16.840.1.113883.10.20.22.4.9")) {
                ai.getReaction().add(processAdverseReactionObservation(child));
            }
        }
        // SHOULD contain zero or one [0..1] entryRelationship (CONF:9961) such that it SHALL contain exactly one [1..1] Severity Observation (templateId:2.16.840.1.113883.10.20.22.4.8) (CONF:9963).
        ai.setCriticality(readCriticality(cda.getSeverity(obs)));
    }
}
Also used : AllergyIntolerance(org.hl7.fhir.dstu3.model.AllergyIntolerance) Element(org.w3c.dom.Element) ListEntryComponent(org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)

Example 63 with Period

use of org.hl7.fhir.r4.model.Period in project org.hl7.fhir.core by hapifhir.

the class ArgonautConverter method processMedicationsSection.

private void processMedicationsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
    scanSection("Medications", section);
    ListResource list = new ListResource();
    list.setId(context.getBaseId() + "-list-medications");
    list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafmedicationlist");
    list.setSubject(context.getSubjectRef());
    list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
    list.setTitle(cda.getChild(section, "title").getTextContent());
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.SNAPSHOT);
    list.setDateElement(context.getNow());
    list.setSource(context.getAuthorRef());
    buildNarrative(list, cda.getChild(section, "text"));
    int i = 0;
    for (Element c : cda.getChildren(section, "entry")) {
        // allergy problem act
        Element sa = cda.getChild(c, "substanceAdministration");
        MedicationStatement ms = new MedicationStatement();
        ms.setId(context.getBaseId() + "-medication-" + i);
        ms.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/medicationstatement-daf-dafmedicationstatement");
        i++;
        ms.setSubject(context.getSubjectRef());
        boolean found = false;
        for (Element e : cda.getChildren(sa, "id")) {
            Identifier id = convert.makeIdentifierFromII(e);
            ms.getIdentifier().add(id);
        }
        if (!found) {
            ms.setStatus(MedicationStatementStatus.COMPLETED);
            list.addEntry().setItem(new Reference().setReference("MedicationStatement/" + ms.getId()));
            // allergy observation
            Element mm = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturedMaterial");
            ms.setMedication(new Reference().setReference("#med"));
            Medication med = new Medication();
            med.setId("med");
            med.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(mm, "code")), null));
            ms.getContained().add(med);
            Dosage dosage = ms.addDosage();
            // allergy observation
            Element qty = cda.getChild(sa, "doseQuantity");
            try {
                if (cda.getChild(qty, "low") != null) {
                    // todo: this is not correct?
                    dosage.getExtension().add(new Extension().setUrl("http://healthintersections.com.au/fhir/extensions/medication-statement-range").setValue(convert.makeRangeFromIVLPQ(qty)));
                } else {
                    dosage.setDose(convert.makeQuantityFromPQ(qty));
                }
            } catch (Exception e) {
                System.out.println("  invalid dose quantity '" + qty.getAttribute("value") + " " + qty.getAttribute("unit") + "' (" + e.getClass().getName() + ") in " + context.getBaseId());
            }
            dosage.setRoute(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(sa, "routeCode")), null));
            Type t = convert.makeSomethingFromGTS(cda.getChildren(sa, "effectiveTime"));
            if (t instanceof Timing) {
                dosage.setTiming((Timing) t);
                if (dosage.getTiming().hasRepeat() && dosage.getTiming().getRepeat().hasBounds())
                    ms.setEffective(dosage.getTiming().getRepeat().getBounds());
            } else if (t instanceof Period)
                ms.setEffective(t);
            else
                throw new Exception("Undecided how to handle " + t.getClass().getName());
            for (Element e : cda.getChildren(sa, "author")) {
                if (ms.hasInformationSource())
                    throw new Error("additional author discovered");
                Practitioner p = processPerformer(cda, convert, context, e, "assignedAuthor", "assignedPerson");
                Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
                ms.setInformationSource(ref);
                ms.setDateAssertedElement(convert.makeDateTimeFromTS(cda.getChild(e, "time")));
            }
            saveResource(ms);
        }
    }
    saveResource(list);
}
Also used : Element(org.w3c.dom.Element) IOException(java.io.IOException) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) ObservationRelationshipType(org.hl7.fhir.dstu3.model.Observation.ObservationRelationshipType)

Example 64 with Period

use of org.hl7.fhir.r4.model.Period 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)

Example 65 with Period

use of org.hl7.fhir.r4.model.Period in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composePatientContactComponent.

protected void composePatientContactComponent(Complex parent, String parentType, String name, Patient.ContactComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "contact", name, element, index);
    for (int i = 0; i < element.getRelationship().size(); i++) composeCodeableConcept(t, "Patient", "relationship", element.getRelationship().get(i), i);
    if (element.hasName())
        composeHumanName(t, "Patient", "name", element.getName(), -1);
    for (int i = 0; i < element.getTelecom().size(); i++) composeContactPoint(t, "Patient", "telecom", element.getTelecom().get(i), i);
    if (element.hasAddress())
        composeAddress(t, "Patient", "address", element.getAddress(), -1);
    if (element.hasGenderElement())
        composeEnum(t, "Patient", "gender", element.getGenderElement(), -1);
    if (element.hasOrganization())
        composeReference(t, "Patient", "organization", element.getOrganization(), -1);
    if (element.hasPeriod())
        composePeriod(t, "Patient", "period", element.getPeriod(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Aggregations

Period (org.hl7.fhir.r4.model.Period)87 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)44 Date (java.util.Date)42 Test (org.junit.Test)42 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)40 Coding (org.hl7.fhir.r4.model.Coding)34 Test (org.junit.jupiter.api.Test)34 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)32 Period (org.hl7.fhir.dstu3.model.Period)30 ArrayList (java.util.ArrayList)29 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)27 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)20 Encounter (org.hl7.fhir.r4.model.Encounter)20 Reference (org.hl7.fhir.r4.model.Reference)20 Patient (org.hl7.fhir.r4.model.Patient)19 Reference (org.hl7.fhir.dstu3.model.Reference)18 HashMap (java.util.HashMap)17 Identifier (org.hl7.fhir.r4.model.Identifier)17 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 List (java.util.List)14