use of org.hl7.fhir.dstu2.model.Reference 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.dstu2.model.Reference 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.dstu2.model.Reference in project cqf-ruler by DBCG.
the class DataOperationsProvider method getLibraryFromMeasure.
public Library getLibraryFromMeasure(Measure measure, RequestDetails theRequestDetails) {
Iterator<Reference> var6 = measure.getLibrary().iterator();
String libraryIdOrCanonical = null;
// use the first library
while (var6.hasNext() && libraryIdOrCanonical == null) {
Reference ref = var6.next();
if (ref != null) {
libraryIdOrCanonical = ref.getReference();
}
}
Library library = read(new IdType(libraryIdOrCanonical), theRequestDetails);
if (library == null) {
library = search(Library.class, Searches.byCanonical(libraryIdOrCanonical), theRequestDetails).firstOrNull();
}
return library;
}
use of org.hl7.fhir.dstu2.model.Reference in project cqf-ruler by DBCG.
the class Session method resolveActions.
private CarePlan resolveActions(RequestDetails theRequest, Session session) {
for (PlanDefinition.PlanDefinitionActionComponent action : session.getPlanDefinition().getAction()) {
// TODO - Apply input/output dataRequirements?
if (meetsConditions(theRequest, session, action)) {
Resource result = resolveDefinition(theRequest, session, action);
RequestGroupActionComponent currentActionTarget = null;
if (result != null) {
currentActionTarget = new RequestGroupActionBuilder().buildResource(new Reference("#" + result.getId())).build();
session.getRequestGroupBuilder().buildContained(result).addAction(currentActionTarget);
}
resolveDynamicActions(theRequest, session, currentActionTarget, action);
}
}
RequestGroup result = session.getRequestGroupBuilder().build();
if (result.getId() == null) {
result.setId(UUID.randomUUID().toString());
}
session.getCarePlanBuilder().buildContained(result).buildActivity(new CarePlanActivityBuilder().buildReference(new Reference("#" + result.getId())).build());
return session.getCarePlan();
}
use of org.hl7.fhir.dstu2.model.Reference in project cqf-ruler by DBCG.
the class Session method resolveDefinition.
private Resource resolveDefinition(RequestDetails theRequest, Session session, PlanDefinition.PlanDefinitionActionComponent action) {
Resource result = null;
if (action.hasDefinition()) {
logger.debug("Resolving definition: {}", action.getDefinition().getReference());
Reference definition = action.getDefinition();
if (definition.getId().contains(session.getPlanDefinition().fhirType())) {
IdType id = new IdType(definition.getId());
CarePlan plan;
try {
plan = applyPlanDefinition(theRequest, id, session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), session.getUserType(), session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
if (plan.getId() == null) {
plan.setId(UUID.randomUUID().toString());
}
// Add an action to the request group which points to this CarePlan
session.getRequestGroupBuilder().buildContained(plan).addAction(new RequestGroupActionBuilder().buildResource(new Reference("#" + plan.getId())).build());
for (Reference r : plan.getDefinition()) {
session.getCarePlanBuilder().buildDefinition(r);
}
result = plan;
} catch (IOException e) {
e.printStackTrace();
logger.error("nested plan failed");
}
} else {
try {
if (action.getDefinition().getReferenceElement().getIdPart().startsWith("#")) {
result = this.activityDefinitionApplyProvider.resolveActivityDefinition((ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinition().getReferenceElement().getIdPart()), session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest);
} else {
result = this.activityDefinitionApplyProvider.apply(theRequest, new IdType(action.getDefinition().getReferenceElement().getIdPart()), session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), null, session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
}
if (result.getId() == null) {
logger.warn("ActivityDefinition {} returned resource with no id, setting one", action.getDefinition().getReferenceElement().getIdPart());
result.setId(UUID.randomUUID().toString());
}
session.getRequestGroupBuilder().buildContained(result).addAction(new RequestGroupActionBuilder().buildResource(new Reference("#" + result.getId())).build());
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition {} could not be applied and threw exception {}", action.getDefinition(), e.toString());
}
}
}
return result;
}
Aggregations