use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveServiceRequest.
private ServiceRequest resolveServiceRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
// status, intent, code, and subject are required
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.DRAFT);
serviceRequest.setIntent(ServiceRequest.ServiceRequestIntent.PROPOSAL);
String patientReferenceString = patientId;
URI patientIdAsUri = URI.create(patientReferenceString);
if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
patientReferenceString = "Patient/" + patientId;
}
serviceRequest.setSubject(new Reference(patientReferenceString));
if (practitionerId != null) {
serviceRequest.setRequester(new Reference(practitionerId));
} else if (organizationId != null) {
serviceRequest.setRequester(new Reference(organizationId));
}
if (activityDefinition.hasExtension()) {
serviceRequest.setExtension(activityDefinition.getExtension());
}
if (activityDefinition.hasCode()) {
serviceRequest.setCode(activityDefinition.getCode());
} else // code can be set as a dynamicValue
if (!activityDefinition.hasCode() && !activityDefinition.hasDynamicValue()) {
throw new ActivityDefinitionApplyException("Missing required code property");
}
if (activityDefinition.hasBodySite()) {
serviceRequest.setBodySite(activityDefinition.getBodySite());
}
if (activityDefinition.hasProduct()) {
throw new ActivityDefinitionApplyException("Product does not map to " + activityDefinition.getKind());
}
if (activityDefinition.hasDosage()) {
throw new ActivityDefinitionApplyException("Dosage does not map to " + activityDefinition.getKind());
}
return serviceRequest;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveActivityDefinition.
// For library use
public Resource resolveActivityDefinition(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId, RequestDetails theRequest) throws FHIRException {
Resource result = newResource(activityDefinition.getKind().toCode());
switch(result.fhirType()) {
case "ServiceRequest":
result = resolveServiceRequest(activityDefinition, patientId, practitionerId, organizationId);
break;
case "MedicationRequest":
result = resolveMedicationRequest(activityDefinition, patientId);
break;
case "SupplyRequest":
result = resolveSupplyRequest(activityDefinition, practitionerId, organizationId);
break;
case "Procedure":
result = resolveProcedure(activityDefinition, patientId);
break;
case "DiagnosticReport":
result = resolveDiagnosticReport(activityDefinition, patientId);
break;
case "Communication":
result = resolveCommunication(activityDefinition, patientId);
break;
case "CommunicationRequest":
result = resolveCommunicationRequest(activityDefinition, patientId);
break;
case "Task":
result = resolveTask(activityDefinition, patientId);
break;
}
for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
// ActivityDefinition apply operation does not fail.
try {
if (dynamicValue.getExpression() != null) {
// Special case for setting a Patient reference
if ("Patient".equals(dynamicValue.getExpression().getExpression())) {
this.modelResolver.setValue(result, dynamicValue.getPath(), new Reference(patientId));
} else {
/*
* TODO: Passing the activityDefinition as context here because that's what will
* have the libraries, but perhaps the "context" here should be the result
* resource?
*/
Object value = expressionEvaluation.evaluateInContext(activityDefinition, dynamicValue.getExpression().getExpression(), patientId, theRequest);
if (value != null) {
logger.debug("dynamicValue value: {}", value);
if (value instanceof Boolean) {
value = new BooleanType((Boolean) value);
} else if (value instanceof DateTime) {
value = Date.from(((DateTime) value).getDateTime().toInstant());
} else if (value instanceof String) {
value = new StringType((String) value);
}
this.modelResolver.setValue(result, dynamicValue.getPath(), value);
} else {
logger.warn("WARNING: ActivityDefinition has null value for path: {}", dynamicValue.getPath());
}
}
}
} catch (Exception e) {
logger.error("ERROR: ActivityDefinition dynamicValue {} could not be applied and threw exception {}", dynamicValue.getPath(), e.toString());
logger.error(e.toString());
}
}
return result;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveCommunication.
private Communication resolveCommunication(ActivityDefinition activityDefinition, String patientId) {
Communication communication = new Communication();
communication.setStatus(Communication.CommunicationStatus.UNKNOWN);
communication.setSubject(new Reference(patientId));
if (activityDefinition.hasCode()) {
communication.setReasonCode(Collections.singletonList(activityDefinition.getCode()));
}
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());
}
Communication.CommunicationPayloadComponent payload = new Communication.CommunicationPayloadComponent();
payload.setContent(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
communication.setPayload(Collections.singletonList(payload));
}
// TODO - other relatedArtifact types
}
}
return communication;
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeActivityDefinition.
protected void composeActivityDefinition(Complex parent, String parentType, String name, ActivityDefinition element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeDomainResource(t, "ActivityDefinition", name, element, index);
if (element.hasUrlElement())
composeUri(t, "ActivityDefinition", "url", element.getUrlElement(), -1);
for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "ActivityDefinition", "identifier", element.getIdentifier().get(i), i);
if (element.hasVersionElement())
composeString(t, "ActivityDefinition", "version", element.getVersionElement(), -1);
if (element.hasNameElement())
composeString(t, "ActivityDefinition", "name", element.getNameElement(), -1);
if (element.hasTitleElement())
composeString(t, "ActivityDefinition", "title", element.getTitleElement(), -1);
if (element.hasStatusElement())
composeEnum(t, "ActivityDefinition", "status", element.getStatusElement(), -1);
if (element.hasExperimentalElement())
composeBoolean(t, "ActivityDefinition", "experimental", element.getExperimentalElement(), -1);
if (element.hasDateElement())
composeDateTime(t, "ActivityDefinition", "date", element.getDateElement(), -1);
if (element.hasPublisherElement())
composeString(t, "ActivityDefinition", "publisher", element.getPublisherElement(), -1);
if (element.hasDescriptionElement())
composeMarkdown(t, "ActivityDefinition", "description", element.getDescriptionElement(), -1);
if (element.hasPurposeElement())
composeMarkdown(t, "ActivityDefinition", "purpose", element.getPurposeElement(), -1);
if (element.hasUsageElement())
composeString(t, "ActivityDefinition", "usage", element.getUsageElement(), -1);
if (element.hasApprovalDateElement())
composeDate(t, "ActivityDefinition", "approvalDate", element.getApprovalDateElement(), -1);
if (element.hasLastReviewDateElement())
composeDate(t, "ActivityDefinition", "lastReviewDate", element.getLastReviewDateElement(), -1);
if (element.hasEffectivePeriod())
composePeriod(t, "ActivityDefinition", "effectivePeriod", element.getEffectivePeriod(), -1);
for (int i = 0; i < element.getUseContext().size(); i++) composeUsageContext(t, "ActivityDefinition", "useContext", element.getUseContext().get(i), i);
for (int i = 0; i < element.getJurisdiction().size(); i++) composeCodeableConcept(t, "ActivityDefinition", "jurisdiction", element.getJurisdiction().get(i), i);
for (int i = 0; i < element.getTopic().size(); i++) composeCodeableConcept(t, "ActivityDefinition", "topic", element.getTopic().get(i), i);
for (int i = 0; i < element.getContributor().size(); i++) composeContributor(t, "ActivityDefinition", "contributor", element.getContributor().get(i), i);
for (int i = 0; i < element.getContact().size(); i++) composeContactDetail(t, "ActivityDefinition", "contact", element.getContact().get(i), i);
if (element.hasCopyrightElement())
composeMarkdown(t, "ActivityDefinition", "copyright", element.getCopyrightElement(), -1);
for (int i = 0; i < element.getRelatedArtifact().size(); i++) composeRelatedArtifact(t, "ActivityDefinition", "relatedArtifact", element.getRelatedArtifact().get(i), i);
for (int i = 0; i < element.getLibrary().size(); i++) composeReference(t, "ActivityDefinition", "library", element.getLibrary().get(i), i);
if (element.hasKindElement())
composeEnum(t, "ActivityDefinition", "kind", element.getKindElement(), -1);
if (element.hasCode())
composeCodeableConcept(t, "ActivityDefinition", "code", element.getCode(), -1);
if (element.hasTiming())
composeType(t, "ActivityDefinition", "timing", element.getTiming(), -1);
if (element.hasLocation())
composeReference(t, "ActivityDefinition", "location", element.getLocation(), -1);
for (int i = 0; i < element.getParticipant().size(); i++) composeActivityDefinitionActivityDefinitionParticipantComponent(t, "ActivityDefinition", "participant", element.getParticipant().get(i), i);
if (element.hasProduct())
composeType(t, "ActivityDefinition", "product", element.getProduct(), -1);
if (element.hasQuantity())
composeQuantity(t, "ActivityDefinition", "quantity", element.getQuantity(), -1);
for (int i = 0; i < element.getDosage().size(); i++) composeDosage(t, "ActivityDefinition", "dosage", element.getDosage().get(i), i);
for (int i = 0; i < element.getBodySite().size(); i++) composeCodeableConcept(t, "ActivityDefinition", "bodySite", element.getBodySite().get(i), i);
if (element.hasTransform())
composeReference(t, "ActivityDefinition", "transform", element.getTransform(), -1);
for (int i = 0; i < element.getDynamicValue().size(); i++) composeActivityDefinitionActivityDefinitionDynamicValueComponent(t, "ActivityDefinition", "dynamicValue", element.getDynamicValue().get(i), i);
}
use of org.hl7.fhir.r4.model.ActivityDefinition in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeActivityDefinitionActivityDefinitionDynamicValueComponent.
protected void composeActivityDefinitionActivityDefinitionDynamicValueComponent(Complex parent, String parentType, String name, ActivityDefinition.ActivityDefinitionDynamicValueComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "dynamicValue", name, element, index);
if (element.hasDescriptionElement())
composeString(t, "ActivityDefinition", "description", element.getDescriptionElement(), -1);
if (element.hasPathElement())
composeString(t, "ActivityDefinition", "path", element.getPathElement(), -1);
if (element.hasLanguageElement())
composeString(t, "ActivityDefinition", "language", element.getLanguageElement(), -1);
if (element.hasExpressionElement())
composeString(t, "ActivityDefinition", "expression", element.getExpressionElement(), -1);
}
Aggregations