Search in sources :

Example 21 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method genInclude.

private boolean genInclude(ResourceContext rcontext, XhtmlNode ul, ConceptSetComponent inc, String type, List<String> langs) throws FHIRException {
    boolean hasExtensions = false;
    XhtmlNode li;
    li = ul.li();
    CodeSystem e = context.fetchCodeSystem(inc.getSystem());
    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);
                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);
                    hasDefinition = hasDefinition || ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_DEFINITION);
                }
                if (hasComments || hasDefinition)
                    hasExtensions = true;
                addTableHeaderRowStandard(t, false, true, hasDefinition, hasComments, false);
                for (ConceptReferenceComponent c : inc.getConcept()) {
                    XhtmlNode tr = t.tr();
                    XhtmlNode td = tr.td();
                    ConceptDefinitionComponent cc = getConceptForCode(e, c.getCode(), inc);
                    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());
                    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 (ExtensionHelper.hasExtension(c, ToolingExtensions.EXT_VS_COMMENT)) {
                        smartAddText(tr.td(), "Note: " + ToolingExtensions.readStringExtension(c, ToolingExtensions.EXT_VS_COMMENT));
                    }
                    for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
                        if (cd.hasLanguage() && !langs.contains(cd.getLanguage()))
                            langs.add(cd.getLanguage());
                    }
                }
            }
            boolean first = true;
            for (ConceptSetFilterComponent f : inc.getFilter()) {
                if (first) {
                    li.addText(type + " codes from ");
                    first = false;
                } else
                    li.tx(" and ");
                addCsRef(inc, li, e);
                li.tx(" where " + f.getProperty() + " " + describe(f.getOp()) + " ");
                if (e != null && codeExistsInValueSet(e, f.getValue())) {
                    String href = prefix + 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 = context.validateCode(inc.getSystem(), 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(rcontext, vs.asStringValue(), li);
            }
        }
    } else {
        li = ul.li();
        li.tx("Import all the codes that are contained in ");
        boolean first = true;
        for (UriType vs : inc.getValueSet()) {
            if (first)
                first = false;
            else
                li.tx(", ");
            AddVsRef(rcontext, vs.asStringValue(), li);
        }
    }
    return hasExtensions;
}
Also used : ConceptSetFilterComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetFilterComponent) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) ConceptReferenceDesignationComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceDesignationComponent) ValidationResult(org.hl7.fhir.dstu3.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.dstu3.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) UriType(org.hl7.fhir.dstu3.model.UriType)

Example 22 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class ValueSetCheckerSimple method validateCode.

public ValidationResult validateCode(CodeableConcept code) throws FHIRException {
    // first, we validate the codings themselves
    List<String> errors = new ArrayList<String>();
    List<String> warnings = new ArrayList<String>();
    if (options.getValueSetMode() != ValueSetMode.CHECK_MEMERSHIP_ONLY) {
        for (Coding c : code.getCoding()) {
            if (!c.hasSystem()) {
                warnings.add(context.formatMessage(I18nConstants.CODING_HAS_NO_SYSTEM__CANNOT_VALIDATE));
            }
            CodeSystem cs = resolveCodeSystem(c.getSystem());
            ValidationResult res = null;
            if (cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) {
                res = context.validateCode(options.noClient(), c, null);
            } else {
                res = validateCode(c, cs);
            }
            if (!res.isOk()) {
                errors.add(res.getMessage());
            } else if (res.getMessage() != null) {
                warnings.add(res.getMessage());
            }
        }
    }
    Coding foundCoding = null;
    if (valueset != null && options.getValueSetMode() != ValueSetMode.NO_MEMBERSHIP_CHECK) {
        Boolean result = false;
        for (Coding c : code.getCoding()) {
            Boolean ok = codeInValueSet(c.getSystem(), c.getCode(), warnings);
            if (ok == null && result == false) {
                result = null;
            } else if (ok) {
                result = true;
                foundCoding = c;
            }
        }
        if (result == null) {
            warnings.add(0, context.formatMessage(I18nConstants.UNABLE_TO_CHECK_IF_THE_PROVIDED_CODES_ARE_IN_THE_VALUE_SET_, valueset.getUrl()));
        } else if (!result) {
            errors.add(0, context.formatMessage(I18nConstants.NONE_OF_THE_PROVIDED_CODES_ARE_IN_THE_VALUE_SET_, valueset.getUrl()));
        }
    }
    if (errors.size() > 0) {
        return new ValidationResult(IssueSeverity.ERROR, errors.toString());
    } else if (warnings.size() > 0) {
        return new ValidationResult(IssueSeverity.WARNING, warnings.toString());
    } else {
        ConceptDefinitionComponent cd = new ConceptDefinitionComponent(foundCoding.getCode());
        cd.setDisplay(foundCoding.getDisplay());
        return new ValidationResult(foundCoding.getSystem(), cd);
    }
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) Coding(org.hl7.fhir.r5.model.Coding) ArrayList(java.util.ArrayList) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) CodeSystem(org.hl7.fhir.r5.model.CodeSystem)

Example 23 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method addLanguageRow.

private void addLanguageRow(ConceptReferenceComponent c, XhtmlNode t, List<String> langs) {
    XhtmlNode tr = t.tr();
    tr.td().addText(c.getCode());
    for (String lang : langs) {
        String d = null;
        for (ConceptReferenceDesignationComponent cd : c.getDesignation()) {
            String l = cd.getLanguage();
            if (lang.equals(l))
                d = cd.getValue();
        }
        tr.td().addText(d == null ? "" : d);
    }
}
Also used : ConceptReferenceDesignationComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceDesignationComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 24 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class CapabilityStatementComparer method intersectCodeableConcepts.

private void intersectCodeableConcepts(List<CodeableConcept> tgt, List<CodeableConcept> src) {
    List<CodeableConcept> toRemove = new ArrayList<CodeableConcept>();
    for (CodeableConcept cd : src) {
        boolean remove = false;
        for (CodeableConcept t : tgt) {
            if (t.matches(cd)) {
                remove = true;
            }
        }
        if (remove) {
            toRemove.add(cd);
        }
    }
    tgt.removeAll(toRemove);
}
Also used : ArrayList(java.util.ArrayList) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept)

Example 25 with CD

use of org.hl7.v3.CD in project org.hl7.fhir.core by hapifhir.

the class CodeSystemComparer method getProp.

public ConceptPropertyComponent getProp(ConceptDefinitionComponent cd, PropertyComponent p, boolean right, CodeSystemComparison comp) {
    String c = p.getCode();
    if (right) {
        c = comp.getPropMap().get(c);
    }
    ConceptPropertyComponent cp = null;
    if (cd != null) {
        for (ConceptPropertyComponent t : cd.getProperty()) {
            if (t.getCode().equals(c)) {
                cp = t;
            }
        }
    }
    return cp;
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r4b.model.CodeSystem.ConceptPropertyComponent)

Aggregations

ArrayList (java.util.ArrayList)24 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 Coding (org.hl7.fhir.r4.model.Coding)10 ValueSet (org.hl7.fhir.r5.model.ValueSet)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)9 BindingSpecification (org.hl7.fhir.definitions.model.BindingSpecification)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 CD (net.ihe.gazelle.hl7v3.datatypes.CD)7 CS (net.ihe.gazelle.hl7v3.datatypes.CS)7 II (net.ihe.gazelle.hl7v3.datatypes.II)7 TS (net.ihe.gazelle.hl7v3.datatypes.TS)7 MCCIMT000100UV01Device (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Device)7 MCCIMT000100UV01Receiver (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Receiver)7 MCCIMT000100UV01Sender (net.ihe.gazelle.hl7v3.mccimt000100UV01.MCCIMT000100UV01Sender)7 Identifier (org.hl7.fhir.r4.model.Identifier)7 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)7 IOException (java.io.IOException)6 ConceptDefinitionComponent (org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent)6 ContactDetail (org.hl7.fhir.r5.model.ContactDetail)5