Search in sources :

Example 71 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProviderTest method inOperationReturnsFalseWhenFhirReturnsFalse.

@Test
public void inOperationReturnsFalseWhenFhirReturnsFalse() throws Exception {
    ValueSetInfo info = new ValueSetInfo();
    info.setId("urn:oid:Test");
    Code code = new Code();
    code.setSystem(TEST_SYSTEM);
    code.setCode(TEST_CODE);
    code.setDisplay(TEST_DISPLAY);
    Parameters parameters = new Parameters();
    parameters.getParameterFirstRep().setName("result").setValue(new BooleanType(false));
    mockFhirResourceRetrieval("/ValueSet/Test/$validate-code?code=" + urlencode(code.getCode()) + "&system=" + urlencode(code.getSystem()) + "&_format=json", parameters);
    boolean result = provider.in(code, info);
    assertFalse(result);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) BooleanType(org.hl7.fhir.r4.model.BooleanType) ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 72 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProviderTest method expandOperationReturnsCorrectCodesMoreThanZero.

@Test
public void expandOperationReturnsCorrectCodesMoreThanZero() {
    ValueSetInfo info = new ValueSetInfo();
    info.setId("urn:oid:Test");
    ValueSet valueSet = new ValueSet();
    valueSet.setId("Test");
    valueSet.getExpansion().getContainsFirstRep().setSystem(TEST_SYSTEM).setCode(TEST_CODE);
    Parameters parameters = new Parameters();
    parameters.getParameterFirstRep().setName("return").setResource(valueSet);
    mockFhirResourceRetrieval("/ValueSet/Test/$expand?_format=json", parameters);
    Iterable<Code> codes = provider.expand(info);
    List<Code> list = StreamSupport.stream(codes.spliterator(), false).collect(Collectors.toList());
    assertEquals(list.size(), 1);
    assertEquals(list.get(0).getSystem(), TEST_SYSTEM);
    assertEquals(list.get(0).getCode(), TEST_CODE);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) ValueSet(org.hl7.fhir.r4.model.ValueSet) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 73 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.

the class R4RestFhirTerminologyProviderTest method inOperationReturnsTrueWhenFhirReturnsTrue.

@Test
public void inOperationReturnsTrueWhenFhirReturnsTrue() throws Exception {
    ValueSetInfo info = new ValueSetInfo();
    info.setId("urn:oid:Test");
    Code code = new Code();
    code.setSystem(TEST_SYSTEM);
    code.setCode(TEST_CODE);
    code.setDisplay(TEST_DISPLAY);
    Parameters parameters = new Parameters();
    parameters.getParameterFirstRep().setName("result").setValue(new BooleanType(true));
    mockFhirResourceRetrieval("/ValueSet/Test/$validate-code?code=" + urlencode(code.getCode()) + "&system=" + urlencode(code.getSystem()) + "&_format=json", parameters);
    boolean result = provider.in(code, info);
    assertTrue(result);
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) BooleanType(org.hl7.fhir.r4.model.BooleanType) ValueSetInfo(org.opencds.cqf.cql.engine.terminology.ValueSetInfo) Code(org.opencds.cqf.cql.engine.runtime.Code) Test(org.junit.Test)

Example 74 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.

the class R4FileSystemFhirTerminologyProvider method in.

/* (non-Javadoc)
	 * 
	 * Returns true if the provided code exists in the provided ValueSet
	 * 
	 * @see org.opencds.cqf.cql.engine.terminology.TerminologyProvider#in(org.opencds.cqf.cql.engine.runtime.Code, org.opencds.cqf.cql.engine.terminology.ValueSetInfo)
	 */
@Override
public boolean in(Code code, ValueSetInfo valueSetInfo) {
    LOG.debug("Entry: in() ValueSet.getId=[{}] version=[{}]", valueSetInfo.getId(), valueSetInfo.getVersion());
    loadFromFile(valueSetInfo);
    VersionedIdentifier valueSetIdentifier = createVersionedIdentifierForValueSet(valueSetInfo);
    // get the valueSet codes from the cache if it is there
    Map<String, Set<String>> codesToCodeSystems = valueSetToCodesCache.get(valueSetIdentifier);
    if (codesToCodeSystems != null) {
        Set<String> systems = codesToCodeSystems.get(code.getCode());
        // if systems is null/empty, then the code isn't in the valueset
        if (systems != null && !systems.isEmpty()) {
            if (code.getSystem() == null) {
                // are codes with more than 1 codesystem present in the valueset, throw an error
                if (systems.size() > 1) {
                    throw new IllegalArgumentException("Ambiguous code lookup of code[" + code.getCode() + "] under valueset[" + valueSetIdentifier.getId() + "]");
                } else {
                    return true;
                }
            } else {
                return systems.contains(code.getSystem());
            }
        }
    }
    LOG.debug("Exit: in() ValueSet.getId=[{}] version=[{}]", valueSetInfo.getId(), valueSetInfo.getVersion());
    return false;
}
Also used : VersionedIdentifier(org.cqframework.cql.elm.execution.VersionedIdentifier) ValueSet(org.hl7.fhir.r4.model.ValueSet) HashSet(java.util.HashSet) Set(java.util.Set)

Example 75 with ValueSet

use of org.hl7.fhir.r4.model.ValueSet in project quality-measure-and-cohort-service by Alvearie.

the class ValueSetUtil method createArtifact.

public static ValueSetArtifact createArtifact(InputStream is, Map<String, String> customCodeSystem) throws IOException {
    XSSFSheet informationSheet;
    try (XSSFWorkbook wb = new XSSFWorkbook(is)) {
        informationSheet = wb.getSheetAt(wb.getSheetIndex("Expansion List"));
    } catch (IllegalArgumentException e) {
        throw new RuntimeException("Spreadsheet is missing required sheet \"Expansion List\"", e);
    }
    ValueSet valueSet = new ValueSet();
    boolean inCodesSection = false;
    valueSet.setStatus(Enumerations.PublicationStatus.ACTIVE);
    HashMap<CodeSystemKey, List<ValueSet.ConceptReferenceComponent>> codeSystemToCodes = new HashMap<>();
    String url = "http://cts.nlm.nih.gov/fhir/ValueSet/";
    String identifier = null;
    for (Row currentRow : informationSheet) {
        String code = currentRow.getCell(0) == null ? "" : currentRow.getCell(0).getStringCellValue();
        if (!code.equals("") && currentRow.getCell(1) != null && !inCodesSection) {
            String value;
            switch(currentRow.getCell(1).getCellType()) {
                case NUMERIC:
                    value = Double.toString(currentRow.getCell(1).getNumericCellValue());
                    break;
                case STRING:
                    value = currentRow.getCell(1).getStringCellValue();
                    break;
                default:
                    throw new RuntimeException("Cell type does not match either String or Numeric for key " + code);
            }
            switch(currentRow.getCell(0).getStringCellValue().toLowerCase()) {
                case "value set name":
                    valueSet.setName(value);
                    valueSet.setTitle(value);
                    break;
                case "id":
                    valueSet.setId(value);
                    identifier = value;
                    break;
                case "oid":
                    if (valueSet.getId() == null) {
                        valueSet.setId(value);
                        identifier = value;
                    }
                    break;
                case "url":
                    // fallthrough
                    url = value.endsWith("/") ? value : value + "/";
                case "definition version":
                    valueSet.setVersion(value);
                    break;
                case "code":
                    inCodesSection = true;
                    break;
                default:
                    break;
            }
        } else if (inCodesSection) {
            String display = currentRow.getCell(1).getStringCellValue();
            String codeSystemEntry = currentRow.getCell(2).getStringCellValue();
            String codeSystemVersion = currentRow.getCell(3).getStringCellValue();
            String codeSystem;
            if (codeSystemEntry.startsWith("http://") || codeSystemEntry.startsWith("https://")) {
                codeSystem = codeSystemEntry;
            } else if (customCodeSystem != null && customCodeSystem.get(codeSystemEntry) != null) {
                codeSystem = customCodeSystem.get(codeSystemEntry);
            } else {
                codeSystem = CodeSystemLookup.getUrlFromName(codeSystemEntry);
            }
            if (codeSystem == null) {
                throw new IllegalArgumentException("Unmatched Code System! " + codeSystemEntry + " not found!");
            }
            ValueSet.ConceptReferenceComponent concept = new ValueSet.ConceptReferenceComponent();
            concept.setCode(code);
            concept.setDisplay(display);
            List<ValueSet.ConceptReferenceComponent> conceptsSoFar = codeSystemToCodes.computeIfAbsent(new CodeSystemKey(codeSystem, codeSystemVersion), x -> new ArrayList<>());
            conceptsSoFar.add(concept);
        }
    }
    if (identifier == null || identifier.equals("")) {
        throw new RuntimeException("There must be an Identifier specified! Please populate the ID field");
    }
    valueSet.setUrl(url + identifier);
    valueSet.setId(identifier);
    ValueSet.ValueSetComposeComponent compose = new ValueSet.ValueSetComposeComponent();
    for (Entry<CodeSystemKey, List<ConceptReferenceComponent>> singleInclude : codeSystemToCodes.entrySet()) {
        ValueSet.ConceptSetComponent component = new ValueSet.ConceptSetComponent();
        component.setSystem(singleInclude.getKey().getCodeSystem());
        component.setVersion(singleInclude.getKey().getCodeSystemVersion());
        component.setConcept(singleInclude.getValue());
        compose.addInclude(component);
    }
    valueSet.setCompose(compose);
    ValueSetArtifact artifact = new ValueSetArtifact();
    artifact.setName(valueSet.getName());
    artifact.setFhirResource(valueSet);
    artifact.setUrl(valueSet.getUrl());
    return artifact;
}
Also used : ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Enumerations(org.hl7.fhir.r4.model.Enumerations) IOException(java.io.IOException) HashMap(java.util.HashMap) ValueSet(org.hl7.fhir.r4.model.ValueSet) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) List(java.util.List) Map(java.util.Map) Entry(java.util.Map.Entry) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) Row(org.apache.poi.ss.usermodel.Row) Bundle(org.hl7.fhir.r4.model.Bundle) BufferedReader(java.io.BufferedReader) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ArrayList(java.util.ArrayList) List(java.util.List) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Row(org.apache.poi.ss.usermodel.Row) ValueSet(org.hl7.fhir.r4.model.ValueSet)

Aggregations

ValueSet (org.hl7.fhir.r5.model.ValueSet)159 ValueSet (org.hl7.fhir.r4.model.ValueSet)116 Test (org.junit.jupiter.api.Test)115 ArrayList (java.util.ArrayList)101 FHIRException (org.hl7.fhir.exceptions.FHIRException)100 IOException (java.io.IOException)97 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 File (java.io.File)36 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)36 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