Search in sources :

Example 11 with ValueSetExpansionContainsComponent

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

the class JavaEnumerationsGenerator method generateEnum.

private void generateEnum(String name, ValueSet vs) throws Exception {
    String url = vs.getUrl();
    CommaSeparatedStringBuilder el = new CommaSeparatedStringBuilder();
    write("    public enum " + name + " {\r\n");
    int l = vs.getExpansion().getContains().size();
    int i = 0;
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        i++;
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        el.append(cc);
        write("        /**\r\n");
        write("         * " + definitions.getCodeDefinition(c.getSystem(), c.getCode()) + "\r\n");
        write("         */\r\n");
        write("        " + cc.toUpperCase() + ", \r\n");
    }
    write("        /**\r\n");
    write("         * added to help the parsers\r\n");
    write("         */\r\n");
    write("        NULL;\r\n");
    el.append("NULL");
    write("        public static " + name + " fromCode(String codeString) throws FHIRException {\r\n");
    write("            if (codeString == null || \"\".equals(codeString))\r\n");
    write("                return null;\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("        if (\"" + c.getCode() + "\".equals(codeString))\r\n");
        write("          return " + cc + ";\r\n");
    }
    write("        throw new FHIRException(\"Unknown " + name + " code '\"+codeString+\"'\");\r\n");
    write("        }\r\n");
    write("        public String toCode() {\r\n");
    write("          switch (this) {\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("            case " + cc + ": return \"" + c.getCode() + "\";\r\n");
    }
    write("            case NULL: return null;\r\n");
    write("            default: return \"?\";\r\n");
    write("          }\r\n");
    write("        }\r\n");
    write("        public String getSystem() {\r\n");
    write("          switch (this) {\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("            case " + cc + ": return \"" + c.getSystem() + "\";\r\n");
    }
    write("            case NULL: return null;\r\n");
    write("            default: return \"?\";\r\n");
    write("          }\r\n");
    write("        }\r\n");
    write("        public String getDefinition() {\r\n");
    write("          switch (this) {\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("            case " + cc + ": return \"" + Utilities.escapeJava(definitions.getCodeDefinition(c.getSystem(), c.getCode())) + "\";\r\n");
    }
    write("            case NULL: return null;\r\n");
    write("            default: return \"?\";\r\n");
    write("          }\r\n");
    write("        }\r\n");
    write("        public String getDisplay() {\r\n");
    write("          switch (this) {\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("            case " + cc + ": return \"" + Utilities.escapeJava(Utilities.noString(c.getDisplay()) ? c.getCode() : c.getDisplay()) + "\";\r\n");
    }
    write("            case NULL: return null;\r\n");
    write("            default: return \"?\";\r\n");
    write("          }\r\n");
    write("        }\r\n");
    if (config.getAdornments().containsKey(name)) {
        write("// manual code from configuration.txt:\r\n");
        write(config.getAdornments().get(name) + "\r\n");
        write("// end addition\r\n");
    }
    write("    }\r\n");
    write("\r\n");
    write("  public static class " + name + "EnumFactory implements EnumFactory<" + name + "> {\r\n");
    write("    public " + name + " fromCode(String codeString) throws IllegalArgumentException {\r\n");
    write("      if (codeString == null || \"\".equals(codeString))\r\n");
    write("            if (codeString == null || \"\".equals(codeString))\r\n");
    write("                return null;\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("        if (\"" + c.getCode() + "\".equals(codeString))\r\n");
        write("          return " + name + "." + cc + ";\r\n");
    }
    write("        throw new IllegalArgumentException(\"Unknown " + name + " code '\"+codeString+\"'\");\r\n");
    write("        }\r\n");
    write("        public Enumeration<" + name + "> fromType(Base code) throws FHIRException {\r\n");
    write("          if (code == null)\r\n");
    write("            return null;\r\n");
    write("          if (code.isEmpty())\r\n");
    write("            return new Enumeration<" + name + ">(this);\r\n");
    write("          String codeString = ((PrimitiveType) code).asStringValue();\r\n");
    write("          if (codeString == null || \"\".equals(codeString))\r\n");
    write("            return null;\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("        if (\"" + c.getCode() + "\".equals(codeString))\r\n");
        write("          return new Enumeration<" + name + ">(this, " + name + "." + cc + ");\r\n");
    }
    write("        throw new FHIRException(\"Unknown " + name + " code '\"+codeString+\"'\");\r\n");
    write("        }\r\n");
    write("    public String toCode(" + name + " code) {\r\n");
    for (ValueSetExpansionContainsComponent c : vs.getExpansion().getContains()) {
        String cc = Utilities.camelCase(c.getCode());
        cc = makeConst(cc);
        write("      if (code == " + name + "." + cc + ")\r\n        return \"" + c.getCode() + "\";\r\n");
    }
    write("      return \"?\";\r\n");
    write("      }\r\n");
    write("    public String toSystem(" + name + " code) {\r\n");
    write("      return code.getSystem();\r\n");
    write("      }\r\n");
    write("    }\r\n");
    write("\r\n");
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 12 with ValueSetExpansionContainsComponent

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

the class ProfileComparer method intersectByExpansion.

private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
    // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
    ValueSet vs = new ValueSet();
    vs.setStatus(ConformanceResourceStatus.DRAFT);
    Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(lvs.getExpansion().getContains(), left);
    Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(rvs.getExpansion().getContains(), right);
    Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
    for (String s : left.keySet()) {
        if (right.containsKey(s)) {
            ValueSetExpansionContainsComponent cc = left.get(s);
            ConceptSetComponent c = inc.get(cc.getSystem());
            if (c == null) {
                c = vs.getCompose().addInclude().setSystem(cc.getSystem());
                inc.put(cc.getSystem(), c);
            }
            c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
        }
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.dstu2.model.ValueSet)

Example 13 with ValueSetExpansionContainsComponent

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

the class NarrativeGenerator method addExpansionRowToTable.

private void addExpansionRowToTable(XhtmlNode t, ValueSetExpansionContainsComponent c, int i, boolean doSystem, Map<ConceptMap, String> mymaps) {
    XhtmlNode tr = t.addTag("tr");
    XhtmlNode td = tr.addTag("td");
    String tgt = makeAnchor(c.getSystem(), c.getCode());
    td.addTag("a").setAttribute("name", tgt).addText(" ");
    String s = Utilities.padLeft("", '.', i * 2);
    td.addText(s);
    Resource e = context.fetchCodeSystem(c.getSystem());
    if (e == null)
        td.addText(c.getCode());
    else {
        XhtmlNode a = td.addTag("a");
        a.addText(c.getCode());
        a.setAttribute("href", prefix + getCsRef(e) + "#" + Utilities.nmtokenize(c.getCode()));
    }
    if (doSystem) {
        td = tr.addTag("td");
        td.addText(c.getSystem());
    }
    td = tr.addTag("td");
    if (c.hasDisplayElement())
        td.addText(c.getDisplay());
    for (ConceptMap m : mymaps.keySet()) {
        td = tr.addTag("td");
        List<TargetElementComponent> mappings = findMappingsForCode(c.getCode(), m);
        boolean first = true;
        for (TargetElementComponent mapping : mappings) {
            if (!first)
                td.addTag("br");
            first = false;
            XhtmlNode span = td.addTag("span");
            span.setAttribute("title", mapping.getEquivalence().toString());
            span.addText(getCharForEquivalence(mapping));
            XhtmlNode a = td.addTag("a");
            a.setAttribute("href", prefix + mymaps.get(m) + "#" + mapping.getCode());
            a.addText(mapping.getCode());
            if (!Utilities.noString(mapping.getComments()))
                td.addTag("i").addText("(" + mapping.getComments() + ")");
        }
    }
    for (ValueSetExpansionContainsComponent cc : c.getContains()) {
        addExpansionRowToTable(t, cc, i + 1, doSystem, mymaps);
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionContainsComponent) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) TargetElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent) ConceptMap(org.hl7.fhir.dstu2.model.ConceptMap) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 14 with ValueSetExpansionContainsComponent

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

the class QuestionnaireBuilder method makeTypeList.

private ValueSet makeTypeList(StructureDefinition profile, List<TypeRefComponent> types, String path) {
    ValueSet vs = new ValueSet();
    vs.setName("Type options for " + path);
    vs.setDescription(vs.getName());
    vs.setStatus(ConformanceResourceStatus.ACTIVE);
    vs.setExpansion(new ValueSetExpansionComponent());
    vs.getExpansion().setIdentifier(Factory.createUUID());
    vs.getExpansion().setTimestampElement(DateTimeType.now());
    for (TypeRefComponent t : types) {
        ValueSetExpansionContainsComponent cc = vs.getExpansion().addContains();
        if (t.getCode().equals("Reference") && (t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/"))) {
            cc.setCode(t.getProfile().get(0).getValue().substring(40));
            cc.setSystem("http://hl7.org/fhir/resource-types");
            cc.setDisplay(cc.getCode());
        } else {
            ProfileUtilities pu = new ProfileUtilities(context, null, null);
            StructureDefinition ps = null;
            if (t.hasProfile())
                ps = pu.getProfile(profile, t.getProfile().get(0).getValue());
            if (ps != null) {
                cc.setCode(t.getProfile().get(0).getValue());
                cc.setDisplay(ps.getSnapshot().getElement().get(0).getType().get(0).getCode());
                cc.setSystem("http://hl7.org/fhir/resource-types");
            } else {
                cc.setCode(t.getCode());
                cc.setDisplay(t.getCode());
                cc.setSystem("http://hl7.org/fhir/data-types");
            }
        }
        t.setUserData("text", cc.getCode());
    }
    return vs;
}
Also used : ValueSetExpansionComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.dstu2016may.model.ElementDefinition.TypeRefComponent) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet)

Example 15 with ValueSetExpansionContainsComponent

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

the class ProfileComparer method intersectByExpansion.

private ValueSet intersectByExpansion(ValueSet lvs, ValueSet rvs) {
    // this is pretty straight forward - we intersect the lists, and build a compose out of the intersection
    ValueSet vs = new ValueSet();
    vs.setStatus(ConformanceResourceStatus.DRAFT);
    Map<String, ValueSetExpansionContainsComponent> left = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(lvs.getExpansion().getContains(), left);
    Map<String, ValueSetExpansionContainsComponent> right = new HashMap<String, ValueSetExpansionContainsComponent>();
    scan(rvs.getExpansion().getContains(), right);
    Map<String, ConceptSetComponent> inc = new HashMap<String, ConceptSetComponent>();
    for (String s : left.keySet()) {
        if (right.containsKey(s)) {
            ValueSetExpansionContainsComponent cc = left.get(s);
            ConceptSetComponent c = inc.get(cc.getSystem());
            if (c == null) {
                c = vs.getCompose().addInclude().setSystem(cc.getSystem());
                inc.put(cc.getSystem(), c);
            }
            c.addConcept().setCode(cc.getCode()).setDisplay(cc.getDisplay());
        }
    }
    return vs;
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet)

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