Search in sources :

Example 1 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project gpconnect-demonstrator by nhsconnect.

the class ValueSetValidator method findValueSet.

private ValueSet findValueSet(String systemUrl) {
    int valueSetNamePos = systemUrl.lastIndexOf("/") + 1;
    String valueSetFilename = String.format("%s.xml", systemUrl.substring(valueSetNamePos));
    ValueSet valSet = null;
    String xmlContent = null;
    if (fhirValueSetsCheckWebFirst == true) {
        xmlContent = readValueSetFromWeb(valueSetFilename);
    }
    if (xmlContent == null) {
        xmlContent = readValueSetFromDisk(valueSetFilename);
    }
    if (fhirValueSetsCheckWebFirst == false && xmlContent == null) {
        xmlContent = readValueSetFromWeb(valueSetFilename);
    }
    if (xmlContent != null) {
        try {
            FhirContext fhirCtx = FhirContext.forDstu3();
            IParser parser = fhirCtx.newXmlParser();
            valSet = parser.parseResource(ValueSet.class, xmlContent);
        } catch (DataFormatException ex) {
            LOG.error(String.format("Error parsing valueSetFilename: %s", valueSetFilename));
        }
    }
    if (valSet == null) {
        throw OperationOutcomeFactory.buildOperationOutcomeException(new UnprocessableEntityException(String.format("Could not find or parse Value Set [SystemUrl: %s] at: %s. See system log for details.", systemUrl, valueSetFilename)), SystemCode.REFERENCE_NOT_FOUND, IssueType.NOTFOUND);
    }
    return valSet;
}
Also used : UnprocessableEntityException(ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException) FhirContext(ca.uhn.fhir.context.FhirContext) DataFormatException(ca.uhn.fhir.parser.DataFormatException) ValueSet(org.hl7.fhir.dstu3.model.ValueSet) IParser(ca.uhn.fhir.parser.IParser)

Example 2 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project gpconnect-demonstrator by nhsconnect.

the class ValueSetValidator method validateCode.

public Boolean validateCode(Coding code) {
    String systemUrl = code.getSystem();
    ValueSet valSet = loadValueSet(systemUrl);
    // Check Code System
    @SuppressWarnings("unused") ValueSetComposeComponent codeSys = valSet.getCompose();
    @SuppressWarnings("unused") List<ValueSet.ConceptReferenceComponent> concepts;
    return true;
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent)

Example 3 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project gpconnect-demonstrator by nhsconnect.

the class ValueSetValidator method loadValueSet.

private ValueSet loadValueSet(String systemUrl) {
    ValueSet set;
    set = getValueSetFromCache(systemUrl);
    if (set == null) {
        set = findValueSet(systemUrl);
        if (valueSetCache == null) {
            valueSetCache = new HashMap<String, ValueSet>();
        }
        valueSetCache.put(systemUrl, set);
    }
    return set;
}
Also used : ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Example 4 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project bunsen by cerner.

the class ValueSets method expandValuesIterator.

private static Iterator<Value> expandValuesIterator(ValueSet valueSet) {
    List<Value> values = new ArrayList<>();
    ValueSetComposeComponent compose = valueSet.getCompose();
    for (ConceptSetComponent inclusion : compose.getInclude()) {
        for (ConceptReferenceComponent concept : inclusion.getConcept()) {
            Value value = new Value();
            value.setValueSetUri(valueSet.getUrl());
            value.setValueSetVersion(valueSet.getVersion());
            value.setSystem(inclusion.getSystem());
            value.setVersion(inclusion.getVersion());
            value.setValue(concept.getCode());
            values.add(value);
        }
    }
    return values.iterator();
}
Also used : ConceptSetComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent) ArrayList(java.util.ArrayList) ValueSetComposeComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetComposeComponent) ConceptReferenceComponent(org.hl7.fhir.dstu3.model.ValueSet.ConceptReferenceComponent)

Example 5 with ValueSet

use of org.hl7.fhir.dstu2016may.model.ValueSet in project bunsen by cerner.

the class ValueSets method withValueSets.

private ValueSets withValueSets(Dataset<ValueSet> newValueSets, Dataset<Value> newValues) {
    Dataset<UrlAndVersion> newMembers = getUrlAndVersions(newValueSets);
    // Instantiating a new composite ConceptMaps requires a new timestamp
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    Dataset<ValueSet> newValueSetsWithTimestamp = newValueSets.withColumn("timestamp", lit(timestamp.toString()).cast("timestamp")).as(VALUE_SET_ENCODER);
    return new ValueSets(spark, this.members.union(newMembers), this.valueSets.union(newValueSetsWithTimestamp), this.values.union(newValues));
}
Also used : Timestamp(java.sql.Timestamp) ValueSet(org.hl7.fhir.dstu3.model.ValueSet)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)115 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)95 ValueSet (org.hl7.fhir.dstu3.model.ValueSet)59 ValueSet (org.hl7.fhir.r4b.model.ValueSet)59 FileNotFoundException (java.io.FileNotFoundException)58 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)56 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)46 HashMap (java.util.HashMap)45 Test (org.junit.Test)45 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)43 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 File (java.io.File)35 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)31 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)29 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)29 FileInputStream (java.io.FileInputStream)27