Search in sources :

Example 56 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project kindling by HL7.

the class JsonLDGenerator method generateElement.

private void generateElement(ElementDefn root, String name, ElementDefn e, JsonObject base, Set<String> types) throws Exception {
    if ((e.getTypes().size() == 1 && e.getTypes().get(0).isWildcardType())) {
        if (!e.getName().contains("[x]"))
            throw new Exception("Element " + e.getName() + " in " + root.getName() + " has multiple types as a choice doesn't have a [x] in the element name");
        for (TypeRef tr : datatypes) {
            String tn = tr.getName();
            if (tn.equals("SimpleQuantity"))
                tn = "Quantity";
            else
                tn = Utilities.capitalize(tn);
            String en = e.getName().substring(0, e.getName().length() - 3) + tn;
            JsonObject property = new JsonObject();
            base.add(name + "." + en, property);
            property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + en);
        }
    // if (e.getTypes().size() == 1)
    // generateAny(root, e, e.getName().replace("[x]", ""), props, relative);
    // else {
    // for (TypeRef t : e.getTypes()) {
    // JsonObject property = new JsonObject();
    // JsonObject property_ = null;
    // String en = e.getName().replace("[x]",  "");
    // props.add(en+upFirst(t.getName()), property);
    // property.addProperty("description", e.getDefinition());
    // String tref = null;
    // String type = null;
    // String pattern = null;
    // if (definitions.getPrimitives().containsKey(t.getName())) {
    // DefinedCode def = definitions.getPrimitives().get(t.getName());
    // type = def.getJsonType();
    // pattern = def.getRegex();
    // if (!Utilities.noString(pattern))
    // property.addProperty("pattern", pattern);
    // 
    // property.addProperty("type", type);
    // property_ = new JsonObject();
    // props.add("_"+en+upFirst(t.getName()), property_);
    // property_.addProperty("description", "Extensions for "+en+upFirst(t.getName()));
    // tref = (relative ? "#" : "Element.schema.json#") +"/definitions/Element";
    // property_.addProperty("$ref", tref);
    // } else {
    // String tn = encodeType(e, t, true);
    // tref = (relative ? "#" : tn.replace(".",  "_")+".schema.json#") +"/definitions/"+tn.replace(".",  "_");
    // property.addProperty("$ref", tref);
    // }
    // }
    // }
    } else if (e.getName().endsWith("[x]")) {
        for (TypeRef tr : e.getTypes()) {
            String tn = tr.getName();
            if (tn.equals("SimpleQuantity"))
                tn = "Quantity";
            else
                tn = Utilities.capitalize(tn);
            String en = e.getName().substring(0, e.getName().length() - 3) + tn;
            JsonObject property = new JsonObject();
            base.add(name + "." + en, property);
            property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + en);
        }
    } else {
        JsonObject property = new JsonObject();
        base.add(name + "." + e.getName(), property);
        if (e.getPath() == null)
            property.addProperty("@id", "http://hl7.org/fhir/" + name + "." + e.getName());
        else
            property.addProperty("@id", "http://hl7.org/fhir/" + e.getPath());
    // if we're using lists:
    // if (e.unbounded())
    // property.addProperty("@container", "@list");
    // property.addProperty("fhir-@type", "http://hl7.org/fhir/"+e.typeCode());
    // String tref = null;
    // String type = null;
    // String pattern = null;
    // 
    // if (e.usesCompositeType()/* && types.containsKey(root.getElementByName(e.typeCode().substring(1)))*/) {
    // ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false);
    // String rtn = types.get(ref);
    // if (rtn == null)
    // throw new Exception("logic error in schema generator (null composite reference in "+types.toString()+")");
    // 
    // if(rtn == "Type")
    // rtn = "Element";
    // type=rtn;
    // tref = "#/definitions/"+rtn.replace(".",  "_");
    // } else if (e.getTypes().size() == 0 && e.getElements().size() > 0){
    // tref = "#/definitions/"+types.get(e).replace(".",  "_");
    // type=types.get(e).replace(".",  "_");
    // }	else if (e.getTypes().size() == 1) {
    // String tn = encodeType(e, e.getTypes().get(0), true);
    // type=tn;
    // if (definitions.getPrimitives().containsKey(e.typeCode())) {
    // DefinedCode def = definitions.getPrimitives().get(e.typeCode());
    // type = def.getJsonType();
    // pattern = def.getRegex();
    // property_ = new JsonObject();
    // props.add("_"+e.getName(), property_);
    // property_.addProperty("description", "Extensions for "+e.getName());
    // tref = (relative ? "#" : "Element.schema.json#") +"/definitions/Element";
    // BindingSpecification cd = e.getBinding();
    // 
    // if (cd != null && (cd.getBinding() == BindingSpecification.BindingMethod.CodeList)) {
    // ValueSet vs = cd.getValueSet();
    // if (vs!= null) {
    // ValueSet ex = workerContext.expandVS(vs, true, false).getValueset();
    // JsonArray enums = new JsonArray();
    // for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
    // enums.add(new JsonPrimitive(cc.getCode()));
    // }
    // property.add("enum", enums);
    // pattern = null;
    // }
    // }
    // } else {
    // tref = (relative ? "#" : tn.replace(".",  "_")+".schema.json#") +"/definitions/"+tn.replace(".",  "_");
    // }
    // } else
    // throw new Exception("how do we get here? "+e.getName()+" in "+root.getName()+" "+Integer.toString(e.getTypes().size()));
    // 
    // if (e.unbounded()) {
    // property.addProperty("type", "array");
    // if (property_ != null) {
    // property_.addProperty("type", "array");
    // JsonObject items = new JsonObject();
    // property.add("items", items);
    // items.addProperty("type", type);
    // if (!Utilities.noString(pattern))
    // items.addProperty("pattern", pattern);
    // 
    // items = new JsonObject();
    // property_.add("items", items);
    // items.addProperty("$ref", tref);
    // } else {
    // JsonObject items = new JsonObject();
    // property.add("items", items);
    // items.addProperty("$ref", tref);
    // }
    // } else {
    // if (property_ != null) {
    // property.addProperty("type", type);
    // if (!Utilities.noString(pattern))
    // property.addProperty("pattern", pattern);
    // 
    // property_.addProperty("$ref", tref);
    // } else if("div".equals(e.getName()) && "xhtml".equals(type)) {
    // // Is there a better type, or ref for html?
    // property.addProperty("type", "string");
    // } else {
    // property.addProperty("$ref", tref);
    // }
    // }
    // if (e.getMinCardinality() > 0 && property_ == null)
    // required.add(e.getName());
    }
}
Also used : TypeRef(org.hl7.fhir.definitions.model.TypeRef) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 57 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project kindling by HL7.

the class XSDBaseGenerator method generateEnum.

private void generateEnum(BindingSpecification bs) throws IOException {
    String en = bs.getValueSet().getName();
    if (genEnums.contains(en))
        return;
    write("  <xs:simpleType name=\"" + en + "-list\">\r\n");
    write("    <xs:restriction base=\"code-primitive\">\r\n");
    bs.getValueSet().setUserData(ToolResourceUtilities.NAME_VS_USE_MARKER, true);
    ValueSet ex = workerContext.expandVS(bs.getValueSet(), true, false).getValueset();
    if (ex == null)
        throw new Error("The expansion for " + bs.getName() + " is null");
    if (ex.getExpansion().getContains().isEmpty())
        throw new Error("The expansion for " + bs.getName() + " is empty");
    for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
        genIncludedCode(cc);
    }
    write("    </xs:restriction>\r\n");
    write("  </xs:simpleType>\r\n");
    write("  <xs:complexType name=\"" + en + "\">\r\n");
    write("    <xs:annotation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(enumDefs.get(en)) + "</xs:documentation>\r\n");
    write("      <xs:documentation xml:lang=\"en\">If the element is present, it must have either a @value, an @id, or extensions</xs:documentation>\r\n");
    write("    </xs:annotation>\r\n");
    write("    <xs:complexContent>\r\n");
    write("       <xs:extension base=\"Element\">\r\n");
    write("         <xs:attribute name=\"value\" type=\"" + en + "-list\" use=\"optional\"/>\r\n");
    write("       </xs:extension>\r\n");
    write("     </xs:complexContent>\r\n");
    write("  </xs:complexType>\r\n");
    genEnums.add(en);
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet)

Example 58 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project kindling by HL7.

the class XSDBaseGenerator method genIncludedCode.

private void genIncludedCode(ValueSetExpansionContainsComponent cc) throws IOException {
    write("      <xs:enumeration value=\"" + Utilities.escapeXml(cc.getCode()) + "\">\r\n");
    write("        <xs:annotation>\r\n");
    // todo: do we need to look the definition up?
    write("          <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(cc.getDisplay()) + "</xs:documentation>\r\n");
    CodeSystem cs = workerContext.fetchCodeSystem(cc.getSystem());
    if (cs != null && cc.hasCode()) {
        ConceptDefinitionComponent c = getCodeDefinition(cc.getCode(), cs.getConcept());
        if (c != null && c.hasDesignation()) {
            for (ConceptDefinitionDesignationComponent l : c.getDesignation()) {
                if (l.hasLanguage()) {
                    write("          <xs:documentation xml:lang=\"" + l.getLanguage() + "\">" + Utilities.escapeXml(l.getValue()) + "</xs:documentation>\r\n");
                }
            }
        }
    }
    write("        </xs:annotation>\r\n");
    write("      </xs:enumeration>\r\n");
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ConceptDefinitionDesignationComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Example 59 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project kindling by HL7.

the class JsonGenerator method generateElement.

private void generateElement(ElementDefn root, ElementDefn e, Set<String> required, JsonObject props, boolean relative) throws Exception {
    if (e.getTypes().size() > 1 || (e.getTypes().size() == 1 && e.getTypes().get(0).isWildcardType())) {
        if (!e.getName().contains("[x]"))
            throw new Exception("Element " + e.getName() + " in " + root.getName() + " has multiple types as a choice doesn't have a [x] in the element name");
        if (e.getTypes().size() == 1)
            generateAny(root, e, e.getName().replace("[x]", ""), props, relative);
        else {
            for (TypeRef t : e.getTypes()) {
                JsonObject property = new JsonObject();
                JsonObject property_ = null;
                TypeDefn td = null;
                if (definitions.getConstraints().containsKey(t.getName()))
                    td = definitions.getElementDefn(definitions.getConstraints().get(t.getName()).getBaseType());
                else if (definitions.hasElementDefn(t.getName()))
                    td = definitions.getElementDefn(t.getName());
                String en = e.getName().replace("[x]", "");
                props.add(en + upFirst(td == null ? t.getName() : td.getName()), property);
                property.addProperty("description", e.getDefinition());
                String tref = null;
                String type = null;
                String pattern = null;
                if (definitions.getPrimitives().containsKey(t.getName())) {
                    DefinedCode def = definitions.getPrimitives().get(t.getName());
                    type = def.getJsonType();
                    pattern = def.getRegex();
                    if (!Utilities.noString(pattern))
                        property.addProperty("pattern", "^" + pattern + "$");
                    property.addProperty("type", type);
                    property_ = new JsonObject();
                    props.add("_" + en + upFirst(t.getName()), property_);
                    property_.addProperty("description", "Extensions for " + en + upFirst(t.getName()));
                    tref = (relative ? "#" : "Element.schema.json#") + "/definitions/Element";
                    property_.addProperty("$ref", tref);
                } else {
                    String tn = encodeType(e, t, true);
                    tref = (relative ? "#" : tn.replace(".", "_") + ".schema.json#") + "/definitions/" + tn.replace(".", "_");
                    property.addProperty("$ref", tref);
                }
            }
        }
    } else {
        JsonObject property = new JsonObject();
        JsonObject property_ = null;
        props.add(e.getName(), property);
        property.addProperty("description", e.getDefinition());
        String tref = null;
        String type = null;
        String pattern = null;
        if (e.usesCompositeType()) /* && types.containsKey(root.getElementByName(e.typeCode().substring(1)))*/
        {
            ElementDefn ref = root.getElementByName(definitions, e.typeCode().substring(1), true, false, null);
            String rtn = types.get(ref);
            if (rtn == null)
                throw new Exception("logic error in schema generator (null composite reference in " + types.toString() + ")");
            if (rtn == "Type")
                rtn = "Element";
            type = rtn;
            tref = "#/definitions/" + rtn.replace(".", "_");
        } else if (e.getTypes().size() == 0 && e.getElements().size() > 0) {
            tref = "#/definitions/" + types.get(e).replace(".", "_");
            type = types.get(e).replace(".", "_");
        } else if (e.getTypes().size() == 1) {
            String tn = encodeType(e, e.getTypes().get(0), true);
            tref = "#/definitions/" + tn;
            if (definitions.getPrimitives().containsKey(e.typeCode())) {
                DefinedCode def = definitions.getPrimitives().get(e.typeCode());
                if (e.getName().equals("id")) {
                    tref = (relative ? "#" : tn.replace(".", "_") + ".schema.json#") + "/definitions/" + tn.replace(".", "_");
                    property.addProperty("$ref", tref);
                } else {
                    property_ = new JsonObject();
                    props.add("_" + e.getName(), property_);
                    property_.addProperty("description", "Extensions for " + e.getName());
                    BindingSpecification cd = e.getBinding();
                    if (cd != null && (cd.getBinding() == BindingSpecification.BindingMethod.CodeList)) {
                        ValueSet vs = cd.getValueSet();
                        if (vs != null) {
                            ValueSet ex = workerContext.expandVS(vs, true, false).getValueset();
                            JsonArray enums = new JsonArray();
                            for (ValueSetExpansionContainsComponent cc : ex.getExpansion().getContains()) {
                                enums.add(new JsonPrimitive(cc.getCode()));
                            }
                            property.add("enum", enums);
                            pattern = null;
                        }
                    } else {
                        property.addProperty("$ref", tref);
                    }
                    tref = (relative ? "#" : "Element.schema.json#") + "/definitions/Element";
                }
            } else {
                tref = (relative ? "#" : tn.replace(".", "_") + ".schema.json#") + "/definitions/" + tn.replace(".", "_");
            }
        } else
            throw new Exception("how do we get here? " + e.getName() + " in " + root.getName() + " " + Integer.toString(e.getTypes().size()));
        if (property_ != null) {
            if (!Utilities.noString(type))
                property.addProperty("type", type);
            if (!Utilities.noString(pattern))
                property.addProperty("pattern", "^" + pattern + "$");
            if (!Utilities.noString(tref))
                property_.addProperty("$ref", tref);
        } else if ("div".equals(e.getName()) && "xhtml".equals(type)) {
            // Is there a better type, or ref for html?
            property.addProperty("type", "string");
        } else {
            property.addProperty("$ref", tref);
        }
        if (e.unbounded()) {
            makeArray(property);
            if (property_ != null)
                makeArray(property_);
        }
        if (e.getMinCardinality() > 0 && property_ == null)
            required.add(e.getName());
    }
}
Also used : TypeDefn(org.hl7.fhir.definitions.model.TypeDefn) JsonArray(com.google.gson.JsonArray) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) JsonPrimitive(com.google.gson.JsonPrimitive) TypeRef(org.hl7.fhir.definitions.model.TypeRef) DefinedCode(org.hl7.fhir.definitions.model.DefinedCode) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) BindingSpecification(org.hl7.fhir.definitions.model.BindingSpecification) JsonObject(com.google.gson.JsonObject) ValueSet(org.hl7.fhir.r5.model.ValueSet) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 60 with ValueSetExpansionContainsComponent

use of org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent in project kindling by HL7.

the class XSDGenerator method genIncludedCode.

private void genIncludedCode(ValueSetExpansionContainsComponent cc) throws IOException {
    write("      <xs:enumeration value=\"" + Utilities.escapeXml(cc.getCode()) + "\">\r\n");
    write("        <xs:annotation>\r\n");
    // todo: do we need to look the definition up?
    write("          <xs:documentation xml:lang=\"en\">" + Utilities.escapeXml(cc.getDisplay()) + "</xs:documentation>\r\n");
    CodeSystem cs = workerContext.fetchCodeSystem(cc.getSystem());
    if (cs != null && cc.hasCode()) {
        ConceptDefinitionComponent c = getCodeDefinition(cc.getCode(), cs.getConcept());
        if (c != null)
            for (ConceptDefinitionDesignationComponent l : c.getDesignation()) if (l.hasLanguage())
                write("          <xs:documentation xml:lang=\"" + l.getLanguage() + "\">" + Utilities.escapeXml(l.getValue()) + "</xs:documentation>\r\n");
    }
    write("        </xs:annotation>\r\n");
    write("      </xs:enumeration>\r\n");
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) ConceptDefinitionDesignationComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Aggregations

ValueSetExpansionContainsComponent (org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent)32 ValueSetExpansionContainsComponent (org.hl7.fhir.r4b.model.ValueSet.ValueSetExpansionContainsComponent)22 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)20 ValueSetExpansionContainsComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent)17 ValueSet (org.hl7.fhir.r4.model.ValueSet)9 HashMap (java.util.HashMap)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 ArrayList (java.util.ArrayList)7 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent)7 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent)7 IOException (java.io.IOException)6 ValueSetExpansionContainsComponent (org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent)6 ValueSetExpansionComponent (org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionComponent)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)5 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)5 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)5 ValueSet (org.hl7.fhir.dstu2016may.model.ValueSet)4 ValueSet (org.hl7.fhir.r4b.model.ValueSet)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)3