Search in sources :

Example 21 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class Provenance30_40 method convertProvenanceAgentComponent.

public static org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent convertProvenanceAgentComponent(org.hl7.fhir.dstu3.model.Provenance.ProvenanceAgentComponent src) throws FHIRException {
    if (src == null)
        return null;
    org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent tgt = new org.hl7.fhir.r4.model.Provenance.ProvenanceAgentComponent();
    ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
    for (org.hl7.fhir.dstu3.model.CodeableConcept t : src.getRole()) tgt.addRole(CodeableConcept30_40.convertCodeableConcept(t));
    if (src.hasWho()) {
        Type t = ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getWho());
        if (t instanceof Reference)
            tgt.setWho((Reference) t);
        if (t instanceof UriType)
            tgt.getWho().setReference(t.primitiveValue());
    }
    if (src.hasOnBehalfOf()) {
        Type t = ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().convertType(src.getOnBehalfOf());
        if (t instanceof Reference)
            tgt.setOnBehalfOf((Reference) t);
        if (t instanceof UriType)
            tgt.getOnBehalfOf().setReference(t.primitiveValue());
    }
    return tgt;
}
Also used : Type(org.hl7.fhir.r4.model.Type) UriType(org.hl7.fhir.r4.model.UriType) Reference(org.hl7.fhir.r4.model.Reference) UriType(org.hl7.fhir.r4.model.UriType)

Example 22 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class IEEE11073Convertor method generateLoincMdcMap.

private static ConceptMap generateLoincMdcMap(CodeSystem mdc, String dst, String src) throws IOException, FHIRException {
    ConceptMap cm = new ConceptMap();
    cm.setId("loinc-mdc");
    cm.setUrl("http:/???/fhir/ConceptMap/loinc-mdc");
    cm.setVersion("[todo]");
    cm.setName("LoincMdcCrossMap");
    cm.setTitle("Cross Map between LOINC and MDC");
    cm.setStatus(PublicationStatus.DRAFT);
    cm.setExperimental(true);
    cm.setDateElement(new DateTimeType());
    cm.setPublisher("HL7, Inc");
    ContactDetail cd = cm.addContact();
    cd.setName("LOINC + IEEE");
    ContactPoint cp = cd.addTelecom();
    cp.setSystem(ContactPointSystem.URL);
    cp.setValue("http://loinc.org");
    cm.setDescription("A Cross Map between the LOINC and MDC Code systems");
    cm.setPurpose("To implementers map between medical device codes and LOINC codes");
    cm.setCopyright("This content LOINC \u00ae is copyright \u00a9 1995 Regenstrief Institute, Inc. and the LOINC Committee, and available at no cost under the license at http://loinc.org/terms-of-use");
    cm.setSource(new UriType("http://loinc.org/vs"));
    cm.setTarget(new UriType(MDC_ALL_VALUES));
    ConceptMapGroupComponent g = cm.addGroup();
    g.setSource("urn:iso:std:iso:11073:10101");
    g.setTarget("http://loinc.org");
    CSVReader csv = new CSVReader(new FileInputStream(src));
    csv.readHeaders();
    while (csv.line()) {
        SourceElementComponent e = g.addElement();
        e.setCode(csv.cell("IEEE_CF_CODE10"));
        e.setDisplay(csv.cell("IEEE_DESCRIPTION"));
        TargetElementComponent t = e.addTarget();
        t.setEquivalence(ConceptMapEquivalence.EQUIVALENT);
        t.setCode(csv.cell("LOINC_NUM"));
        t.setDisplay(csv.cell("LOINC_LONG_COMMON_NAME"));
    }
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dst, "conceptmap-" + cm.getId() + ".xml")), cm);
    System.out.println("Done");
    return cm;
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) CSVReader(org.hl7.fhir.utilities.CSVReader) FileOutputStream(java.io.FileOutputStream) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) FileInputStream(java.io.FileInputStream) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)

Example 23 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class ISO21090Importer method produceProperties.

private void produceProperties(List<ElementDefinition> elements, String name, List<Property> properties, boolean attrMode, boolean snapshot) throws FHIRFormatError {
    for (Property p : properties) {
        if (p.isIsattr() == attrMode) {
            ElementDefinition ed = new ElementDefinition();
            elements.add(ed);
            ed.setPath(name + "." + p.getName());
            if (p.getType().startsWith("xsd:"))
                ToolingExtensions.addStringExtension(ed.addType(), ToolingExtensions.EXT_XML_TYPE, p.getType());
            else
                ed.addType().setCode(p.getType());
            ed.setMin(p.getMin());
            ed.setMax(p.getMax() == Integer.MAX_VALUE ? "*" : Integer.toString(p.getMax()));
            ed.setDefinition(p.getDoco());
            if (p.isIsattr())
                ed.addRepresentation(PropertyRepresentation.XMLATTR);
            if (p.getBinding() != null)
                ed.getBinding().setStrength(BindingStrength.REQUIRED).setValueSet(new UriType("http://hl7.org/fhir/iso21090/ValueSet/" + p.getBinding()));
            if (snapshot)
                ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());
        }
    }
}
Also used : ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 24 with UriType

use of org.hl7.fhir.r4b.model.UriType in project org.hl7.fhir.core by hapifhir.

the class R5ToR5Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r5 = null;
    if (isJson)
        r5 = new JsonParser().parse(stream);
    else
        r5 = new XmlParser().parse(stream);
    Bundle b;
    if (r5 instanceof Bundle)
        b = (Bundle) r5;
    else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
    }
    for (CodeSystem cs : cslist) {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    }
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
                sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
                for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
                for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
            }
        }
    }
    return b;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) ArrayList(java.util.ArrayList) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 25 with UriType

use of org.hl7.fhir.r4b.model.UriType 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

FHIRException (org.hl7.fhir.exceptions.FHIRException)60 UriType (org.hl7.fhir.r5.model.UriType)45 ArrayList (java.util.ArrayList)42 UriType (org.hl7.fhir.r4.model.UriType)41 UriType (org.hl7.fhir.r4b.model.UriType)29 UriType (org.hl7.fhir.dstu3.model.UriType)26 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)19 List (java.util.List)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 UriType (org.hl7.fhir.dstu2016may.model.UriType)12 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 Coding (org.hl7.fhir.r4.model.Coding)12 IOException (java.io.IOException)11 StringType (org.hl7.fhir.r4.model.StringType)10 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)10 StringType (org.hl7.fhir.r5.model.StringType)10