Search in sources :

Example 26 with UriType

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

the class ValueSetExpanderSimple method importValueSet.

private void importValueSet(String value, List<ValueSetExpansionParameterComponent> params) throws ETooCostly, TerminologyServiceException, FileNotFoundException, IOException {
    if (value == null)
        throw new TerminologyServiceException("unable to find value set with no identity");
    ValueSet vs = context.fetchResource(ValueSet.class, value);
    if (vs == null)
        throw new TerminologyServiceException("Unable to find imported value set " + value);
    ValueSetExpansionOutcome vso = factory.getExpander().expand(vs);
    if (vso.getService() != null)
        throw new TerminologyServiceException("Unable to expand imported value set " + value);
    if (vs.hasVersion())
        if (!existsInParams(params, "version", new UriType(vs.getUrl() + "?version=" + vs.getVersion())))
            params.add(new ValueSetExpansionParameterComponent().setName("version").setValue(new UriType(vs.getUrl() + "?version=" + vs.getVersion())));
    for (ValueSetExpansionParameterComponent p : vso.getValueset().getExpansion().getParameter()) {
        if (!existsInParams(params, p.getName(), p.getValue()))
            params.add(p);
    }
    for (ValueSetExpansionContainsComponent c : vso.getValueset().getExpansion().getContains()) {
        addCode(c.getSystem(), c.getCode(), c.getDisplay());
    }
}
Also used : ValueSetExpansionContainsComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionContainsComponent) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu2016may.model.ValueSet.ValueSetExpansionParameterComponent) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ValueSet(org.hl7.fhir.dstu2016may.model.ValueSet) UriType(org.hl7.fhir.dstu2016may.model.UriType)

Example 27 with UriType

use of org.hl7.fhir.dstu2016may.model.UriType 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)

Example 28 with UriType

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

the class ValueSet method setProperty.

@Override
public void setProperty(String name, Base value) throws FHIRException {
    if (name.equals("url"))
        // UriType
        this.url = castToUri(value);
    else if (name.equals("identifier"))
        // Identifier
        this.identifier = castToIdentifier(value);
    else if (name.equals("version"))
        // StringType
        this.version = castToString(value);
    else if (name.equals("name"))
        // StringType
        this.name = castToString(value);
    else if (name.equals("status"))
        // Enumeration<ConformanceResourceStatus>
        this.status = new ConformanceResourceStatusEnumFactory().fromType(value);
    else if (name.equals("experimental"))
        // BooleanType
        this.experimental = castToBoolean(value);
    else if (name.equals("publisher"))
        // StringType
        this.publisher = castToString(value);
    else if (name.equals("contact"))
        this.getContact().add((ValueSetContactComponent) value);
    else if (name.equals("date"))
        // DateTimeType
        this.date = castToDateTime(value);
    else if (name.equals("lockedDate"))
        // DateType
        this.lockedDate = castToDate(value);
    else if (name.equals("description"))
        // StringType
        this.description = castToString(value);
    else if (name.equals("useContext"))
        this.getUseContext().add(castToCodeableConcept(value));
    else if (name.equals("immutable"))
        // BooleanType
        this.immutable = castToBoolean(value);
    else if (name.equals("requirements"))
        // StringType
        this.requirements = castToString(value);
    else if (name.equals("copyright"))
        // StringType
        this.copyright = castToString(value);
    else if (name.equals("extensible"))
        // BooleanType
        this.extensible = castToBoolean(value);
    else if (name.equals("compose"))
        // ValueSetComposeComponent
        this.compose = (ValueSetComposeComponent) value;
    else if (name.equals("expansion"))
        // ValueSetExpansionComponent
        this.expansion = (ValueSetExpansionComponent) value;
    else
        super.setProperty(name, value);
}
Also used : ConformanceResourceStatusEnumFactory(org.hl7.fhir.dstu2016may.model.Enumerations.ConformanceResourceStatusEnumFactory)

Example 29 with UriType

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

the class R2016MayToR5Loader method loadResource.

@Override
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2016may = null;
    if (isJson)
        r2016may = new JsonParser().parse(stream);
    else
        r2016may = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_14_50.convertResource(r2016may);
    setPath(r5);
    if (!advisor.getCslist().isEmpty()) {
        throw new FHIRException("Error: Cannot have included code systems");
    }
    if (killPrimitives) {
        throw new FHIRException("Cannot kill primitives when using deferred loading");
    }
    if (patchUrls) {
        if (r5 instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) r5;
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
            for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
        }
    }
    return r5;
}
Also used : XmlParser(org.hl7.fhir.dstu2016may.formats.XmlParser) Resource(org.hl7.fhir.dstu2016may.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu2016may.formats.JsonParser)

Example 30 with UriType

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

the class R2ToR5Loader method loadResource.

@Override
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2 = null;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2, advisor);
    setPath(r5);
    if (!advisor.getCslist().isEmpty()) {
        throw new FHIRException("Error: Cannot have included code systems");
    }
    if (killPrimitives) {
        throw new FHIRException("Cannot kill primitives when using deferred loading");
    }
    if (patchUrls) {
        if (r5 instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) r5;
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
            for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
        }
    }
    return r5;
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Resource(org.hl7.fhir.dstu2.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)60 UriType (org.hl7.fhir.r5.model.UriType)45 ArrayList (java.util.ArrayList)42 UriType (org.hl7.fhir.r4.model.UriType)41 UriType (org.hl7.fhir.r4b.model.UriType)29 UriType (org.hl7.fhir.dstu3.model.UriType)26 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)22 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)19 List (java.util.List)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 NotImplementedException (org.apache.commons.lang3.NotImplementedException)15 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 UriType (org.hl7.fhir.dstu2016may.model.UriType)12 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 Coding (org.hl7.fhir.r4.model.Coding)12 IOException (java.io.IOException)11 StringType (org.hl7.fhir.r4.model.StringType)10 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)10 StringType (org.hl7.fhir.r5.model.StringType)10