use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveProcedure.
private Procedure resolveProcedure(ActivityDefinition activityDefinition, String patientId) {
Procedure procedure = new Procedure();
// TODO - set the appropriate status
procedure.setStatus(Procedure.ProcedureStatus.UNKNOWN);
procedure.setSubject(new Reference(patientId));
if (activityDefinition.hasCode()) {
procedure.setCode(activityDefinition.getCode());
}
if (activityDefinition.hasBodySite()) {
procedure.setBodySite(activityDefinition.getBodySite());
}
return procedure;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveCommunicationRequest.
private CommunicationRequest resolveCommunicationRequest(ActivityDefinition activityDefinition, String patientId) {
CommunicationRequest communicationRequest = new CommunicationRequest();
communicationRequest.setStatus(CommunicationRequest.CommunicationRequestStatus.UNKNOWN);
communicationRequest.setSubject(new Reference(patientId));
// Unsure if this is correct - this is the way Motive is doing it...
if (activityDefinition.hasCode()) {
if (activityDefinition.getCode().hasText()) {
communicationRequest.addPayload().setContent(new StringType(activityDefinition.getCode().getText()));
}
}
if (activityDefinition.hasRelatedArtifact()) {
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
if (artifact.hasUrl()) {
Attachment attachment = new Attachment().setUrl(artifact.getUrl());
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
CommunicationRequest.CommunicationRequestPayloadComponent payload = new CommunicationRequest.CommunicationRequestPayloadComponent();
payload.setContent(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
communicationRequest.setPayload(Collections.singletonList(payload));
}
// TODO - other relatedArtifact types
}
}
return communicationRequest;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveMedicationRequest.
private MedicationRequest resolveMedicationRequest(ActivityDefinition activityDefinition, String patientId) throws ActivityDefinitionApplyException {
// intent, medication, and subject are required
MedicationRequest medicationRequest = new MedicationRequest();
medicationRequest.setIntent(MedicationRequest.MedicationRequestIntent.ORDER);
medicationRequest.setSubject(new Reference(patientId));
if (activityDefinition.hasProduct()) {
medicationRequest.setMedication(activityDefinition.getProduct());
} else {
throw new ActivityDefinitionApplyException("Missing required product property");
}
if (activityDefinition.hasDosage()) {
medicationRequest.setDosageInstruction(activityDefinition.getDosage());
}
if (activityDefinition.hasBodySite()) {
throw new ActivityDefinitionApplyException("BodySite does not map to " + activityDefinition.getKind());
}
if (activityDefinition.hasCode()) {
throw new ActivityDefinitionApplyException("Code does not map to " + activityDefinition.getKind());
}
if (activityDefinition.hasQuantity()) {
throw new ActivityDefinitionApplyException("Quantity does not map to " + activityDefinition.getKind());
}
return medicationRequest;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveTask.
private Task resolveTask(ActivityDefinition activityDefinition, String patientId) {
Task task = new Task();
task.setStatus(Task.TaskStatus.DRAFT);
task.setIntent(Task.TaskIntent.PROPOSAL);
task.setFor(new Reference(patientId));
Task.ParameterComponent input = new Task.ParameterComponent();
if (activityDefinition.hasCode()) {
task.setCode(activityDefinition.getCode());
input.setType(activityDefinition.getCode());
}
// Extension defined by CPG-on-FHIR for Questionnaire canonical URI
Extension collectsWith = activityDefinition.getExtensionByUrl("http://hl7.org/fhir/uv/cpg/StructureDefinition/cpg-collectWith");
if (collectsWith != null && collectsWith.getValueAsPrimitive().toString() != null) {
CanonicalType uri = new CanonicalType(collectsWith.getValueAsPrimitive().toString());
input.setValue(uri);
}
if (activityDefinition.hasRelatedArtifact()) {
for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
if (artifact.hasUrl()) {
Attachment attachment = new Attachment().setUrl(artifact.getUrl());
if (artifact.hasDisplay()) {
attachment.setTitle(artifact.getDisplay());
}
input.setValue(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
}
// TODO - other relatedArtifact types
}
}
// If input has been populated, then add it to the Task.
if (input.getType() != null || input.getValue() != null) {
task.addInput(input);
}
return task;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class Session method resolveDefinition.
private Resource resolveDefinition(Session session, PlanDefinition.PlanDefinitionActionComponent action, RequestDetails theRequest) {
Resource result = null;
if (action.hasDefinition()) {
logger.debug("Resolving definition: {}", action.getDefinitionCanonicalType().getValue());
String definition = action.getDefinitionCanonicalType().getValue();
if (definition.contains(session.getPlanDefinition().fhirType())) {
IdType id = new IdType(definition);
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());
}
for (CanonicalType c : plan.getInstantiatesCanonical()) {
session.getCarePlanBuilder().buildInstantiatesCanonical(c.getValueAsString());
}
result = plan;
} catch (IOException e) {
e.printStackTrace();
logger.error("nested plan failed");
}
} else {
try {
if (action.getDefinitionCanonicalType().getValue().startsWith("#")) {
result = this.activityDefinitionApplyProvider.resolveActivityDefinition((ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinitionCanonicalType().getValue()), session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest);
} else {
result = this.activityDefinitionApplyProvider.apply(theRequest, new IdType(CanonicalHelper.getId(action.getDefinitionCanonicalType())), 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.getDefinitionCanonicalType().getId());
result.setId(UUID.randomUUID().toString());
}
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition {} could not be applied and threw exception {}", action.getDefinition(), e.toString());
}
}
}
return result;
}
Aggregations