Search in sources :

Example 16 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.hasSubtitleElement())
        composeString(t, "ActivityDefinition", "subtitle", element.getSubtitleElement(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "ActivityDefinition", "status", element.getStatusElement(), -1);
    if (element.hasExperimentalElement())
        composeBoolean(t, "ActivityDefinition", "experimental", element.getExperimentalElement(), -1);
    if (element.hasSubject())
        composeType(t, "ActivityDefinition", "subject", element.getSubject(), -1);
    if (element.hasDateElement())
        composeDateTime(t, "ActivityDefinition", "date", element.getDateElement(), -1);
    if (element.hasPublisherElement())
        composeString(t, "ActivityDefinition", "publisher", element.getPublisherElement(), -1);
    for (int i = 0; i < element.getContact().size(); i++) composeContactDetail(t, "ActivityDefinition", "contact", element.getContact().get(i), i);
    if (element.hasDescriptionElement())
        composeMarkdown(t, "ActivityDefinition", "description", element.getDescriptionElement(), -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);
    if (element.hasPurposeElement())
        composeMarkdown(t, "ActivityDefinition", "purpose", element.getPurposeElement(), -1);
    if (element.hasUsageElement())
        composeString(t, "ActivityDefinition", "usage", element.getUsageElement(), -1);
    if (element.hasCopyrightElement())
        composeMarkdown(t, "ActivityDefinition", "copyright", element.getCopyrightElement(), -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.getTopic().size(); i++) composeCodeableConcept(t, "ActivityDefinition", "topic", element.getTopic().get(i), i);
    for (int i = 0; i < element.getAuthor().size(); i++) composeContactDetail(t, "ActivityDefinition", "author", element.getAuthor().get(i), i);
    for (int i = 0; i < element.getEditor().size(); i++) composeContactDetail(t, "ActivityDefinition", "editor", element.getEditor().get(i), i);
    for (int i = 0; i < element.getReviewer().size(); i++) composeContactDetail(t, "ActivityDefinition", "reviewer", element.getReviewer().get(i), i);
    for (int i = 0; i < element.getEndorser().size(); i++) composeContactDetail(t, "ActivityDefinition", "endorser", element.getEndorser().get(i), i);
    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++) composeCanonical(t, "ActivityDefinition", "library", element.getLibrary().get(i), i);
    if (element.hasKindElement())
        composeEnum(t, "ActivityDefinition", "kind", element.getKindElement(), -1);
    if (element.hasProfileElement())
        composeCanonical(t, "ActivityDefinition", "profile", element.getProfileElement(), -1);
    if (element.hasCode())
        composeCodeableConcept(t, "ActivityDefinition", "code", element.getCode(), -1);
    if (element.hasIntentElement())
        composeEnum(t, "ActivityDefinition", "intent", element.getIntentElement(), -1);
    if (element.hasPriorityElement())
        composeEnum(t, "ActivityDefinition", "priority", element.getPriorityElement(), -1);
    if (element.hasDoNotPerformElement())
        composeBoolean(t, "ActivityDefinition", "doNotPerform", element.getDoNotPerformElement(), -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);
    for (int i = 0; i < element.getSpecimenRequirement().size(); i++) composeReference(t, "ActivityDefinition", "specimenRequirement", element.getSpecimenRequirement().get(i), i);
    for (int i = 0; i < element.getObservationRequirement().size(); i++) composeReference(t, "ActivityDefinition", "observationRequirement", element.getObservationRequirement().get(i), i);
    for (int i = 0; i < element.getObservationResultRequirement().size(); i++) composeReference(t, "ActivityDefinition", "observationResultRequirement", element.getObservationResultRequirement().get(i), i);
    if (element.hasTransformElement())
        composeCanonical(t, "ActivityDefinition", "transform", element.getTransformElement(), -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.r4.utils.formats.Turtle.Complex)

Example 17 with ActivityDefinition

use of org.hl7.fhir.r4.model.ActivityDefinition in project org.hl7.fhir.core by hapifhir.

the class DataRenderer method isCanonical.

private boolean isCanonical(String path) {
    if (!path.endsWith(".url"))
        return false;
    String t = path.substring(0, path.length() - 4);
    StructureDefinition sd = getContext().getWorker().fetchTypeDefinition(t);
    if (sd == null)
        return false;
    if (Utilities.existsInList(t, VersionUtilities.getCanonicalResourceNames(getContext().getWorker().getVersion()))) {
        return true;
    }
    if (Utilities.existsInList(t, "ActivityDefinition", "CapabilityStatement", "CapabilityStatement2", "ChargeItemDefinition", "Citation", "CodeSystem", "CompartmentDefinition", "ConceptMap", "ConditionDefinition", "EventDefinition", "Evidence", "EvidenceReport", "EvidenceVariable", "ExampleScenario", "GraphDefinition", "ImplementationGuide", "Library", "Measure", "MessageDefinition", "NamingSystem", "PlanDefinition"))
        return true;
    return sd.getBaseDefinitionElement().hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-codegen-super");
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 18 with ActivityDefinition

use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProviderIT method testActivityDefinitionApply.

@Test
public void testActivityDefinitionApply() throws Exception {
    DomainResource activityDefinition = (DomainResource) activityDefinitions.get("opioidcds-risk-assessment-request");
    // Patient First
    Map<String, IBaseResource> resources = uploadTests("test/activitydefinition/Patient");
    IBaseResource patient = resources.get("ExamplePatient");
    Resource applyResult = activityDefinitionApplyProvider.apply(new SystemRequestDetails(), activityDefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
    assertTrue(applyResult instanceof ServiceRequest);
    assertEquals("454281000124100", ((ServiceRequest) applyResult).getCode().getCoding().get(0).getCode());
}
Also used : DomainResource(org.hl7.fhir.r4.model.DomainResource) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 19 with ActivityDefinition

use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.

the class Session method resolveActions.

private void resolveActions(RequestDetails theRequest, PlanDefinition planDefinition, List<PlanDefinition.PlanDefinitionActionComponent> actions, Context context, String patientId, RequestGroupBuilder requestGroupBuilder, List<RequestGroup.RequestGroupActionComponent> actionComponents) {
    for (PlanDefinition.PlanDefinitionActionComponent action : actions) {
        boolean conditionsMet = true;
        for (PlanDefinition.PlanDefinitionActionConditionComponent condition : action.getCondition()) {
            if (condition.getKind() == PlanDefinition.ActionConditionKind.APPLICABILITY) {
                if (!condition.hasExpression()) {
                    continue;
                }
                Boolean aliasedExpression = null;
                if (condition.hasLanguage()) {
                    String language = condition.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;
                }
                Object result = expressionEvaluation.evaluateInContext(planDefinition, condition.getExpression(), aliasedExpression, patientId, theRequest);
                if (!(result instanceof Boolean)) {
                    continue;
                }
                if (!(Boolean) result) {
                    conditionsMet = false;
                }
            }
            if (conditionsMet) {
                RequestGroupActionBuilder actionBuilder = new RequestGroupActionBuilder();
                if (action.hasTitle()) {
                    actionBuilder.buildTitle(action.getTitle());
                }
                if (action.hasDescription()) {
                    actionBuilder.buildDescripition(action.getDescription());
                }
                // source
                if (action.hasDocumentation()) {
                    RelatedArtifact artifact = action.getDocumentationFirstRep();
                    RelatedArtifactBuilder artifactBuilder = new RelatedArtifactBuilder();
                    if (artifact.hasDisplay()) {
                        artifactBuilder.buildDisplay(artifact.getDisplay());
                    }
                    if (artifact.hasUrl()) {
                        artifactBuilder.buildUrl(artifact.getUrl());
                    }
                    if (artifact.hasDocument() && artifact.getDocument().hasUrl()) {
                        AttachmentBuilder attachmentBuilder = new AttachmentBuilder();
                        attachmentBuilder.buildUrl(artifact.getDocument().getUrl());
                        artifactBuilder.buildDocument(attachmentBuilder.build());
                    }
                    actionBuilder.buildDocumentation(Collections.singletonList(artifactBuilder.build()));
                }
                // TODO - uuid
                if (action.hasLabel()) {
                    actionBuilder.buildLabel(action.getLabel());
                }
                if (action.hasType()) {
                    actionBuilder.buildType(action.getType());
                }
                if (action.hasDefinition()) {
                    if (action.getDefinition().getReferenceElement().getResourceType().equals("ActivityDefinition")) {
                        if (action.getDefinition().getResource() != null) {
                            ActivityDefinition activityDefinition = (ActivityDefinition) action.getDefinition().getResource();
                            ReferenceBuilder referenceBuilder = new ReferenceBuilder();
                            referenceBuilder.buildDisplay(activityDefinition.getDescription());
                            actionBuilder.buildResource(referenceBuilder.build());
                            if (activityDefinition.hasDescription()) {
                                actionBuilder.buildDescripition(activityDefinition.getDescription());
                            }
                        }
                        ActivityDefinition activityDefinition = this.activityDefinitionDao.read(action.getDefinition().getReferenceElement());
                        if (activityDefinition.hasDescription()) {
                            actionBuilder.buildDescripition(activityDefinition.getDescription());
                        }
                        try {
                            this.activityDefinitionApplyProvider.apply(theRequest, new IdType(action.getDefinition().getReferenceElement().getIdPart()), patientId, null, null, null, null, null, null, null, null).setId(UUID.randomUUID().toString());
                        } catch (FHIRException e) {
                            throw new RuntimeException("Error applying ActivityDefinition " + e.getMessage());
                        }
                        Parameters inParams = new Parameters();
                        inParams.addParameter().setName("patient").setValue(new StringType(patientId));
                        Parameters outParams = this.fhirContext.newRestfulGenericClient(theRequest.getFhirServerBase()).operation().onInstance(new IdDt("ActivityDefinition", action.getDefinition().getId())).named("$apply").withParameters(inParams).useHttpGet().execute();
                        List<Parameters.ParametersParameterComponent> response = outParams.getParameter();
                        Resource resource = response.get(0).getResource().setId(UUID.randomUUID().toString());
                        actionBuilder.buildResourceTarget(resource);
                        actionBuilder.buildResource(new ReferenceBuilder().buildReference(resource.getId()).build());
                    }
                }
                // on here...
                if (action.hasDynamicValue()) {
                    for (PlanDefinition.PlanDefinitionActionDynamicValueComponent dynamicValue : action.getDynamicValue()) {
                        if (dynamicValue.hasPath() && dynamicValue.hasExpression()) {
                            if (dynamicValue.getPath().endsWith("title")) {
                                // summary
                                String title = (String) context.resolveExpressionRef(dynamicValue.getExpression()).evaluate(context);
                                actionBuilder.buildTitle(title);
                            } else if (dynamicValue.getPath().endsWith("description")) {
                                // detail
                                String description = (String) context.resolveExpressionRef(dynamicValue.getExpression()).evaluate(context);
                                actionBuilder.buildDescripition(description);
                            } else if (dynamicValue.getPath().endsWith("extension")) {
                                // indicator
                                String extension = (String) context.resolveExpressionRef(dynamicValue.getExpression()).evaluate(context);
                                actionBuilder.buildExtension(extension);
                            }
                        }
                    }
                }
                if (!actionBuilder.build().isEmpty()) {
                    actionComponents.add(actionBuilder.build());
                }
                if (action.hasAction()) {
                    resolveActions(theRequest, planDefinition, action.getAction(), context, patientId, requestGroupBuilder, actionComponents);
                }
            }
        }
    }
    requestGroupBuilder.buildAction(new ArrayList<>(actionComponents));
}
Also used : Parameters(org.hl7.fhir.dstu3.model.Parameters) StringType(org.hl7.fhir.dstu3.model.StringType) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) Resource(org.hl7.fhir.dstu3.model.Resource) IdDt(ca.uhn.fhir.model.primitive.IdDt) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.dstu3.model.IdType) RequestGroupActionBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.RequestGroupActionBuilder) AttachmentBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.AttachmentBuilder) ReferenceBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.ReferenceBuilder) PlanDefinition(org.hl7.fhir.dstu3.model.PlanDefinition) RelatedArtifactBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.RelatedArtifactBuilder) ActivityDefinition(org.hl7.fhir.dstu3.model.ActivityDefinition)

Example 20 with ActivityDefinition

use of org.hl7.fhir.r4.model.ActivityDefinition in project cqf-ruler by DBCG.

the class ActivityDefinitionApplyProvider method resolveDiagnosticReport.

private DiagnosticReport resolveDiagnosticReport(ActivityDefinition activityDefinition, String patientId) {
    DiagnosticReport diagnosticReport = new DiagnosticReport();
    diagnosticReport.setStatus(DiagnosticReport.DiagnosticReportStatus.UNKNOWN);
    diagnosticReport.setSubject(new Reference(patientId));
    if (activityDefinition.hasCode()) {
        diagnosticReport.setCode(activityDefinition.getCode());
    } else {
        throw new ActivityDefinitionApplyException("Missing required ActivityDefinition.code property for DiagnosticReport");
    }
    if (activityDefinition.hasRelatedArtifact()) {
        List<Attachment> presentedFormAttachments = new ArrayList<>();
        for (RelatedArtifact artifact : activityDefinition.getRelatedArtifact()) {
            Attachment attachment = new Attachment();
            if (artifact.hasUrl()) {
                attachment.setUrl(artifact.getUrl());
            }
            if (artifact.hasDisplay()) {
                attachment.setTitle(artifact.getDisplay());
            }
            presentedFormAttachments.add(attachment);
        }
        diagnosticReport.setPresentedForm(presentedFormAttachments);
    }
    return diagnosticReport;
}
Also used : Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact)

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