use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project cqf-ruler by DBCG.
the class CollectDataProviderIT method testCollectData.
@Test
public void testCollectData() {
// Create test Measure
String cql = CqlBuilder.newCqlLibrary("4.0.1").addExpression("Initial Population", "exists([Observation])").build();
Library lib = Libraries.library(cql);
Measure m = MeasureBuilder.newCohortMeasure(lib).build();
this.update(lib);
this.update(m);
// Create test data
Patient john = Patients.john_doe();
this.create(john);
Observation obs = newResource(Observation.class).setSubject(new Reference(john));
this.create(obs);
Encounter enc = newResource(Encounter.class).setSubject(new Reference(john));
this.create(enc);
// Submit it
Parameters results = collectDataProvider.collectData(new SystemRequestDetails(), m.getIdElement(), "2019-01-01", "2019-12-31", Ids.simple(john), null, null);
List<ParametersParameterComponent> resources = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, "resource");
assertEquals(1, resources.size());
assertEquals("Observation", resources.get(0).getResource().fhirType());
List<ParametersParameterComponent> reports = org.opencds.cqf.ruler.utility.r4.Parameters.getPartsByName(results, "measureReport");
assertEquals(1, reports.size());
assertEquals("MeasureReport", reports.get(0).getResource().fhirType());
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project cqf-ruler by DBCG.
the class Session method applyPlanDefinition.
@Operation(name = "$apply", idempotent = true, type = PlanDefinition.class)
public CarePlan applyPlanDefinition(RequestDetails theRequest, @IdParam IdType theId, @OperationParam(name = "patient") String patientId, @OperationParam(name = "encounter") String encounterId, @OperationParam(name = "practitioner") String practitionerId, @OperationParam(name = "organization") String organizationId, @OperationParam(name = "userType") String userType, @OperationParam(name = "userLanguage") String userLanguage, @OperationParam(name = "userTaskContext") String userTaskContext, @OperationParam(name = "setting") String setting, @OperationParam(name = "settingContext") String settingContext) throws IOException, FHIRException {
PlanDefinition planDefinition = this.planDefinitionDao.read(theId);
if (planDefinition == null) {
throw new IllegalArgumentException("Couldn't find PlanDefinition " + theId);
}
logger.info("Performing $apply operation on PlanDefinition/{}", theId);
CarePlanBuilder builder = new CarePlanBuilder();
builder.buildInstantiatesCanonical(planDefinition.getUrl()).buildSubject(new Reference(patientId)).buildStatus(CarePlan.CarePlanStatus.DRAFT);
if (encounterId != null)
builder.buildEncounter(new Reference(encounterId));
if (practitionerId != null)
builder.buildAuthor(new Reference(practitionerId));
if (organizationId != null)
builder.buildAuthor(new Reference(organizationId));
if (userLanguage != null)
builder.buildLanguage(userLanguage);
// Each Group of actions shares a RequestGroup
RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
Session session = new Session(planDefinition, builder, patientId, encounterId, practitionerId, organizationId, userType, userLanguage, userTaskContext, setting, settingContext, requestGroupBuilder);
return (CarePlan) ContainedHelper.liftContainedResourcesToParent(resolveActions(session, theRequest));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project cqf-ruler by DBCG.
the class Session method applyPlanDefinition.
@Operation(name = "$apply", idempotent = true, type = PlanDefinition.class)
public CarePlan applyPlanDefinition(RequestDetails theRequest, @IdParam IdType theId, @OperationParam(name = "patient") String patientId, @OperationParam(name = "encounter") String encounterId, @OperationParam(name = "practitioner") String practitionerId, @OperationParam(name = "organization") String organizationId, @OperationParam(name = "userType") String userType, @OperationParam(name = "userLanguage") String userLanguage, @OperationParam(name = "userTaskContext") String userTaskContext, @OperationParam(name = "setting") String setting, @OperationParam(name = "settingContext") String settingContext) throws IOException, FHIRException {
PlanDefinition planDefinition = this.planDefinitionDao.read(theId);
if (planDefinition == null) {
throw new IllegalArgumentException("Couldn't find PlanDefinition " + theId);
}
logger.info("Performing $apply operation on PlanDefinition/{}", theId);
CarePlanBuilder builder = new CarePlanBuilder();
builder.buildDefinition(new Reference(planDefinition.getIdElement().getIdPart())).buildSubject(new Reference(patientId)).buildStatus(CarePlan.CarePlanStatus.DRAFT);
if (encounterId != null)
builder.buildContext(new Reference(encounterId));
if (practitionerId != null)
builder.buildAuthor(new Reference(practitionerId));
if (organizationId != null)
builder.buildAuthor(new Reference(organizationId));
if (userLanguage != null)
builder.buildLanguage(userLanguage);
// Each Group of actions shares a RequestGroup
RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
Session session = new Session(planDefinition, builder, patientId, encounterId, practitionerId, organizationId, userType, userLanguage, userTaskContext, setting, settingContext, requestGroupBuilder);
return (CarePlan) ContainedHelper.liftContainedResourcesToParent(resolveActions(theRequest, session));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainNonPatientContext.
@Test
public void testMainNonPatientContext() throws Exception {
Encounter encounter = new Encounter();
encounter.setId("123");
encounter.setStatus(Encounter.EncounterStatus.FINISHED);
Encounter otherEncounter = new Encounter();
otherEncounter.setId("234");
otherEncounter.setStatus(Encounter.EncounterStatus.FINISHED);
FhirServerConfig fhirConfig = getFhirServerConfig();
String resourcePath = "/Encounter?_count=1000&_format=json";
mockFhirResourceRetrieval(resourcePath, getFhirParser(), makeBundle(encounter, otherEncounter));
setupTestFor(encounter, fhirConfig, "cql.encounter-context");
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-t", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/encounter-context", "-l", "EncounterContext", "-v", "1.0.0", "-e", "ValidEncounterCount", "-n", "Encounter" });
} finally {
System.setOut(originalOut);
}
String output = baos.toString();
assertTrue(output.contains("Expression: \"ValidEncounterCount\", Result: 2"));
verify(1, getRequestedFor(urlEqualTo(resourcePath)));
} finally {
tmpFile.delete();
}
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ENCOUNTER in project quality-measure-and-cohort-service by Alvearie.
the class CqlTemporalTests method canFindMultipleEncountersFollowingEachOther.
@Test
public void canFindMultipleEncountersFollowingEachOther() throws Exception {
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
FhirServerConfig fhirConfig = getFhirServerConfig();
Bundle bundle = new Bundle();
Bundle.BundleEntryComponent firstEncounter = new Bundle.BundleEntryComponent();
firstEncounter.setResource(ENCOUNTER_1);
Bundle.BundleEntryComponent secondEncounter = new Bundle.BundleEntryComponent();
secondEncounter.setResource(ENCOUNTER_2);
bundle.addEntry(firstEncounter);
bundle.addEntry(secondEncounter);
mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), bundle, fhirConfig);
CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
String expression = "ValidEncounters2";
CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test3", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
Map<String, Object> expected = new HashMap<>();
expected.put(expression, true);
Assert.assertEquals(expected, actual.getExpressionResults());
}
Aggregations