use of org.hl7.fhir.dstu3.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ExpressionEvaluation method getLibraryReferences.
private List<Reference> getLibraryReferences(DomainResource instance, JpaFhirDal jpaFhirDal, RequestDetails theRequest) {
List<Reference> references = new ArrayList<>();
if (instance.hasContained()) {
for (Resource resource : instance.getContained()) {
if (resource instanceof Library) {
resource.setId(resource.getIdElement().getIdPart().replace("#", ""));
jpaFhirDal.update((Library) resource);
// getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(),
// getLibraryLoader().toElmLibrary((Library) resource));
}
}
}
if (instance instanceof ActivityDefinition) {
references.addAll(((ActivityDefinition) instance).getLibrary());
} else if (instance instanceof PlanDefinition) {
references.addAll(((PlanDefinition) instance).getLibrary());
} else if (instance instanceof Measure) {
references.addAll(((Measure) instance).getLibrary());
}
for (Extension extension : instance.getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/cqif-library")) {
Type value = extension.getValue();
if (value instanceof Reference) {
references.add((Reference) value);
} else {
throw new RuntimeException("Library extension does not have a value of type reference");
}
}
return cleanReferences(references);
}
use of org.hl7.fhir.dstu3.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveProcedureRequest.
private ProcedureRequest resolveProcedureRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
// status, intent, code, and subject are required
ProcedureRequest procedureRequest = new ProcedureRequest();
procedureRequest.setStatus(ProcedureRequest.ProcedureRequestStatus.DRAFT);
procedureRequest.setIntent(ProcedureRequest.ProcedureRequestIntent.PROPOSAL);
String patientReferenceString = patientId;
URI patientIdAsUri = URI.create(patientReferenceString);
if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
patientReferenceString = "Patient/" + patientId;
}
procedureRequest.setSubject(new Reference(patientReferenceString));
if (practitionerId != null) {
procedureRequest.setRequester(new ProcedureRequest.ProcedureRequestRequesterComponent().setAgent(new Reference(practitionerId)));
} else if (organizationId != null) {
procedureRequest.setRequester(new ProcedureRequest.ProcedureRequestRequesterComponent().setAgent(new Reference(organizationId)));
}
if (activityDefinition.hasExtension()) {
procedureRequest.setExtension(activityDefinition.getExtension());
}
if (activityDefinition.hasCode()) {
procedureRequest.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()) {
procedureRequest.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 procedureRequest;
}
use of org.hl7.fhir.dstu3.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 "ProcedureRequest":
result = resolveProcedureRequest(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;
}
for (ActivityDefinition.ActivityDefinitionDynamicValueComponent dynamicValue : activityDefinition.getDynamicValue()) {
if (dynamicValue.getExpression() != null) {
Boolean aliasedExpression = null;
if (dynamicValue.hasLanguage()) {
String language = dynamicValue.getLanguage();
if (language.equals("text/cql.identifier") || language.equals("text/cql-identifier") || language.equals("text/cql.name") || language.equals("text/cql-name")) {
aliasedExpression = true;
} else {
aliasedExpression = false;
}
} else {
aliasedExpression = false;
}
/*
* 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(), aliasedExpression, patientId, theRequest);
// TODO need to verify type... yay
if (value instanceof Boolean) {
value = new BooleanType((Boolean) value);
}
this.modelResolver.setValue(result, dynamicValue.getPath(), value);
}
}
return result;
}
use of org.hl7.fhir.dstu3.model.ActivityDefinition in project cqf-ruler by DBCG.
the class ExpressionEvaluation method getLibraryReferences.
private List<CanonicalType> getLibraryReferences(DomainResource instance, RequestDetails theRequest) {
List<CanonicalType> references = new ArrayList<>();
if (instance.hasContained()) {
for (Resource resource : instance.getContained()) {
if (resource instanceof Library) {
resource.setId(resource.getIdElement().getIdPart().replace("#", ""));
this.jpaFhirDalFactory.create(theRequest).update((Library) resource);
// getLibraryLoader().putLibrary(resource.getIdElement().getIdPart(),
// getLibraryLoader().toElmLibrary((Library) resource));
}
}
}
if (instance instanceof ActivityDefinition) {
references.addAll(((ActivityDefinition) instance).getLibrary());
} else if (instance instanceof PlanDefinition) {
references.addAll(((PlanDefinition) instance).getLibrary());
} else if (instance instanceof Measure) {
references.addAll(((Measure) instance).getLibrary());
}
for (Extension extension : instance.getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/cqif-library")) {
Type value = extension.getValue();
if (value instanceof CanonicalType) {
references.add((CanonicalType) value);
} else {
throw new RuntimeException("Library extension does not have a value of type reference");
}
}
return cleanReferences(references);
}
use of org.hl7.fhir.dstu3.model.ActivityDefinition in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeActivityDefinitionActivityDefinitionParticipantComponent.
protected void composeActivityDefinitionActivityDefinitionParticipantComponent(Complex parent, String parentType, String name, ActivityDefinition.ActivityDefinitionParticipantComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "participant", name, element, index);
if (element.hasTypeElement())
composeEnum(t, "ActivityDefinition", "type", element.getTypeElement(), -1);
if (element.hasRole())
composeCodeableConcept(t, "ActivityDefinition", "role", element.getRole(), -1);
}
Aggregations