Search in sources :

Example 81 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System 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 82 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System 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 83 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project quality-measure-and-cohort-service by Alvearie.

the class R4LibraryResourceFieldHandlerTest method getIdentifiers.

@Test
public void getIdentifiers() {
    Identifier identifier = new Identifier().setSystem("system").setValue("value");
    Library library = new Library();
    library.addIdentifier(identifier);
    List<Identifier> libraryIdentifiers = libraryFieldHandler.getIdentifiers(library);
    Assert.assertEquals(1, libraryIdentifiers.size());
    Assert.assertTrue(identifier.equalsDeep(libraryIdentifiers.get(0)));
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) Library(org.hl7.fhir.r4.model.Library) Test(org.junit.Test)

Example 84 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project quality-measure-and-cohort-service by Alvearie.

the class R4MeasureResourceFieldHandlerTest method getIdentifiers.

@Test
public void getIdentifiers() {
    Identifier identifier = new Identifier().setSystem("system").setValue("value");
    Measure measure = new Measure();
    measure.addIdentifier(identifier);
    List<Identifier> measureIdentifiers = measureFieldHandler.getIdentifiers(measure);
    Assert.assertEquals(1, measureIdentifiers.size());
    Assert.assertTrue(identifier.equalsDeep(measureIdentifiers.get(0)));
}
Also used : Identifier(org.hl7.fhir.r4.model.Identifier) Measure(org.hl7.fhir.r4.model.Measure) Test(org.junit.Test)

Example 85 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System 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

Test (org.junit.jupiter.api.Test)92 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)75 ArrayList (java.util.ArrayList)70 Coding (org.hl7.fhir.r4.model.Coding)70 Identifier (org.hl7.fhir.r4.model.Identifier)62 FHIRException (org.hl7.fhir.exceptions.FHIRException)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)45 Resource (org.hl7.fhir.r4.model.Resource)45 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 Test (org.junit.Test)37 Coding (org.hl7.fhir.dstu3.model.Coding)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 HashMap (java.util.HashMap)30 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)28 List (java.util.List)27 IOException (java.io.IOException)26 Bundle (org.hl7.fhir.r4.model.Bundle)26 Patient (org.hl7.fhir.r4.model.Patient)25 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21