Search in sources :

Example 26 with RelatedArtifact

use of org.hl7.fhir.r4.model.RelatedArtifact in project clinical_quality_language by cqframework.

the class DataRequirementsProcessorTest method TestLibraryDataRequirements.

@Test
public void TestLibraryDataRequirements() {
    CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
    cqlTranslatorOptions.getFormats().add(CqlTranslator.Format.JSON);
    try {
        // CqlTranslator translator = createTranslator("/ecqm/resources/library-EXM506-2.2.000.json", cqlTranslatorOptions);
        CqlTranslator translator = createTranslator("CompositeMeasures/cql/BCSComponent.cql", cqlTranslatorOptions);
        translator.toELM();
        assertTrue(translator.getErrors().isEmpty());
        libraryManager.cacheLibrary(translator.getTranslatedLibrary());
        DataRequirementsProcessor dqReqTrans = new DataRequirementsProcessor();
        org.hl7.fhir.r5.model.Library moduleDefinitionLibrary = dqReqTrans.gatherDataRequirements(libraryManager, translator.getTranslatedLibrary(), cqlTranslatorOptions, null, false);
        assertTrue(moduleDefinitionLibrary.getType().getCode("http://terminology.hl7.org/CodeSystem/library-type").equalsIgnoreCase("module-definition"));
        List<Extension> directReferenceCodes = moduleDefinitionLibrary.getExtensionsByUrl("http://hl7.org/fhir/us/cqfmeasures/StructureDefinition/cqfm-directReferenceCode");
        assertTrue(directReferenceCodes.size() == 5);
        Extension directReferenceCode = directReferenceCodes.get(0);
        Coding coding = directReferenceCode.getValueCoding();
        assertEquals("http://loinc.org", coding.getSystem());
        assertEquals("21112-8", coding.getCode());
        assertEquals("Birth date", coding.getDisplay());
        assertTrue(moduleDefinitionLibrary.getRelatedArtifact().size() >= 45);
        RelatedArtifact loincCodeSystem = null;
        for (RelatedArtifact relatedArtifact : moduleDefinitionLibrary.getRelatedArtifact()) {
            if (relatedArtifact.getType() == RelatedArtifact.RelatedArtifactType.DEPENDSON && relatedArtifact.getResource() != null && relatedArtifact.getResource().equals("http://loinc.org")) {
                loincCodeSystem = relatedArtifact;
                break;
            }
        }
        assertTrue(loincCodeSystem != null);
        assertTrue(moduleDefinitionLibrary.getParameter().size() >= 16);
        ParameterDefinition measurementPeriod = null;
        for (ParameterDefinition parameter : moduleDefinitionLibrary.getParameter()) {
            if (parameter.getName().equals("Measurement Period")) {
                measurementPeriod = parameter;
                break;
            }
        }
        assertTrue(measurementPeriod != null);
        assertTrue(moduleDefinitionLibrary.getDataRequirement().size() >= 15);
        DataRequirement diagnosisRequirement = null;
        for (DataRequirement requirement : moduleDefinitionLibrary.getDataRequirement()) {
            if (requirement.getType() == Enumerations.FHIRAllTypes.CONDITION && requirement.getCodeFilter().size() == 1) {
                DataRequirement.DataRequirementCodeFilterComponent cfc = requirement.getCodeFilterFirstRep();
                if (cfc.hasPath() && cfc.getPath().equals("code") && cfc.hasValueSet() && cfc.getValueSet().equals("http://cts.nlm.nih.gov/fhir/ValueSet/2.16.840.1.113883.3.464.1003.198.12.1071")) {
                    diagnosisRequirement = requirement;
                    break;
                }
            }
        }
        assertTrue(diagnosisRequirement != null);
        FhirContext context = getFhirContext();
        IParser parser = context.newJsonParser();
        String moduleDefString = parser.setPrettyPrint(true).encodeResourceToString(moduleDefinitionLibrary);
        logger.debug(moduleDefString);
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) IOException(java.io.IOException) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) IParser(ca.uhn.fhir.parser.IParser) Test(org.testng.annotations.Test)

Example 27 with RelatedArtifact

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

the class DataOperationsProvider method visitLibrary.

private void visitLibrary(Library library, List<Library> queue, Map<String, Library> resources, RequestDetails theRequestDetails) {
    for (RelatedArtifact relatedArtifact : library.getRelatedArtifact()) {
        if (relatedArtifact.getType().equals(RelatedArtifact.RelatedArtifactType.DEPENDSON) && relatedArtifact.hasResource()) {
            IdType id = Ids.newId(Library.class, relatedArtifact.getResource().getReference());
            Library lib = search(Library.class, Searches.byId(id), theRequestDetails).firstOrNull();
            if (lib != null) {
                resources.putIfAbsent(lib.getId(), lib);
                queue.add(lib);
            }
        }
    }
}
Also used : Library(org.hl7.fhir.dstu3.model.Library) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 28 with RelatedArtifact

use of org.hl7.fhir.r4.model.RelatedArtifact 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 29 with RelatedArtifact

use of org.hl7.fhir.r4.model.RelatedArtifact 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)

Example 30 with RelatedArtifact

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

the class ActivityDefinitionApplyProvider method resolveCommunicationRequest.

private CommunicationRequest resolveCommunicationRequest(ActivityDefinition activityDefinition, String patientId) {
    CommunicationRequest communicationRequest = new CommunicationRequest();
    communicationRequest.setStatus(CommunicationRequest.CommunicationRequestStatus.UNKNOWN);
    communicationRequest.setSubject(new Reference(patientId));
    // Unsure if this is correct - this is the way Motive is doing it...
    if (activityDefinition.hasCode()) {
        if (activityDefinition.getCode().hasText()) {
            communicationRequest.addPayload().setContent(new StringType(activityDefinition.getCode().getText()));
        }
    }
    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());
                }
                CommunicationRequest.CommunicationRequestPayloadComponent payload = new CommunicationRequest.CommunicationRequestPayloadComponent();
                payload.setContent(artifact.hasDisplay() ? attachment.setTitle(artifact.getDisplay()) : attachment);
                communicationRequest.setPayload(Collections.singletonList(payload));
            }
        // TODO - other relatedArtifact types
        }
    }
    return communicationRequest;
}
Also used : StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) CommunicationRequest(org.hl7.fhir.r4.model.CommunicationRequest)

Aggregations

RelatedArtifact (org.hl7.fhir.r4.model.RelatedArtifact)13 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13 ArrayList (java.util.ArrayList)7 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)7 RelatedArtifact (org.hl7.fhir.dstu3.model.RelatedArtifact)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 Attachment (org.hl7.fhir.r4.model.Attachment)5 IParser (ca.uhn.fhir.parser.IParser)4 Extension (org.hl7.fhir.r4.model.Extension)4 Library (org.hl7.fhir.r4.model.Library)4 RelatedArtifact (org.hl7.fhir.r5.model.RelatedArtifact)4 Attachment (org.hl7.fhir.dstu3.model.Attachment)3 Reference (org.hl7.fhir.r4.model.Reference)3 FhirContext (ca.uhn.fhir.context.FhirContext)2 IdDt (ca.uhn.fhir.model.primitive.IdDt)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FhirServerConfig (com.ibm.cohort.fhir.client.config.FhirServerConfig)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileWriter (java.io.FileWriter)2