Search in sources :

Example 71 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class XmlParserTests method testXsiDeserialiserXmlParser.

@Test
public /**
 * Deserializes a simplified CDA example into the logical model and checks that
 * xml deserialization works for the xsi:type
 *
 * @throws IOException
 */
void testXsiDeserialiserXmlParser() throws IOException {
    Element cda = Manager.parseSingle(context, TestingUtilities.loadTestResourceStream("validator", "cda", "example-xsi.xml"), FhirFormat.XML);
    ByteArrayOutputStream baosXml = new ByteArrayOutputStream();
    Manager.compose(context, cda, baosXml, FhirFormat.XML, OutputStyle.PRETTY, null);
    String cdaSerialised = baosXml.toString();
    Assertions.assertTrue(cdaSerialised.indexOf("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"") > 0);
    Assertions.assertTrue(cdaSerialised.indexOf("xsi:type=\"CD\"") > 0);
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 72 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method mergeProps.

private void mergeProps(ConceptDefinitionComponent cd, ConceptDefinitionComponent l, ConceptDefinitionComponent r, List<PropertyComponent> destProps, CodeSystemComparison res) {
    List<ConceptPropertyComponent> matchR = new ArrayList<>();
    for (ConceptPropertyComponent lp : l.getProperty()) {
        ConceptPropertyComponent rp = findRightProp(r.getProperty(), lp, res);
        if (rp == null) {
            cd.getProperty().add(lp);
        } else {
            matchR.add(rp);
            cd.getProperty().add(lp);
            if (lp.getValue().equalsDeep(rp.getValue())) {
                cd.getProperty().add(rp.setCode(res.getPropMap().get(rp.getCode())));
            }
        }
    }
    for (ConceptPropertyComponent rp : r.getProperty()) {
        if (!matchR.contains(rp)) {
            cd.getProperty().add(rp.setCode(res.getPropMap().get(rp.getCode())));
        }
    }
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent) ArrayList(java.util.ArrayList)

Example 73 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class ValueSetRenderer method addLanguageRow.

private void addLanguageRow(ConceptReferenceComponent c, XhtmlNode t, List<String> langs) {
    XhtmlNode tr = t.tr();
    tr.td().addText(c.getCode());
    for (String lang : langs) {
        String d = null;
        for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
            String l = cd.getLanguage();
            if (lang.equals(l))
                d = cd.getValue();
        }
        tr.td().addText(d == null ? "" : d);
    }
}
Also used : ConceptReferenceDesignationComponent(org.hl7.fhir.r4b.model.ValueSet.ConceptReferenceDesignationComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 74 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method displayLeaf.

private boolean displayLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, String name, boolean showCodeDetails, boolean allowLinks) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return false;
    Base e = ew.getBase();
    if (e == null)
        return false;
    Map<String, String> displayHints = readDisplayHints(defn);
    if (name.endsWith("[x]"))
        name = name.substring(0, name.length() - 3);
    if (!showCodeDetails && e instanceof PrimitiveType && isDefault(displayHints, ((PrimitiveType) e)))
        return false;
    if (e instanceof StringType) {
        x.addText(name + ": " + ((StringType) e).getValue());
        return true;
    } else if (e instanceof CodeType) {
        x.addText(name + ": " + ((CodeType) e).getValue());
        return true;
    } else if (e instanceof IdType) {
        x.addText(name + ": " + ((IdType) e).getValue());
        return true;
    } else if (e instanceof UriType) {
        if (Utilities.isAbsoluteUrlLinkable(((UriType) e).getValue()) && allowLinks) {
            x.tx(name + ": ");
            x.ah(((UriType) e).getValue()).addText(((UriType) e).getValue());
        } else {
            x.addText(name + ": " + ((UriType) e).getValue());
        }
        return true;
    } else if (e instanceof DateTimeType) {
        x.addText(name + ": " + ((DateTimeType) e).toHumanDisplay());
        return true;
    } else if (e instanceof InstantType) {
        x.addText(name + ": " + ((InstantType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Extension) {
        // x.tx("Extensions: todo");
        return false;
    } else if (e instanceof org.hl7.fhir.r5.model.DateType) {
        x.addText(name + ": " + ((org.hl7.fhir.r5.model.DateType) e).toHumanDisplay());
        return true;
    } else if (e instanceof Enumeration) {
        // todo: look up a display name if there is one
        x.addText(((Enumeration<?>) e).getValue().toString());
        return true;
    } else if (e instanceof BooleanType) {
        if (((BooleanType) e).hasValue()) {
            x.addText(name);
            x.addText(": ");
            x.addText(((BooleanType) e).getValueAsString());
            return true;
        }
    } else if (e instanceof CodeableReference) {
        if (((CodeableReference) e).hasReference()) {
            Reference r = ((CodeableReference) e).getReference();
            renderReference(res, x, r, allowLinks);
        } else {
            renderCodeableConcept(x, ((CodeableReference) e).getConcept(), showCodeDetails);
        }
        return true;
    } else if (e instanceof CodeableConcept) {
        renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
        return true;
    } else if (e instanceof Coding) {
        renderCoding(x, (Coding) e, showCodeDetails);
        return true;
    } else if (e instanceof Annotation) {
        renderAnnotation(x, (Annotation) e, showCodeDetails);
        return true;
    } else if (e instanceof org.hl7.fhir.r5.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue()));
        return true;
    } else if (e instanceof org.hl7.fhir.r5.model.DecimalType) {
        x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString());
        return true;
    } else if (e instanceof Identifier) {
        renderIdentifier(x, (Identifier) e);
        return true;
    } else if (e instanceof HumanName) {
        renderHumanName(x, (HumanName) e);
        return true;
    } else if (e instanceof SampledData) {
        renderSampledData(x, (SampledData) e);
        return true;
    } else if (e instanceof Address) {
        renderAddress(x, (Address) e);
        return true;
    } else if (e instanceof ContactPoint) {
        if (allowLinks) {
            renderContactPoint(x, (ContactPoint) e);
        } else {
            displayContactPoint(x, (ContactPoint) e);
        }
        return true;
    } else if (e instanceof Timing) {
        renderTiming(x, (Timing) e);
        return true;
    } else if (e instanceof Quantity) {
        renderQuantity(x, (Quantity) e, showCodeDetails);
        return true;
    } else if (e instanceof Ratio) {
        renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
        x.tx("/");
        renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
        return true;
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(name + ": ");
        x.addText(!p.hasStart() ? "?ngen-2?" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
        return true;
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.hasDisplayElement())
            x.addText(r.getDisplay());
        else if (r.hasReferenceElement()) {
            ResourceWithReference tr = resolveReference(res, r.getReference());
            // getDisplayForReference(tr.getReference()));
            x.addText(tr == null ? r.getReference() : "?ngen-3");
        } else
            x.tx("?ngen-4?");
        return true;
    } else if (e instanceof Narrative) {
        return false;
    } else if (e instanceof Resource) {
        return false;
    } else if (e instanceof ContactDetail) {
        ContactDetail cd = (ContactDetail) e;
        if (cd.hasName()) {
            x.tx(cd.getName() + ": ");
        }
        boolean first = true;
        for (ContactPoint c : cd.getTelecom()) {
            if (first)
                first = false;
            else
                x.tx(",");
            if (allowLinks) {
                renderContactPoint(x, c);
            } else {
                displayContactPoint(x, c);
            }
        }
        return true;
    } else if (e instanceof Range) {
        return false;
    } else if (e instanceof Meta) {
        return false;
    } else if (e instanceof Dosage) {
        return false;
    } else if (e instanceof Signature) {
        return false;
    } else if (e instanceof UsageContext) {
        return false;
    } else if (e instanceof RelatedArtifact) {
        return false;
    } else if (e instanceof ElementDefinition) {
        return false;
    } else if (e instanceof Base64BinaryType) {
        return false;
    } else if (!(e instanceof Attachment))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
    return false;
}
Also used : Meta(org.hl7.fhir.r5.model.Meta) Address(org.hl7.fhir.r5.model.Address) StringType(org.hl7.fhir.r5.model.StringType) Attachment(org.hl7.fhir.r5.model.Attachment) Dosage(org.hl7.fhir.r5.model.Dosage) Identifier(org.hl7.fhir.r5.model.Identifier) Coding(org.hl7.fhir.r5.model.Coding) Narrative(org.hl7.fhir.r5.model.Narrative) SampledData(org.hl7.fhir.r5.model.SampledData) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) InstantType(org.hl7.fhir.r5.model.InstantType) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) Period(org.hl7.fhir.r5.model.Period) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) Range(org.hl7.fhir.r5.model.Range) RelatedArtifact(org.hl7.fhir.r5.model.RelatedArtifact) IdType(org.hl7.fhir.r5.model.IdType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) UsageContext(org.hl7.fhir.r5.model.UsageContext) Timing(org.hl7.fhir.r5.model.Timing) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UriType(org.hl7.fhir.r5.model.UriType) HumanName(org.hl7.fhir.r5.model.HumanName) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Ratio(org.hl7.fhir.r5.model.Ratio) Enumeration(org.hl7.fhir.r5.model.Enumeration) Reference(org.hl7.fhir.r5.model.Reference) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) BooleanType(org.hl7.fhir.r5.model.BooleanType) Quantity(org.hl7.fhir.r5.model.Quantity) Base(org.hl7.fhir.r5.model.Base) Annotation(org.hl7.fhir.r5.model.Annotation) Extension(org.hl7.fhir.r5.model.Extension) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) Signature(org.hl7.fhir.r5.model.Signature) CodeType(org.hl7.fhir.r5.model.CodeType) Base64BinaryType(org.hl7.fhir.r5.model.Base64BinaryType)

Example 75 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class DataRenderer method describeLang.

protected String describeLang(String lang) {
    // special cases:
    if ("fr-CA".equals(lang)) {
        // this one was omitted from the value set
        return "French (Canadian)";
    }
    ValueSet v = getContext().getWorker().fetchResource(ValueSet.class, "http://hl7.org/fhir/ValueSet/languages");
    if (v != null) {
        ConceptReferenceComponent l = null;
        for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
            if (cc.getCode().equals(lang))
                l = cc;
        }
        if (l == null) {
            if (lang.contains("-")) {
                lang = lang.substring(0, lang.indexOf("-"));
            }
            for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
                if (cc.getCode().equals(lang)) {
                    l = cc;
                    break;
                }
            }
            if (l == null) {
                for (ConceptReferenceComponent cc : v.getCompose().getIncludeFirstRep().getConcept()) {
                    if (cc.getCode().startsWith(lang + "-")) {
                        l = cc;
                        break;
                    }
                }
            }
        }
        if (l != null) {
            if (lang.contains("-"))
                lang = lang.substring(0, lang.indexOf("-"));
            String en = l.getDisplay();
            String nativelang = null;
            for (ConceptReferenceDesignationComponent cd : l.getDesignation()) {
                if (cd.getLanguage().equals(lang))
                    nativelang = cd.getValue();
            }
            if (nativelang == null)
                return en + " (" + lang + ")";
            else
                return nativelang + " (" + en + ", " + lang + ")";
        }
    }
    return lang;
}
Also used : ConceptReferenceDesignationComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceDesignationComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Aggregations

ArrayList (java.util.ArrayList)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 Coding (org.hl7.fhir.r4.model.Coding)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 CD (net.ihe.gazelle.hl7v3.datatypes.CD)7 CS (net.ihe.gazelle.hl7v3.datatypes.CS)7 II (net.ihe.gazelle.hl7v3.datatypes.II)7 TS (net.ihe.gazelle.hl7v3.datatypes.TS)7 MCCIMT000100UV01Device (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device)7 MCCIMT000100UV01Receiver (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver)7 MCCIMT000100UV01Sender (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender)7 Identifier (org.hl7.fhir.r4.model.Identifier)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 IOException (java.io.IOException)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)5