Search in sources :

Example 11 with ActivityDefinition

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

Example 12 with ActivityDefinition

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;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) BooleanType(org.hl7.fhir.r4.model.BooleanType) DateTime(org.opencds.cqf.cql.engine.runtime.DateTime) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Example 13 with ActivityDefinition

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;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Communication(org.hl7.fhir.r4.model.Communication)

Example 14 with ActivityDefinition

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

Example 15 with ActivityDefinition

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);
}
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