Skip to content

Commit

Permalink
Extract Zip and Update Tests
Browse files Browse the repository at this point in the history
Also removed display from criterion reference name
  • Loading branch information
bastianschaffer committed Sep 4, 2024
1 parent b239112 commit d0c80c8
Show file tree
Hide file tree
Showing 798 changed files with 830 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static Container<RetrieveExpression> retrieveExpr(MappingContext mappingContext,
}

private static String referenceName(TermCode termCode) {
return "%s".formatted(termCode.display() + termCode.code() + "Ref");
return termCode.code() + "Ref";
}

public abstract T appendAttributeFilter(AttributeFilter attributeFilter);
Expand Down
52 changes: 14 additions & 38 deletions src/test/java/de/numcodex/sq2cql/AcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import de.numcodex.sq2cql.model.structured_query.StructuredQuery;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.*;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.Library;
import org.hl7.fhir.r4.model.Measure;
import org.hl7.fhir.r4.model.MeasureReport;
import org.hl7.fhir.r4.model.Parameters;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
Expand All @@ -32,9 +36,8 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.zip.ZipFile;
import java.util.stream.Stream;

import static de.numcodex.sq2cql.Util.createTranslator;
import static java.lang.String.format;
Expand Down Expand Up @@ -78,41 +81,14 @@ private static Bundle createBundle(Library library, Measure measure) {
}

public static List<StructuredQuery> getTestQueriesReturningOnePatient() throws URISyntaxException, IOException {
var exclusions = Set.of("new_testdata/1-age.json",
// Blaze can't parse the unit [arb'U]/mL https://github.com/samply/blaze/issues/1234
"new_testdata/ObservationLab-38dfe76b-ae35-8290-6d80-ab08c963d148",
"new_testdata/ObservationLab-16408169-a38d-8afc-fdd2-ed7af97ccc57",
"new_testdata/ObservationLab-0fa07a3f-2e29-5065-6fa2-31e959acdd98",
"new_testdata/ObservationLab-43eb280e-7901-7990-64e3-22cfa51de78b",
"new_testdata/ObservationLab-09c67417-306a-a871-feef-71cbc915d113",
"new_testdata/ObservationLab-26184c80-edf6-b1e0-ee8f-0e0999755cb9",
"new_testdata/ObservationLab-9d44c93e-7799-a8e2-b368-c5539c30ceaa",
"new_testdata/ObservationLab-755a3ac1-32ae-2a20-1ac9-02ee25777cf0",
"new_testdata/ObservationLab-8ec9ea98-6581-f934-9bcf-b1c4f87e3560",
"new_testdata/ObservationLab-315e8080-7425-f4e9-3891-aef5ebe0572c",
"new_testdata/ObservationLab-44c8fd00-1a0f-f218-9eb8-83257add8fed",
"new_testdata/ObservationLab-7a2be049-40d2-d16f-3db6-12f46df2fc82",
"new_testdata/ObservationLab-78c5a976-1786-72e8-006b-8fd6af157ed9",
"new_testdata/ObservationLab-254bf7ae-1d0a-b994-f20b-575d4e28e674",
"new_testdata/ObservationLab-4bf41e10-1c62-2f82-d081-3d923aca43f2",
// Blaze can't parse the unit /[HPF]
"new_testdata/ObservationLab-bf7b68ae-1f89-41b6-e6a1-a40bf031f4b9",
"new_testdata/ObservationLab-b080e003-5e7f-503c-4b13-47f601d6d903",
"new_testdata/ObservationLab-3dd0c866-0649-def5-0fb2-de1ea0b976c2",
"new_testdata/ObservationLab-98b33c6e-0a14-b90a-7795-e98680ee526e",
// Blaze can't parse the unit /100{WBCs}
"new_testdata/ObservationLab-d2d07223-0b20-ee0f-8505-0a17d2e1ed4d"
);
try (var zipFile = new ZipFile(resourcePath("returningOnePatient.zip").toString())) {
return zipFile.stream()
.filter(entry -> !exclusions.contains(entry.toString()))
.map(entry -> {
try {
return new ObjectMapper().readValue(zipFile.getInputStream(entry), StructuredQuery.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}).toList();
try (Stream<Path> paths = Files.list(resourcePath("returningOnePatient"))) {
return paths.map(path -> {
try {
return new ObjectMapper().readValue(Files.readString(path), StructuredQuery.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}).toList();
}
}

Expand Down
42 changes: 21 additions & 21 deletions src/test/java/de/numcodex/sq2cql/MedicationAdministrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public void translateMedicationAdministration() throws Exception {
context Unfiltered
define HeparinB01AB01Ref:
define B01AB01Ref:
from [Medication: Code 'B01AB01' from atc] M
return 'Medication/' + M.id
context Patient
define Criterion:
exists (from [MedicationAdministration] M
where M.medication.reference in HeparinB01AB01Ref)
where M.medication.reference in B01AB01Ref)
define InInitialPopulation:
Criterion
Expand All @@ -74,15 +74,15 @@ public void translateMedicationAdministrationTimeRestriction() throws Exception
context Unfiltered
define HeparinB01AB01Ref:
define B01AB01Ref:
from [Medication: Code 'B01AB01' from atc] M
return 'Medication/' + M.id
context Patient
define Criterion:
exists (from [MedicationAdministration] M
where M.medication.reference in HeparinB01AB01Ref and
where M.medication.reference in B01AB01Ref and
(ToDate(M.effective as dateTime) in Interval[@2024-01-01, @2024-02-01] or
M.effective overlaps Interval[@2024-01-01, @2024-02-01]))
Expand All @@ -107,21 +107,21 @@ public void translateMedicationAdministrationDoubleCriteria() throws Exception {
context Unfiltered
define HeparinB01AB01Ref:
define B01AB01Ref:
from [Medication: Code 'B01AB01' from atc] M
return 'Medication/' + M.id
context Patient
define "Criterion 1":
exists (from [MedicationAdministration] M
where M.medication.reference in HeparinB01AB01Ref and
where M.medication.reference in B01AB01Ref and
(ToDate(M.effective as dateTime) in Interval[@2024-01-01, @2024-02-01] or
M.effective overlaps Interval[@2024-01-01, @2024-02-01]))
define "Criterion 2":
exists (from [MedicationAdministration] M
where M.medication.reference in HeparinB01AB01Ref and
where M.medication.reference in B01AB01Ref and
(ToDate(M.effective as dateTime) in Interval[@2023-01-01, @2023-02-01] or
M.effective overlaps Interval[@2023-01-01, @2023-02-01]))
Expand All @@ -142,29 +142,29 @@ public void translateMedicationAdministrationTwoCriteria() throws Exception {
library Retrieve version '1.0.0'
using FHIR version '4.0.0'
include FHIRHelpers version '4.0.0'
codesystem atc: 'http://fhir.de/CodeSystem/bfarm/atc'
context Unfiltered
define "AcetylsalicylsäureB01AC06Ref":
from [Medication: Code 'B01AC06' from atc] M
return 'Medication/' + M.id
define HeparinB01AB01Ref:
define B01AB01Ref:
from [Medication: Code 'B01AB01' from atc] M
return 'Medication/' + M.id
define B01AC06Ref:
from [Medication: Code 'B01AC06' from atc] M
return 'Medication/' + M.id
context Patient
define "Criterion 1":
exists (from [MedicationAdministration] M
where M.medication.reference in HeparinB01AB01Ref)
where M.medication.reference in B01AB01Ref)
define "Criterion 2":
exists (from [MedicationAdministration] M
where M.medication.reference in "AcetylsalicylsäureB01AC06Ref")
where M.medication.reference in B01AC06Ref)
define InInitialPopulation:
"Criterion 1" and
"Criterion 2"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "I08.0", "display": "", "system": "http://fhir.de/CodeSystem/bfarm/icd-10-gm"}], "context": {"code": "Diagnose", "display": "Diagnose", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "P01CA", "display": "", "system": "http://fhir.de/CodeSystem/bfarm/atc"}], "context": {"code": "Medikamentenverabreichung", "display": "Verabreichung von Medikamenten", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "46128-5", "display": "", "system": "http://loinc.org"}], "valueFilter": {"selectedConcepts": [{"code": "260373001", "display": "", "system": "http://snomed.info/sct"}], "type": "concept"}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "734-4", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "10*3/uL", "display": "10*3/uL"}, "value": 22.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "32207-3", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "fL", "display": "fL"}, "value": -14.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "40569-6", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "10*3/uL", "display": "10*3/uL"}, "value": 67.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "2705-2", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mm[Hg]", "display": "mm[Hg]"}, "value": -80.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "4542-7", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mg/dL", "display": "mg/dL"}, "value": 17.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "20483-4", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "{titer}", "display": "{titer}"}, "value": -22.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "728-6", "display": "", "system": "http://loinc.org"}], "valueFilter": {"selectedConcepts": [{"code": "260373001", "display": "", "system": "http://snomed.info/sct"}], "type": "concept"}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "30433-7", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "10*3/uL", "display": "10*3/uL"}, "value": 1.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "26465-5", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "/uL", "display": "/uL"}, "value": 61.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "2069-3", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mmol/L", "display": "mmol/L"}, "value": 38.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "19234-4", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mmol/L", "display": "mmol/L"}, "value": 58.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "1961-2", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mmol/L", "display": "mmol/L"}, "value": 87.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "2871-2", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "g/dL", "display": "g/dL"}, "value": -45.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "5235-7", "display": "", "system": "http://loinc.org"}], "valueFilter": {"selectedConcepts": [{"code": "260415000", "display": "", "system": "http://snomed.info/sct"}], "type": "concept"}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "2164-2", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mL/min", "display": "mL/min"}, "value": 7.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "13983-2", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "%", "display": "%"}, "value": -48.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "15152-2", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mg/dL", "display": "mg/dL"}, "value": 46.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "2704-5", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "mm[Hg]", "display": "mm[Hg]"}, "value": 77.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "26511-6", "display": "", "system": "http://loinc.org"}], "valueFilter": {"comparator": "eq", "type": "quantity-comparator", "unit": {"code": "%", "display": "%"}, "value": 66.0}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"inclusionCriteria": [[{"attributeFilters": [], "termCodes": [{"code": "94531-1", "display": "", "system": "http://loinc.org"}], "valueFilter": {"selectedConcepts": [{"code": "260373001", "display": "", "system": "http://snomed.info/sct"}], "type": "concept"}, "context": {"code": "Laboruntersuchung", "display": "Laboruntersuchung", "system": "fdpg.mii.cds", "version": "1.0.0"}}]], "version": "http://to_be_decided.com/draft-1/schema#"}
Loading

0 comments on commit d0c80c8

Please sign in to comment.