Search in sources :

Example 61 with Property

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

the class FHIRPathEngine method funcResolve.

private List<Base> funcResolve(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    List<Base> result = new ArrayList<Base>();
    Base refContext = null;
    for (Base item : focus) {
        String s = convertToString(item);
        if (item.fhirType().equals("Reference")) {
            refContext = item;
            Property p = item.getChildByName("reference");
            if (p != null && p.hasValues()) {
                s = convertToString(p.getValues().get(0));
            } else {
                // a reference without any valid actual reference (just identifier or display, but we can't resolve it)
                s = null;
            }
        }
        if (item.fhirType().equals("canonical")) {
            s = item.primitiveValue();
            refContext = item;
        }
        if (s != null) {
            Base res = null;
            if (s.startsWith("#")) {
                Property p = context.rootResource.getChildByName("contained");
                if (p != null) {
                    for (Base c : p.getValues()) {
                        if (chompHash(s).equals(chompHash(c.getIdBase()))) {
                            res = c;
                            break;
                        }
                    }
                }
            } else if (hostServices != null) {
                res = hostServices.resolveReference(context.appInfo, s, refContext);
            }
            if (res != null) {
                result.add(res);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) Property(org.hl7.fhir.r5.model.Property) Base(org.hl7.fhir.r5.model.Base)

Example 62 with Property

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

the class ValueSetExpanderSimple method includeCodes.

private void includeCodes(ConceptSetComponent inc, List<ValueSetExpansionParameterComponent> params, ExpansionProfile profile) throws ETooCostly, FileNotFoundException, IOException, FHIRException {
    List<ValueSet> imports = new ArrayList<ValueSet>();
    for (UriType imp : inc.getValueSet()) imports.add(importValueSet(imp.getValue(), params, profile));
    if (!inc.hasSystem()) {
        if (// though this is not supposed to be the case
        imports.isEmpty())
            return;
        ValueSet base = imports.get(0);
        imports.remove(0);
        copyImportContains(base.getExpansion().getContains(), null, profile, imports);
    } else {
        CodeSystem cs = context.fetchCodeSystem(inc.getSystem());
        if ((cs == null || cs.getContent() != CodeSystemContentMode.COMPLETE) && context.supportsSystem(inc.getSystem())) {
            addCodes(context.expandVS(inc, canBeHeirarchy), params, profile, imports);
            return;
        }
        if (cs == null) {
            if (context.isNoTerminologyServer())
                throw new NoTerminologyServiceException("unable to find code system " + inc.getSystem().toString());
            else
                throw new TerminologyServiceException("unable to find code system " + inc.getSystem().toString());
        }
        if (cs.getContent() != CodeSystemContentMode.COMPLETE)
            throw new TerminologyServiceException("Code system " + inc.getSystem().toString() + " is incomplete");
        if (cs.hasVersion())
            if (!existsInParams(params, "version", new UriType(cs.getUrl() + "|" + cs.getVersion())))
                params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(cs.getUrl() + "|" + 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, null, profile, imports);
            }
        }
        if (!inc.getConcept().isEmpty()) {
            canBeHeirarchy = false;
            for (ConceptReferenceComponent c : inc.getConcept()) {
                addCode(inc.getSystem(), c.getCode(), Utilities.noString(c.getDisplay()) ? getCodeDisplay(cs, c.getCode()) : c.getDisplay(), null, convertDesignations(c.getDesignation()), profile, false, CodeSystemUtilities.isInactive(cs, c.getCode()), imports);
            }
        }
        if (inc.getFilter().size() > 1) {
            // which will bt the case if we get around to supporting this
            canBeHeirarchy = false;
            // 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 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, null, profile, imports);
            } else if ("concept".equals(fc.getProperty()) && fc.getOp() == FilterOperator.DESCENDENTOF) {
                // special: all 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() + "'");
                for (ConceptDefinitionComponent c : def.getConcept()) addCodeAndDescendents(cs, inc.getSystem(), c, null, profile, imports);
            } else if ("display".equals(fc.getProperty()) && fc.getOp() == FilterOperator.EQUAL) {
                // gg; note: wtf is this: if the filter is display=v, look up the code 'v', and see if it's diplsay is 'v'?
                canBeHeirarchy = false;
                ConceptDefinitionComponent def = getConceptForCode(cs.getConcept(), fc.getValue());
                if (def != null) {
                    if (isNotBlank(def.getDisplay()) && isNotBlank(fc.getValue())) {
                        if (def.getDisplay().contains(fc.getValue())) {
                            addCode(inc.getSystem(), def.getCode(), def.getDisplay(), null, def.getDesignation(), profile, CodeSystemUtilities.isNotSelectable(cs, def), CodeSystemUtilities.isInactive(cs, def), imports);
                        }
                    }
                }
            } else
                throw new NotImplementedException("Search by property[" + fc.getProperty() + "] and op[" + fc.getOp() + "] is not supported yet");
        }
    }
}
Also used : NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) ConceptDefinitionComponent(org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent) NotImplementedException(org.apache.commons.lang3.NotImplementedException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 63 with Property

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

the class RdfParser method composeTerminologyCapabilitiesTerminologyCapabilitiesCodeSystemVersionComponent.

protected void composeTerminologyCapabilitiesTerminologyCapabilitiesCodeSystemVersionComponent(Complex parent, String parentType, String name, TerminologyCapabilities.TerminologyCapabilitiesCodeSystemVersionComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "version", name, element, index);
    if (element.hasCodeElement())
        composeString(t, "TerminologyCapabilities", "code", element.getCodeElement(), -1);
    if (element.hasIsDefaultElement())
        composeBoolean(t, "TerminologyCapabilities", "isDefault", element.getIsDefaultElement(), -1);
    if (element.hasCompositionalElement())
        composeBoolean(t, "TerminologyCapabilities", "compositional", element.getCompositionalElement(), -1);
    for (int i = 0; i < element.getLanguage().size(); i++) composeCode(t, "TerminologyCapabilities", "language", element.getLanguage().get(i), i);
    for (int i = 0; i < element.getFilter().size(); i++) composeTerminologyCapabilitiesTerminologyCapabilitiesCodeSystemVersionFilterComponent(t, "TerminologyCapabilities", "filter", element.getFilter().get(i), i);
    for (int i = 0; i < element.getProperty().size(); i++) composeCode(t, "TerminologyCapabilities", "property", element.getProperty().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 64 with Property

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

the class RdfParser method composeValueSetConceptSetFilterComponent.

protected void composeValueSetConceptSetFilterComponent(Complex parent, String parentType, String name, ValueSet.ConceptSetFilterComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "filter", name, element, index);
    if (element.hasPropertyElement())
        composeCode(t, "ValueSet", "property", element.getPropertyElement(), -1);
    if (element.hasOpElement())
        composeEnum(t, "ValueSet", "op", element.getOpElement(), -1);
    if (element.hasValueElement())
        composeString(t, "ValueSet", "value", element.getValueElement(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 65 with Property

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

the class VerticalBarParser method parse.

@Override
public Element parse(InputStream stream) throws IOException, FHIRFormatError, DefinitionException, FHIRException {
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, "http://hl7.org/fhir/v2/StructureDefinition/Message");
    Element message = new Element("Message", new Property(context, sd.getSnapshot().getElementFirstRep(), sd));
    VerticalBarParserReader reader = new VerticalBarParserReader(new BufferedInputStream(stream), charset);
    preDecode(reader);
    while (// && (getOptions().getSegmentLimit() == 0 || getOptions().getSegmentLimit() > message.getSegments().size()))
    !reader.isFinished()) readSegment(message, reader);
    return message;
}
Also used : StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) BufferedInputStream(java.io.BufferedInputStream)

Aggregations

ArrayList (java.util.ArrayList)35 FHIRException (org.hl7.fhir.exceptions.FHIRException)35 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)30 JsonElement (com.google.gson.JsonElement)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)21 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)15 JsonObject (com.google.gson.JsonObject)14 List (java.util.List)14 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)14 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)11 HashMap (java.util.HashMap)8 HashSet (java.util.HashSet)8 Collectors (java.util.stream.Collectors)8 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)8 SpecialElement (org.hl7.fhir.r4b.elementmodel.Element.SpecialElement)8 NamedElement (org.hl7.fhir.r4b.elementmodel.ParserBase.NamedElement)8 SpecialElement (org.hl7.fhir.r5.elementmodel.Element.SpecialElement)8