Search in sources :

Example 86 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class CodeListToValueSetParser method generateConceptMapV3.

private void generateConceptMapV3(String v3map, ValueSet vs, CodeSystem cs) throws Exception {
    if (!v3map.startsWith("http://terminology.hl7.org/ValueSet/v3-"))
        v3map = "http://terminology.hl7.org/ValueSet/v3-" + v3map;
    ConceptMap cm = new ConceptMap();
    cm.setVersion(version);
    cm.setId("cm-" + vs.getId() + "-v3");
    cm.setUserData("path", cm.getId() + ".html");
    cm.setUserData("generate", true);
    cm.setUrl("http://hl7.org/fhir/ConceptMap/" + cm.getId());
    cm.setName("v3." + vs.getName());
    cm.setTitle("v3 map for " + vs.present());
    cm.setPublisher("HL7 (FHIR Project)");
    for (ContactDetail cc : vs.getContact()) {
        ContactDetail cd = cm.addContact();
        cd.setName(cc.getName());
        for (ContactPoint ccs : cc.getTelecom()) cd.addTelecom(ccs.copy());
    }
    cm.setCopyright(vs.getCopyright());
    // until we publish DSTU, then .review
    cm.setStatus(vs.getStatus());
    cm.setDate(vs.getDate());
    cm.setSource(Factory.newCanonical(vs.getUrl()));
    cm.setTarget(Factory.newCanonical(v3map));
    if (cs != null)
        processV3ConceptDefs(cm, cs.getUrl(), cs.getConcept());
    for (ConceptSetComponent cc : vs.getCompose().getInclude()) for (ConceptReferenceComponent c : cc.getConcept()) {
        processV3Map(cm, cc.getSystem(), c.getCode(), c.getUserString("v2"));
    }
    maps.see(cm, packageInfo);
}
Also used : ContactDetail(org.hl7.fhir.r5.model.ContactDetail) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptMap(org.hl7.fhir.r5.model.ConceptMap) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)

Example 87 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project kindling by HL7.

the class CodeListToValueSetParser method execute.

public void execute(String v2map, String v3map, boolean utg) throws Exception {
    boolean hasDefine = false;
    for (int row = 0; row < sheet.rows.size(); row++) {
        hasDefine = hasDefine || Utilities.noString(sheet.getColumn(row, "System"));
    }
    Map<String, ConceptDefinitionComponent> codes = new HashMap<String, ConceptDefinitionComponent>();
    Map<String, ConceptDefinitionComponent> codesById = new HashMap<String, ConceptDefinitionComponent>();
    Map<String, ConceptSetComponent> includes = new HashMap<String, ConceptSetComponent>();
    CodeSystem cs = null;
    if (hasDefine) {
        cs = new CodeSystem();
        if (utg)
            cs.setUrl("http://terminology.hl7.org/CodeSystem/" + sheetName);
        else
            cs.setUrl("http://hl7.org/fhir/" + sheetName);
        if (!valueSet.hasCompose())
            valueSet.setCompose(new ValueSetComposeComponent());
        valueSet.getCompose().addInclude().setSystem(cs.getUrl());
        cs.setVersion(version);
        cs.setCaseSensitive(true);
        cs.setContent(CodeSystemContentMode.COMPLETE);
        codeSystems.see(cs, packageInfo);
        for (int row = 0; row < sheet.rows.size(); row++) {
            if (Utilities.noString(sheet.getColumn(row, "System"))) {
                ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
                cc.setUserData("id", sheet.getColumn(row, "Id"));
                cc.setCode(sheet.getColumn(row, "Code"));
                if (codes.containsKey(cc.getCode()))
                    throw new Exception("Duplicate Code " + cc.getCode());
                codes.put(cc.getCode(), cc);
                codesById.put(cc.getUserString("id"), cc);
                cc.setDisplay(sheet.getColumn(row, "Display"));
                if (sheet.getColumn(row, "Abstract").toUpperCase().equals("Y"))
                    CodeSystemUtilities.setNotSelectable(cs, cc);
                if (cc.hasCode() && !cc.hasDisplay())
                    cc.setDisplay(Utilities.humanize(cc.getCode()));
                cc.setDefinition(Utilities.appendPeriod(sheet.getColumn(row, "Definition")));
                if (!Utilities.noString(sheet.getColumn(row, "Comment")))
                    ToolingExtensions.addCSComment(cc, sheet.getColumn(row, "Comment"));
                cc.setUserData("v2", sheet.getColumn(row, "v2"));
                cc.setUserData("v3", sheet.getColumn(row, "v3"));
                for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
                    cc.addDesignation().setLanguage(ct.substring(8)).setValue(sheet.getColumn(row, ct));
                String parent = sheet.getColumn(row, "Parent");
                if (Utilities.noString(parent))
                    cs.addConcept(cc);
                else if (parent.startsWith("#") && codesById.containsKey(parent.substring(1)))
                    codesById.get(parent.substring(1)).addConcept(cc);
                else if (codes.containsKey(parent))
                    codes.get(parent).addConcept(cc);
                else
                    throw new Exception("Parent " + parent + " not resolved in " + sheetName);
            }
        }
    }
    for (int row = 0; row < sheet.rows.size(); row++) {
        if (!Utilities.noString(sheet.getColumn(row, "System"))) {
            String system = sheet.getColumn(row, "System");
            ConceptSetComponent t = includes.get(system);
            if (t == null) {
                if (!valueSet.hasCompose())
                    valueSet.setCompose(new ValueSetComposeComponent());
                t = valueSet.getCompose().addInclude();
                t.setSystem(system);
                includes.put(system, t);
            }
            ConceptReferenceComponent cc = t.addConcept();
            cc.setCode(sheet.getColumn(row, "Code"));
            if (codes.containsKey(cc.getCode()))
                throw new Exception("Duplicate Code " + cc.getCode());
            codes.put(cc.getCode(), null);
            cc.setDisplay(sheet.getColumn(row, "Display"));
            if (!Utilities.noString(sheet.getColumn(row, "Definition")))
                ToolingExtensions.addDefinition(cc, sheet.getColumn(row, "Definition"));
            if (!Utilities.noString(sheet.getColumn(row, "Comment")))
                ToolingExtensions.addVSComment(cc, sheet.getColumn(row, "Comment"));
            cc.setUserDataINN("v2", sheet.getColumn(row, "v2"));
            cc.setUserDataINN("v3", sheet.getColumn(row, "v3"));
            for (String ct : sheet.columns) if (ct.startsWith("Display:") && !Utilities.noString(sheet.getColumn(row, ct)))
                cc.addDesignation().setLanguage(ct.substring(8)).setValue(sheet.getColumn(row, ct));
        }
    }
    if (!Utilities.noString(v2map)) {
        generateConceptMapV2(v2map, valueSet, cs);
    }
    if (!Utilities.noString(v3map)) {
        generateConceptMapV3(v3map, valueSet, cs);
    }
    if (cs != null)
        CodeSystemConvertor.populate(cs, valueSet);
}
Also used : ConceptSetComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HashMap(java.util.HashMap) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ValueSetComposeComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 88 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class ICD11Generator method makeFullVs.

private void makeFullVs(String dest, CodeSystem cs) throws IOException {
    String url = "http://id.who.int/icd11/ValueSet/all-MMS";
    ValueSet vs = new ValueSet();
    vs.setId("all-MMS");
    vs.setUrl(url);
    vs.setName("ICDMMSAll");
    vs.setTitle("Value Set for all ICD MMS Codes");
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExperimental(false);
    vs.setDate(cs.getDate());
    vs.setPublisher("WHO");
    vs.setCopyright("Consult WHO For terms of use");
    vs.setVersion(cs.getVersion());
    vs.setStatus(cs.getStatus());
    ConceptSetComponent inc = vs.getCompose().addInclude();
    inc.setSystem(cs.getUrl());
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "vs-all-MMS.xml")), vs);
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) XmlParser(org.hl7.fhir.r4.formats.XmlParser) FileOutputStream(java.io.FileOutputStream)

Example 89 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent in project org.hl7.fhir.core by hapifhir.

the class ICD11Generator method makeFullVs2.

private void makeFullVs2(String dest, CodeSystem cs) throws IOException {
    String url = "http://id.who.int/icd11/ValueSet/all-foundation";
    ValueSet vs = new ValueSet();
    vs.setId("all-foundation");
    vs.setUrl(url);
    vs.setName("ICDFoundationAll");
    vs.setTitle("Value Set for all ICD Foundation Concepts");
    vs.setStatus(PublicationStatus.ACTIVE);
    vs.setExperimental(false);
    vs.setDate(cs.getDate());
    vs.setPublisher("WHO");
    vs.setCopyright("Consult WHO For terms of use");
    vs.setVersion(cs.getVersion());
    vs.setStatus(cs.getStatus());
    ConceptSetComponent inc = vs.getCompose().addInclude();
    inc.setSystem(cs.getUrl());
    new XmlParser(XmlVersion.V1_1).setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "vs-all-foundation.xml")), vs);
}
Also used : ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) XmlParser(org.hl7.fhir.r4.formats.XmlParser) FileOutputStream(java.io.FileOutputStream)

Example 90 with ConceptSetComponent

use of org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent 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(PublicationStatus.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.r4.model.ValueSet.ConceptSetComponent) ValueSetExpansionContainsComponent(org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Aggregations

ConceptSetComponent (org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent)25 ArrayList (java.util.ArrayList)22 ConceptSetComponent (org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent)21 IOException (java.io.IOException)20 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)20 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)17 HashMap (java.util.HashMap)15 ConceptSetComponent (org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent)14 ConceptReferenceComponent (org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent)14 ValueSet (org.hl7.fhir.r4.model.ValueSet)13 ValueSet (org.hl7.fhir.r5.model.ValueSet)13 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)12 ConceptSetComponent (org.hl7.fhir.r4b.model.ValueSet.ConceptSetComponent)12 FileNotFoundException (java.io.FileNotFoundException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)10 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)9