Search in sources :

Example 26 with ActivityDefinition

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);
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) Resource(org.hl7.fhir.dstu3.model.Resource) Measure(org.hl7.fhir.dstu3.model.Measure) PlanDefinition(org.hl7.fhir.dstu3.model.PlanDefinition) Library(org.hl7.fhir.dstu3.model.Library) ActivityDefinition(org.hl7.fhir.dstu3.model.ActivityDefinition)

Example 27 with ActivityDefinition

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;
}
Also used : Reference(org.hl7.fhir.dstu3.model.Reference) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) URI(java.net.URI)

Example 28 with ActivityDefinition

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;
}
Also used : Resource(org.hl7.fhir.dstu3.model.Resource) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) ActivityDefinition(org.hl7.fhir.dstu3.model.ActivityDefinition)

Example 29 with ActivityDefinition

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);
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) Type(org.hl7.fhir.r4.model.Type) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) IdType(org.hl7.fhir.r4.model.IdType) ArrayList(java.util.ArrayList) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) Measure(org.hl7.fhir.r4.model.Measure) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) Library(org.hl7.fhir.r4.model.Library) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Example 30 with ActivityDefinition

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);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Aggregations

Reference (org.hl7.fhir.dstu3.model.Reference)8 Reference (org.hl7.fhir.r4.model.Reference)8 Resource (org.hl7.fhir.dstu3.model.Resource)6 ArrayList (java.util.ArrayList)5 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 RelatedArtifact (org.hl7.fhir.r4.model.RelatedArtifact)5 Resource (org.hl7.fhir.r4.model.Resource)5 ActivityDefinition (org.hl7.fhir.dstu3.model.ActivityDefinition)4 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)4 ActivityDefinition (org.hl7.fhir.r4.model.ActivityDefinition)4 Attachment (org.hl7.fhir.r4.model.Attachment)4 DomainResource (org.hl7.fhir.r4.model.DomainResource)4 IdType (org.hl7.fhir.dstu3.model.IdType)3 RelatedArtifact (org.hl7.fhir.dstu3.model.RelatedArtifact)3 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)3 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)3 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)2 IdDt (ca.uhn.fhir.model.primitive.IdDt)2 IOException (java.io.IOException)2 URI (java.net.URI)2