Search in sources :

Example 21 with CanonicalType

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

the class ConceptMap10_40 method convertConceptMap.

public static org.hl7.fhir.r4.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2.model.ConceptMap src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r4.model.ConceptMap tgt = new org.hl7.fhir.r4.model.ConceptMap();
    ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyDomainResource(src, tgt);
    if (src.hasUrlElement())
        tgt.setUrlElement(Uri10_40.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.setIdentifier(Identifier10_40.convertIdentifier(src.getIdentifier()));
    if (src.hasVersionElement())
        tgt.setVersionElement(String10_40.convertString(src.getVersionElement()));
    if (src.hasNameElement())
        tgt.setNameElement(String10_40.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations10_40.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean10_40.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisherElement())
        tgt.setPublisherElement(String10_40.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime10_40.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_10_40.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept10_40.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept10_40.convertCodeableConceptToUsageContext(t));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    org.hl7.fhir.r4.model.Type r = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getSource());
    tgt.setSource(r instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) r).getReference()) : r);
    r = ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().convertType(src.getTarget());
    tgt.setTarget(r instanceof org.hl7.fhir.r4.model.Reference ? new CanonicalType(((org.hl7.fhir.r4.model.Reference) r).getReference()) : r);
    for (org.hl7.fhir.dstu2.model.ConceptMap.SourceElementComponent t : src.getElement()) {
        List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> ws = convertSourceElementComponent(t);
        for (SourceElementComponentWrapper<ConceptMap.SourceElementComponent> w : ws) getGroup(tgt, w.getSource(), w.getTarget()).addElement(w.getComp());
    }
    return tgt;
}
Also used : ConceptMap(org.hl7.fhir.r4.model.ConceptMap) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ConceptMap(org.hl7.fhir.r4.model.ConceptMap) SourceElementComponentWrapper(org.hl7.fhir.convertors.SourceElementComponentWrapper)

Example 22 with CanonicalType

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

the class ConceptMap14_50 method convertConceptMap.

public static org.hl7.fhir.r5.model.ConceptMap convertConceptMap(org.hl7.fhir.dstu2016may.model.ConceptMap src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.ConceptMap tgt = new org.hl7.fhir.r5.model.ConceptMap();
    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyDomainResource(src, tgt);
    if (src.hasUrl())
        tgt.setUrlElement(Uri14_50.convertUri(src.getUrlElement()));
    if (src.hasIdentifier())
        tgt.addIdentifier(Identifier14_50.convertIdentifier(src.getIdentifier()));
    if (src.hasVersion())
        tgt.setVersionElement(String14_50.convertString(src.getVersionElement()));
    if (src.hasName())
        tgt.setNameElement(String14_50.convertString(src.getNameElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations14_50.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean14_50.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisher())
        tgt.setPublisherElement(String14_50.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2016may.model.ConceptMap.ConceptMapContactComponent t : src.getContact()) tgt.addContact(convertConceptMapContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime14_50.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2016may.model.CodeableConcept t : src.getUseContext()) if (CodeableConcept14_50.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept14_50.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept14_50.convertCodeableConceptToUsageContext(t));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    org.hl7.fhir.r5.model.DataType tt = ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getSource());
    tgt.setSource(tt instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) tt).getReference()) : tt);
    tt = ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getTarget());
    tgt.setTarget(tt instanceof org.hl7.fhir.r5.model.Reference ? new CanonicalType(((org.hl7.fhir.r5.model.Reference) tt).getReference()) : tt);
    for (org.hl7.fhir.dstu2016may.model.ConceptMap.SourceElementComponent t : src.getElement()) {
        List<SourceElementComponentWrapper<ConceptMap.SourceElementComponent>> ws = convertSourceElementComponent(t);
        for (SourceElementComponentWrapper<ConceptMap.SourceElementComponent> w : ws) getGroup(tgt, w.getSource(), w.getTarget()).addElement(w.getComp());
    }
    return tgt;
}
Also used : CanonicalType(org.hl7.fhir.r5.model.CanonicalType) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) SourceElementComponentWrapper(org.hl7.fhir.convertors.SourceElementComponentWrapper)

Example 23 with CanonicalType

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

the class ConceptMap40_50 method convertUriAndVersionToCanonical.

private static CanonicalType convertUriAndVersionToCanonical(org.hl7.fhir.r4.model.UriType srcUri, org.hl7.fhir.r4.model.StringType srcVersion) {
    if (srcUri == null && srcVersion == null)
        return null;
    org.hl7.fhir.r5.model.CanonicalType tgt = new org.hl7.fhir.r5.model.CanonicalType();
    ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(srcUri == null ? srcVersion : srcUri, tgt);
    if (srcUri.hasValue()) {
        if (srcVersion.hasValue()) {
            tgt.setValue(srcUri.getValue() + "|" + srcVersion.getValue());
        } else {
            tgt.setValue(srcUri.getValue());
        }
    }
    return tgt;
}
Also used : CanonicalType(org.hl7.fhir.r5.model.CanonicalType) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 24 with CanonicalType

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

the class JavaResourceGenerator method resolvedTypeCode.

private String resolvedTypeCode(ElementDefinition e, String tf) {
    if (e.hasContentReference()) {
        return e.getContentReference().replace("#", "@");
    }
    StringBuilder tn = new StringBuilder();
    boolean first = true;
    for (TypeRefComponent t : e.getType()) {
        if ((tf == null || t.getWorkingCode().equals(tf)) && !Utilities.existsInList(t.getWorkingCode(), "Element", "BackboneElement")) {
            if (!first)
                tn.append("|");
            first = false;
            tn.append(t.getWorkingCode());
            if (t.hasTargetProfile()) {
                tn.append("(");
                boolean f = true;
                for (CanonicalType s : t.getTargetProfile()) {
                    // } else {
                    if (!f)
                        tn.append("|");
                    f = false;
                    String stn = s.asStringValue().substring(40);
                    tn.append("Resource".equals(stn) ? "Any" : stn);
                // }
                }
                tn.append(")");
            }
        }
    }
    return tn.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 25 with CanonicalType

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

the class JavaParserJsonGenerator method genElementComposer.

private void genElementComposer(Analysis analysis, TypeInfo ti, ElementDefinition ed, ElementDefinition inh) throws Exception {
    String name = ed.getName();
    if (name.endsWith("[x]") || name.equals("[type]")) {
        String en = name.endsWith("[x]") && !name.equals("[x]") ? name.replace("[x]", "") : "value";
        String pfx = name.endsWith("[x]") ? name.replace("[x]", "") : "";
        composer.append("      if (element.has" + upFirst(en) + "()) {\r\n");
        composer.append("        composeType(\"" + pfx + "\", element.get" + upFirst(en) + "());\r\n");
        composer.append("      }\r\n");
    } else {
        String tn = ed.getUserString("java.type");
        String comp = null;
        String en = null;
        boolean enShared = false;
        if (ed.hasUserData("java.enum")) {
            // getCodeListType(cd.getBinding());
            EnumInfo ei = (EnumInfo) ed.getUserData("java.enum");
            ValueSet vs = ei.getValueSet();
            enShared = vs.hasUserData("shared");
            if (enShared) {
                en = "Enumerations." + ei.getName();
            } else {
                en = analysis.getClassName() + "." + ei.getName();
            }
        } else {
            if (name.equals("extension")) {
                name = "extension";
                tn = "Extension";
            }
            if (tn.equals("XhtmlNode")) {
                tn = "xhtml";
                comp = "composeXhtml";
            } else if (tn.equals("code")) {
                tn = "Code";
                comp = "composeCode";
            } else if (tn.equals("instant")) {
                tn = "Instant";
            } else if (tn.contains("Reference(")) {
                comp = "composeReference";
                tn = "Reference";
            } else if (tn.contains("canonical(")) {
                comp = "composeCanonical";
                tn = "CanonicalType";
            } else if (tn.contains("(")) {
                comp = "compose" + tn;
            } else if (tn.startsWith(analysis.getName()) && !tn.equals(analysis.getClassName())) {
                comp = "compose" + leaf(tn);
            } else if (isPrimitive(ed)) {
                comp = "compose" + leaf(tn);
                // remove Type"
                comp = comp.substring(0, comp.length() - 4);
            } else {
                comp = "compose" + leaf(tn);
            }
        }
        if (ed.unbounded()) {
            tn = ed.getUserString("java.type");
            if (tn.contains("Reference(")) {
                comp = "composeReference";
                tn = "Reference";
            } else if (tn.contains("canonical(")) {
                comp = "composeCanonical";
                tn = "CanonicalType";
            }
            String stn = tn;
            if (ed.isInlineType() || ed.hasContentReference()) {
                stn = analysis.getClassName() + "." + tn;
            }
            composer.append("      if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
            if (en == null) {
                if (tn.equals("String"))
                    tn = "StringType";
                if (definitions.hasPrimitiveType(tn)) {
                    tn = upFirst(tn) + "Type";
                }
                if (isPrimitive(ed) || ed.typeSummary().startsWith("canonical(")) {
                    composer.append("        if (anyHasValue(element.get" + upFirst(getElementName(name, false)) + "())) {\r\n");
                    composer.append("          openArray(\"" + name + "\");\r\n");
                    composer.append("          for (" + (tn.contains("(") ? stn : upFirst(tn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
                    composer.append("            " + comp + "Core(null, e, e != element.get" + upFirst(getElementName(name, false)) + "().get(element.get" + upFirst(getElementName(name, false)) + "().size()-1));\r\n");
                    composer.append("          closeArray();\r\n");
                    composer.append("        }\r\n");
                    composer.append("        if (anyHasExtras(element.get" + upFirst(getElementName(name, false)) + "())) {\r\n");
                    composer.append("          openArray(\"_" + name + "\");\r\n");
                    composer.append("          for (" + (stn.contains("(") ? stn : upFirst(stn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
                    composer.append("            " + comp + "Extras(null, e, true);\r\n");
                    composer.append("          closeArray();\r\n");
                    composer.append("        }\r\n");
                } else if (ed.typeSummary().equals("Resource")) {
                    composer.append("        openArray(\"" + name + "\");\r\n");
                    composer.append("        for (" + (stn.contains("(") ? tn : upFirst(tn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) {\r\n");
                    composer.append("          open(null);\r\n");
                    composer.append("          " + comp + "(e);\r\n");
                    composer.append("          close();\r\n");
                    composer.append("        }\r\n");
                    composer.append("        closeArray();\r\n");
                } else {
                    composer.append("        openArray(\"" + name + "\");\r\n");
                    composer.append("        for (" + (stn.contains("(") ? stn : upFirst(stn)) + " e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
                    composer.append("          " + comp + "(null, e);\r\n");
                    composer.append("        closeArray();\r\n");
                }
            } else {
                composer.append("        openArray(\"" + name + "\");\r\n");
                composer.append("        for (Enumeration<" + prepEnumName(en) + "> e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
                composer.append("          composeEnumerationCore(null, e, new " + prepEnumName(en) + "EnumFactory(), true);\r\n");
                composer.append("        closeArray();\r\n");
                composer.append("        if (anyHasExtras(element.get" + upFirst(getElementName(name, false)) + "())) {\r\n");
                composer.append("          openArray(\"_" + name + "\");\r\n");
                composer.append("          for (Enumeration<" + prepEnumName(en) + "> e : element.get" + upFirst(getElementName(name, false)) + "()) \r\n");
                composer.append("            composeEnumerationExtras(null, e, new " + prepEnumName(en) + "EnumFactory(), true);\r\n");
                composer.append("          closeArray();\r\n");
                composer.append("        }\r\n");
            }
            composer.append("      };\r\n");
        } else if (en != null) {
            composer.append("      if (element.has" + upFirst(getElementName(name, false)) + "Element()) {\r\n");
            if (enShared) {
                composer.append("        composeEnumerationCore(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
                composer.append("        composeEnumerationExtras(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
            } else {
                composer.append("        composeEnumerationCore(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
                composer.append("        composeEnumerationExtras(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), new " + prepEnumName(en) + "EnumFactory(), false);\r\n");
            }
            composer.append("      }\r\n");
        // composer.append("        composeString(\""+name+"\", element.get"+upFirst(getElementName(name, false))+"().toCode());\r\n");
        } else if (ed.typeSummary().equals("Resource")) {
            composer.append("        if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
            composer.append("          open(\"" + name + "\");\r\n");
            composer.append("          " + comp + "(element.get" + upFirst(getElementName(name, false)) + "());\r\n");
            composer.append("          close();\r\n");
            composer.append("        }\r\n");
        } else if (!"xhtml".equals(ed.typeSummary()) && (isPrimitive(ed) || ed.typeSummary().startsWith("canonical("))) {
            composer.append("      if (element.has" + upFirst(getElementName(name, false)) + "Element()) {\r\n");
            composer.append("        " + comp + "Core(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), false);\r\n");
            composer.append("        " + comp + "Extras(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "Element(), false);\r\n");
            composer.append("      }\r\n");
        } else if (tn.equals("xhtml")) {
            composer.append("      if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
            composer.append("        XhtmlNode node = element.getDiv();\r\n");
            composer.append("        if (node.getNsDecl() == null) {\r\n");
            composer.append("          node.attribute(\"xmlns\", XHTML_NS);\r\n");
            composer.append("        }\r\n");
            composer.append("        " + comp + "(\"" + name + "\", node);\r\n");
            composer.append("      }\r\n");
        } else if (inh != null && inh.unbounded()) {
            composer.append("      if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
            composer.append("        " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "FirstRep());\r\n");
            composer.append("      }\r\n");
        } else {
            composer.append("      if (element.has" + upFirst(getElementName(name, false)) + "()) {\r\n");
            composer.append("        " + comp + "(\"" + name + "\", element.get" + upFirst(getElementName(name, false)) + "());\r\n");
            composer.append("      }\r\n");
        }
    }
}
Also used : EnumInfo(org.hl7.fhir.core.generator.analysis.EnumInfo) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)45 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)27 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Extension (org.hl7.fhir.r4.model.Extension)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Bundle (org.hl7.fhir.r4.model.Bundle)5 IdType (org.hl7.fhir.r4.model.IdType)5