Search in sources :

Example 71 with ConceptDefinitionComponent

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

the class ValueSetRenderer method renderExpandGroup.

private void renderExpandGroup(HierarchicalTableGenerator gen, TableModel model, Extension ext, ConceptSetComponent inc, Map<String, ConceptDefinitionComponent> definitions) {
    Row row = gen.new Row();
    model.getRows().add(row);
    row.setIcon("icon_entry_blue.png", "entry");
    String code = ext.getExtensionString("code");
    if (code != null) {
        row.getCells().add(gen.new Cell(null, null, code, null, null));
        row.getCells().add(gen.new Cell(null, null, getDisplayForCode(inc, code, definitions), null, null));
    } else if (ext.hasId()) {
        row.getCells().add(gen.new Cell(null, null, "(#" + ext.getId() + ")", null, null));
        row.getCells().add(gen.new Cell(null, null, ext.getExtensionString("display"), null, null));
    } else {
        row.getCells().add(gen.new Cell(null, null, null, null, null));
        row.getCells().add(gen.new Cell(null, null, ext.getExtensionString("display"), null, null));
    }
    for (Extension member : ext.getExtensionsByUrl("member")) {
        Row subRow = gen.new Row();
        row.getSubRows().add(subRow);
        subRow.setIcon("icon_entry_blue.png", "entry");
        String mc = member.getValue().primitiveValue();
        // mc might be a reference to another expansion group - we check that first, or to a code in the compose
        if (mc.startsWith("#")) {
            // it's a reference by id
            subRow.getCells().add(gen.new Cell(null, null, "(" + mc + ")", null, null));
            subRow.getCells().add(gen.new Cell(null, null, "group reference by id", null, null));
        } else {
            Extension tgt = findTargetByCode(inc, mc);
            if (tgt != null) {
                subRow.getCells().add(gen.new Cell(null, null, mc, null, null));
                subRow.getCells().add(gen.new Cell(null, null, "group reference by code", null, null));
            } else {
                subRow.getCells().add(gen.new Cell(null, null, mc, null, null));
                subRow.getCells().add(gen.new Cell(null, null, getDisplayForCode(inc, mc, definitions), null, null));
            }
        }
    }
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row)

Example 72 with ConceptDefinitionComponent

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

the class ValueSetRenderer method genInclude.

private boolean genInclude(XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs, boolean doDesignations, List<UsedConceptMap> maps, Map<String, String> designations, int index) throws FHIRException, IOException {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.li();
    CodeSystem e = getContext().getWorker().fetchCodeSystem(inc.getSystem());
    Map<String, ConceptDefinitionComponent> definitions = new HashMap<>();
    if (inc.hasSystem()) {
        if (inc.getConcept().size() == 0 && inc.getFilter().size() == 0) {
            li.addText(type + " all codes defined in ");
            addCsRef(inc, li, e);
        } else {
            if (inc.getConcept().size() > 0) {
                li.addText(type + " these codes as defined in ");
                addCsRef(inc, li, e);
                if (inc.hasVersion()) {
                    li.addText(" version ");
                    li.code(inc.getVersion());
                }
                // for performance reasons, we do all the fetching in one batch
                definitions = getConceptsForCodes(e, inc);
                XhtmlNode t = li.table("none");
                boolean hasComments = false;
                boolean hasDefinition = false;
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    hasComments = hasComments || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT);
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    hasDefinition = hasDefinition || ((cc != null && cc.hasDefinition()) || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION));
                }
                if (hasComments || hasDefinition)
                    hasExtensions = true;
                addMapHeaders(addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false, false, null, langs, designations, doDesignations), maps);
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    XhtmlNode tr = t.tr();
                    XhtmlNode td = tr.td();
                    ConceptDefinitionComponent cc = definitions.get(c.getCode());
                    addCodeToTable(false, inc.getSystem(), c.getCode(), c.hasDisplay() ? c.getDisplay() : cc != null ? cc.getDisplay() : "", td);
                    td = tr.td();
                    if (!Utilities.noString(c.getDisplay()))
                        td.addText(c.getDisplay());
                    else if (cc != null && !Utilities.noString(cc.getDisplay()))
                        td.addText(cc.getDisplay());
                    if (hasDefinition) {
                        td = tr.td();
                        if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION)) {
                            smartAddText(td, ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_DEFINITION));
                        } else if (cc != null && !Utilities.noString(cc.getDefinition())) {
                            smartAddText(td, cc.getDefinition());
                        }
                    }
                    if (hasComments) {
                        td = tr.td();
                        if (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
                            smartAddText(td, "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
                        }
                    }
                    if (doDesignations) {
                        addDesignationsToRow(c, designations, tr);
                        addLangaugesToRow(c, langs, tr);
                    }
                }
            }
            if (inc.getFilter().size() > 0) {
                li.addText(type + " codes from ");
                addCsRef(inc, li, e);
                li.tx(" where ");
                for (int i = 0; i < inc.getFilter().size(); i++) {
                    ConceptSetFilterComponent f = inc.getFilter().get(i);
                    if (i > 0) {
                        if (i == inc.getFilter().size() - 1) {
                            li.tx(" and ");
                        } else {
                            li.tx(", ");
                        }
                    }
                    if (f.getOp() == FilterOperator.EXISTS) {
                        if (f.getValue().equals("true")) {
                            li.tx(f.getProperty() + " exists");
                        } else {
                            li.tx(f.getProperty() + " doesn't exist");
                        }
                    } else {
                        li.tx(f.getProperty() + " " + describe(f.getOp()) + " ");
                        if (e != null && codeExistsInValueSet(e, f.getValue())) {
                            String href = getContext().fixReference(getCsRef(e));
                            if (href.contains("#"))
                                href = href + "-" + Utilities.nmtokenize(f.getValue());
                            else
                                href = href + "#" + e.getId() + "-" + Utilities.nmtokenize(f.getValue());
                            li.ah(href).addText(f.getValue());
                        } else if ("concept".equals(f.getProperty()) && inc.hasSystem()) {
                            li.addText(f.getValue());
                            ValidationResult vr = getContext().getWorker().validateCode(getContext().getTerminologyServiceOptions(), inc.getSystem(), inc.getVersion(), f.getValue(), null);
                            if (vr.isOk()) {
                                li.tx(" (" + vr.getDisplay() + ")");
                            }
                        } else
                            li.addText(f.getValue());
                        String disp = ToolingExtensions.getDisplayHint(f);
                        if (disp != null)
                            li.tx(" (" + disp + ")");
                    }
                }
            }
        }
        if (inc.hasValueSet()) {
            li.tx(", where the codes are contained in ");
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        }
        if (inc.hasExtension(ToolingExtensions.EXT_EXPAND_RULES) || inc.hasExtension(ToolingExtensions.EXT_EXPAND_GROUP)) {
            hasExtensions = true;
            renderExpansionRules(li, inc, index, definitions);
        }
    } else {
        li.tx("Import all the codes that are contained in ");
        if (inc.getValueSet().size() < 4) {
            boolean first = true;
            for (UriType vs : inc.getValueSet()) {
                if (first)
                    first = false;
                else
                    li.tx(", ");
                AddVsRef(vs.asStringValue(), li);
            }
        } else {
            XhtmlNode xul = li.ul();
            for (UriType vs : inc.getValueSet()) {
                AddVsRef(vs.asStringValue(), xul.li());
            }
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) HashMap(java.util.HashMap) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.r5.model.UriType)

Example 73 with ConceptDefinitionComponent

use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent in project redmatch by aehrc.

the class RedmatchGrammarCodeSystemGenerator method createBaseCodeSystem.

private CodeSystem createBaseCodeSystem(VersionedFhirPackage fhirPackage) {
    CodeSystem cs = new CodeSystem();
    cs.setId("redmatch-" + fhirPackage.getName());
    cs.setUrl("http://redmatch." + fhirPackage.getName());
    cs.setVersion(fhirPackage.getVersion());
    cs.setName("Redmatch Validation Code System for " + fhirPackage.getName());
    cs.setStatus(PublicationStatus.ACTIVE);
    cs.setDescription("A code system with all the valid paths used to refer to attributes of resources in " + fhirPackage.getName());
    cs.setValueSet("http://redmatch." + fhirPackage.getName() + "?vs");
    cs.setHierarchyMeaning(CodeSystemHierarchyMeaning.ISA);
    cs.setContent(CodeSystemContentMode.COMPLETE);
    cs.setExperimental(false);
    cs.setCompositional(false);
    cs.setVersionNeeded(false);
    cs.addProperty().setCode("parent").setDescription("Parent codes.").setType(PropertyType.CODE);
    cs.addProperty().setCode("root").setDescription("Indicates if this concept is a root concept.").setType(PropertyType.BOOLEAN);
    cs.addProperty().setCode("deprecated").setDescription("Indicates if this concept is deprecated.").setType(PropertyType.BOOLEAN);
    cs.addProperty().setCode("parentResourceOrProfile").setDescription("If this concept represents an attribute then this property represents the resource or profile" + "that contains the attribute. If this concepts is a profile or resource then the parent resource is Object.").setType(PropertyType.CODE);
    cs.addProperty().setCode("min").setDescription("Minimum cardinality").setType(PropertyType.INTEGER);
    cs.addProperty().setCode("max").setDescription("Maximum cardinality").setType(PropertyType.STRING);
    cs.addProperty().setCode("type").setDescription("Data type for this element.").setType(PropertyType.STRING);
    cs.addProperty().setCode("targetProfile").setDescription("If this code represents a Reference attribute, contains an allowed target profile.").setType(PropertyType.STRING);
    cs.addProperty().setCode("profile").setDescription("Indicates if this code represents a profile.").setType(PropertyType.BOOLEAN);
    cs.addProperty().setCode("baseResource").setDescription("For profiles, indicates the resource the profile constrains.").setType(PropertyType.CODE);
    cs.addProperty().setCode("extensionUrl").setDescription("If this code represents an extension, then this is its url.").setType(PropertyType.STRING);
    cs.addProperty().setCode("profileUrl").setDescription("If this code represents a profile, then this is its url.").setType(PropertyType.STRING);
    cs.addFilter().setCode("root").setValue("True or false.").addOperator(FilterOperator.EQUAL);
    cs.addFilter().setCode("deprecated").setValue("True or false.").addOperator(FilterOperator.EQUAL);
    cs.addFilter().setCode("parentResourceOrProfile").setValue("The parent resource or profile code.").addOperator(FilterOperator.EQUAL);
    cs.addFilter().setCode("profile").setValue("True or false.").addOperator(FilterOperator.EQUAL);
    // Create root concept
    ConceptDefinitionComponent objectRoot = cs.addConcept().setCode("Object").setDisplay("Object");
    objectRoot.addProperty().setCode("root").setValue(new BooleanType(true));
    objectRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
    ConceptDefinitionComponent complexTypeRoot = cs.addConcept().setCode("ComplexType").setDisplay("ComplexType");
    complexTypeRoot.addProperty().setCode("root").setValue(new BooleanType(false));
    complexTypeRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
    complexTypeRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
    ConceptDefinitionComponent resourceRoot = cs.addConcept().setCode("Resource").setDisplay("Resource");
    resourceRoot.addProperty().setCode("root").setValue(new BooleanType(false));
    resourceRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
    resourceRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
    ConceptDefinitionComponent profileRoot = cs.addConcept().setCode("Profile").setDisplay("Profile");
    profileRoot.addProperty().setCode("root").setValue(new BooleanType(false));
    profileRoot.addProperty().setCode("deprecated").setValue(new BooleanType(false));
    profileRoot.addProperty().setCode("parent").setValue(new CodeType("Object"));
    return cs;
}
Also used : CodeSystem(org.hl7.fhir.r4.model.CodeSystem)

Example 74 with ConceptDefinitionComponent

use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent in project synthea by synthetichealth.

the class ValidationSupportR4 method lookupCode.

@Override
public LookupCodeResult lookupCode(ValidationSupportContext theValidationSupportContext, String theSystem, String theCode, String theDisplayLanguage) {
    LookupCodeResult result = new LookupCodeResult();
    result.setSearchedForCode(theCode);
    result.setSearchedForSystem(theSystem);
    result.setFound(false);
    CodeSystem cs = (CodeSystem) this.fetchCodeSystem(theSystem);
    if (cs != null) {
        for (ConceptDefinitionComponent cdc : cs.getConcept()) {
            if (conceptContainsCode(cdc, theCode)) {
                result.setFound(true);
            }
        }
    }
    return result;
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) CodeSystem(org.hl7.fhir.r4.model.CodeSystem)

Example 75 with ConceptDefinitionComponent

use of org.hl7.fhir.r4b.model.CodeSystem.ConceptDefinitionComponent in project elexis-server by elexis.

the class CodeSystemTest method getCodeSystemProperties.

@Test
public void getCodeSystemProperties() {
    // tessinercode
    CodeSystem readCodeSystem = client.read().resource(CodeSystem.class).withId("tessinercode").execute();
    assertNotNull(readCodeSystem);
    assertEquals(CodingSystem.ELEXIS_DIAGNOSE_TESSINERCODE.getSystem(), readCodeSystem.getUrl());
    Optional<ConceptDefinitionComponent> concept = getConceptFromSytem("A1", readCodeSystem);
    assertTrue(concept.isPresent());
    // coveragetype
    readCodeSystem = client.read().resource(CodeSystem.class).withId("coveragetype").execute();
    assertNotNull(readCodeSystem);
    assertEquals(CodingSystem.ELEXIS_COVERAGE_TYPE.getSystem(), readCodeSystem.getUrl());
    concept = getConceptFromSytem("KVG", readCodeSystem);
    assertTrue(concept.isPresent());
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) Test(org.junit.Test)

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