Search in sources :

Example 11 with ConceptDefinitionComponent

use of org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.

the class NUCCConvertor method processLine.

private void processLine(CodeSystem cs, String[] values) throws FHIRFormatError {
    ConceptDefinitionComponent cc = new ConceptDefinitionComponent();
    cs.getConcept().add(cc);
    cc.setCode(values[0]);
    cc.setDisplay(values[4]);
    if (!Utilities.noString(values[1])) {
        cc.addProperty().setCode("grouping").setValue(new StringType(values[1]));
    }
    if (!Utilities.noString(values[2])) {
        cc.addProperty().setCode("classification").setValue(new StringType(values[2]));
    }
    if (!Utilities.noString(values[3])) {
        cc.addProperty().setCode("specialization").setValue(new StringType(values[3]));
    }
    if (values.length > 5 && !Utilities.noString(values[5]))
        cc.setDefinition(values[5]);
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) StringType(org.hl7.fhir.r4.model.StringType)

Example 12 with ConceptDefinitionComponent

use of org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.

the class CountryCodesConverter method execute.

private void execute() throws ParserConfigurationException, SAXException, IOException {
    Document src = load();
    CodeSystem cs1 = new CodeSystem();
    CodeSystem cs2 = new CodeSystem();
    CodeSystem cs3 = new CodeSystem();
    setMetadata(src, cs1, "iso3166", "urn:iso:std:iso:3166", "", "");
    setMetadata(src, cs2, "iso3166-2", "urn:iso:std:iso:3166:-2", "Part2", " Part 2");
    cs1.addProperty().setCode("canonical").setDescription("The 2 letter code that identifies the same country (so 2/3/numeric codes can be aligned)").setType(PropertyType.CODE);
    cs2.addProperty().setCode("country").setDescription("The 2 letter code that identifies the country for the subdivision").setType(PropertyType.CODE);
    for (Element e : XMLUtil.getNamedChildren(src.getDocumentElement(), "country")) {
        System.out.println(e.getAttribute("id"));
        String c2 = XMLUtil.getNamedChildText(e, "alpha-2-code");
        String c3 = XMLUtil.getNamedChildText(e, "alpha-3-code");
        String cN = XMLUtil.getNamedChildText(e, "numeric-code");
        Element n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
        if (n == null)
            continue;
        String name = n.getTextContent();
        n = XMLUtil.getNamedChildByAttribute(e, "full-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "full-name-upper-case", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
        String desc = n.getTextContent();
        ConceptDefinitionComponent cc = cs1.addConcept();
        cc.setCode(c2);
        cc.setDisplay(name);
        cc.setDefinition(desc);
        poplang(e, cc);
        if (c3 != null) {
            cc = cs1.addConcept();
            cc.setCode(c3);
            cc.setDisplay(name);
            cc.setDefinition(desc);
            cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
            poplang(e, cc);
        }
        if (cN != null) {
            cc = cs1.addConcept();
            cc.setCode(cN);
            cc.setDisplay(name);
            cc.setDefinition(desc);
            cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
            poplang(e, cc);
        }
        for (Element sd : XMLUtil.getNamedChildren(e, "subdivision")) {
            cc = cs2.addConcept();
            cc.setCode(XMLUtil.getNamedChildText(sd, "subdivision-code"));
            Element l = XMLUtil.getNamedChild(sd, "subdivision-locale");
            cc.setDisplay(XMLUtil.getNamedChildText(l, "subdivision-locale-name"));
            cc.addProperty().setCode("country").setValue(new CodeType(c2));
        }
    }
    cs1.setCount(cs1.getConcept().size());
    cs2.setCount(cs2.getConcept().size());
    throw new Error("Needs revisiting");
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166.json")), cs1);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166.json")), cs1); // format hasn't changed
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166-2.json")), cs2);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166-2.json")), cs2); // format hasn't changed
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) Element(org.w3c.dom.Element) CodeType(org.hl7.fhir.r4.model.CodeType) Document(org.w3c.dom.Document) CodeSystem(org.hl7.fhir.r4.model.CodeSystem)

Example 13 with ConceptDefinitionComponent

use of org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method addDefineRowToTable.

private boolean addDefineRowToTable(XhtmlNode t, ConceptDefinitionComponent c, int i, boolean hasHierarchy, boolean hasDisplay, boolean comment, boolean deprecated, Map<ConceptMap, String> maps, String system) {
    boolean hasExtensions = false;
    XhtmlNode tr = t.addTag("tr");
    XhtmlNode td = tr.addTag("td");
    if (hasHierarchy) {
        td.addText(Integer.toString(i + 1));
        td = tr.addTag("td");
        String s = Utilities.padLeft("", '\u00A0', i * 2);
        td.addText(s);
    }
    td.addText(c.getCode());
    XhtmlNode a;
    if (c.hasCodeElement()) {
        a = td.addTag("a");
        a.setAttribute("name", Utilities.nmtokenize(c.getCode()));
        a.addText(" ");
    }
    if (hasDisplay) {
        td = tr.addTag("td");
        if (c.hasDisplayElement())
            td.addText(c.getDisplay());
    }
    td = tr.addTag("td");
    if (c != null)
        smartAddText(td, c.getDefinition());
    if (deprecated) {
        td = tr.addTag("td");
        Boolean b = ToolingExtensions.getDeprecated(c);
        if (b != null && b) {
            smartAddText(td, "Deprecated");
            hasExtensions = true;
            if (ToolingExtensions.hasExtension(c, ToolingExtensions.EXT_REPLACED_BY)) {
                Coding cc = (Coding) ToolingExtensions.getExtension(c, ToolingExtensions.EXT_REPLACED_BY).getValue();
                td.addText(" (replaced by ");
                String url = getCodingReference(cc, system);
                if (url != null) {
                    td.addTag("a").setAttribute("href", url).addText(cc.getCode());
                    td.addText(": " + cc.getDisplay() + ")");
                } else
                    td.addText(cc.getCode() + " '" + cc.getDisplay() + "' in " + cc.getSystem() + ")");
            }
        }
    }
    if (comment) {
        td = tr.addTag("td");
        String s = ToolingExtensions.getComment(c);
        if (s != null) {
            smartAddText(td, s);
            hasExtensions = true;
        }
    }
    for (ConceptMap m : maps.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.hasEquivalence() ? mapping.getEquivalence().toCode() : "");
            span.addText(getCharForEquivalence(mapping));
            a = td.addTag("a");
            a.setAttribute("href", prefix + maps.get(m) + "#" + makeAnchor(mapping.getCodeSystem(), mapping.getCode()));
            a.addText(mapping.getCode());
            if (!Utilities.noString(mapping.getComments()))
                td.addTag("i").addText("(" + mapping.getComments() + ")");
        }
    }
    for (CodeType e : ToolingExtensions.getSubsumes(c)) {
        hasExtensions = true;
        tr = t.addTag("tr");
        td = tr.addTag("td");
        String s = Utilities.padLeft("", '.', i * 2);
        td.addText(s);
        a = td.addTag("a");
        a.setAttribute("href", "#" + Utilities.nmtokenize(e.getValue()));
        a.addText(c.getCode());
    }
    for (ConceptDefinitionComponent cc : c.getConcept()) {
        hasExtensions = addDefineRowToTable(t, cc, i + 1, hasHierarchy, hasDisplay, comment, deprecated, maps, system) || hasExtensions;
    }
    return hasExtensions;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent) Coding(org.hl7.fhir.dstu2.model.Coding) TargetElementComponent(org.hl7.fhir.dstu2.model.ConceptMap.TargetElementComponent) CodeType(org.hl7.fhir.dstu2.model.CodeType) ConceptMap(org.hl7.fhir.dstu2.model.ConceptMap) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 14 with ConceptDefinitionComponent

use of org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
    if (context.supportsSystem(inc.getSystem())) {
        addCodes(context.expandVS(inc), params);
        return;
    }
    ValueSet cs = context.fetchCodeSystem(inc.getSystem());
    if (cs == null)
        throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
    if (cs.hasVersion())
        if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
    if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
        // special case - add all the code system
        for (ConceptDefinitionComponent def : cs.getCodeSystem().getConcept()) {
            addCodeAndDescendents(inc.getSystem(), def);
        }
    }
    for (ConceptReferenceComponent c : inc.getConcept()) {
        addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
    }
    if (inc.getFilter().size() > 1)
        // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
        throw new TerminologyServiceException("Multiple filters not handled yet");
    if (inc.getFilter().size() == 1) {
        ConceptSetFilterComponent fc = inc.getFilter().get(0);
        if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
            // special: all non-abstract codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getCodeSystem().getConcept(), fc.getValue());
            if (def == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            addCodeAndDescendents(inc.getSystem(), def);
        } else
            throw new NotImplementedException("not done yet");
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2.model.ValueSet.ValueSetExpansionParameterComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu2.model.ValueSet) ConceptReferenceComponent(org.hl7.fhir.dstu2.model.ValueSet.ConceptReferenceComponent) UriType(org.hl7.fhir.dstu2.model.UriType)

Example 15 with ConceptDefinitionComponent

use of org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent in project org.hl7.fhir.core by hapifhir.

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params) throws TerminologyServiceException, ETooCostly {
    if (context.supportsSystem(inc.getSystem())) {
        try {
            int i = codes.size();
            addCodes(context.expandVS(inc), params);
            if (codes.size() > i)
                return;
        } catch (Exception e) {
        // ok, we'll try locally
        }
    }
    CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
    if (cs == null)
        throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
    if (cs.hasVersion())
        if (!existsInParams(params, "version", new UriType(cs.getUrl() + "?version=" + cs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "?version=" + cs.getVersion())));
    if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
        // special case - add all the code system
        for (ConceptDefinitionComponent def : cs.getConcept()) {
            addCodeAndDescendents(cs, inc.getSystem(), def);
        }
    }
    for (ConceptReferenceComponent c : inc.getConcept()) {
        addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay());
    }
    if (inc.getFilter().size() > 1)
        // need to and them, and this isn't done yet. But this shouldn't arise in non loinc and snomed value sets
        throw new TerminologyServiceException("Multiple filters not handled yet");
    if (inc.getFilter().size() == 1) {
        ConceptSetFilterComponent fc = inc.getFilter().get(0);
        if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.ISA) {
            // special: all non-abstract codes in the target code system under the value
            ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
            if (def == null)
                throw new TerminologyServiceException("Code '" + fc.getValue() + "' not found in system '" + inc.getSystem() + "'");
            addCodeAndDescendents(cs, inc.getSystem(), def);
        } else
            throw new NotImplementedException("not done yet");
    }
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) CodeSystem(org.hl7.fhir.dstu2016may.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ConceptReferenceComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) UriType(org.hl7.fhir.dstu2016may.model.UriType)

Aggregations

ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)54 ArrayList (java.util.ArrayList)26 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)26 ConceptDefinitionComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent)22 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)21 ConceptDefinitionComponent (org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent)17 ConceptDefinitionComponent (org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent)16 ValueSet (org.hl7.fhir.dstu2.model.ValueSet)15 FHIRException (org.hl7.fhir.exceptions.FHIRException)14 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 ConceptPropertyComponent (org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent)10 ConceptPropertyComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptPropertyComponent)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 NotImplementedException (org.apache.commons.lang3.NotImplementedException)9 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)9 FileNotFoundException (java.io.FileNotFoundException)8 ConceptDefinitionComponent (org.hl7.fhir.dstu2016may.model.CodeSystem.ConceptDefinitionComponent)8 ValidationResult (org.hl7.fhir.r5.context.IWorkerContext.ValidationResult)8 ConceptDefinitionDesignationComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionDesignationComponent)8