use of org.hl7.fhir.r4b.model.IdType in project cqf-ruler by DBCG.
the class DataOperationsProvider method dataRequirements.
@Operation(name = "$data-requirements", idempotent = true, type = Measure.class)
public Library dataRequirements(@IdParam IdType theId, @OperationParam(name = "startPeriod") String startPeriod, @OperationParam(name = "endPeriod") String endPeriod, RequestDetails theRequestDetails) throws InternalErrorException, FHIRException {
Measure measure = read(theId, theRequestDetails);
Library library = getLibraryFromMeasure(measure, theRequestDetails);
if (library == null) {
throw new RuntimeException("Could not load measure library.");
}
// TODO: Pass startPeriod and endPeriod as parameters to the data requirements operation
return processDataRequirements(measure, library, theRequestDetails);
}
use of org.hl7.fhir.r4b.model.IdType 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.r4b.model.IdType 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;
}
use of org.hl7.fhir.r4b.model.IdType 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.r4b.model.IdType in project cqf-ruler by DBCG.
the class ExpressionEvaluation method setupContext.
private Context setupContext(DomainResource instance, String cql, String patientId, Boolean aliasedExpression, RequestDetails theRequest) {
JpaFhirDal jpaFhirDal = jpaFhirDalFactory.create(theRequest);
List<CanonicalType> libraries = getLibraryReferences(instance, theRequest);
String fhirVersion = this.fhirContext.getVersion().getVersion().getFhirVersionString();
// Remove LocalLibrary from cache first...
VersionedIdentifier localLibraryIdentifier = new VersionedIdentifier().withId("LocalLibrary");
globalLibraryCache.remove(localLibraryIdentifier);
// temporary LibraryLoader to resolve library dependencies when building
// includes
LibraryLoader tempLibraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest))));
String source = "";
if (aliasedExpression) {
if (libraries.size() != 1) {
throw new RuntimeException("If an aliased expression is provided, there must be exactly one primary Library");
}
VersionedIdentifier vi = getVersionedIdentifierFromCanonical(libraries.get(0));
// Still not the best way to build include, but at least checks dal for an
// existing library
// Check if id works for LibraryRetrieval
org.cqframework.cql.elm.execution.Library executionLibrary = null;
try {
executionLibrary = tempLibraryLoader.load(vi);
} catch (Exception e) {
// log error
}
if (executionLibrary == null) {
Library library = (Library) jpaFhirDal.read(new IdType("Library", Canonicals.getIdPart(libraries.get(0))));
vi.setId(library.getName());
if (library.getVersion() != null) {
vi.setVersion(library.getVersion());
}
}
source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), vi.getId() + ".\"" + cql + "\"");
} else {
source = String.format("library LocalLibrary using FHIR version '" + fhirVersion + "' include FHIRHelpers version '" + fhirVersion + "' called FHIRHelpers %s parameter %s %s parameter \"%%context\" %s define Expression: %s", buildIncludes(tempLibraryLoader, jpaFhirDal, libraries, theRequest), instance.fhirType(), instance.fhirType(), instance.fhirType(), cql);
}
LibraryLoader libraryLoader = libraryLoaderFactory.create(new ArrayList<LibraryContentProvider>(Arrays.asList(jpaLibraryContentProviderFactory.create(theRequest), new InMemoryLibraryContentProvider(Arrays.asList(source)))));
// resolve execution context
return setupContext(instance, patientId, libraryLoader, theRequest);
}
Aggregations