Search in sources :

Example 1 with RelatedArtifact

use of org.hl7.fhir.r5.model.RelatedArtifact in project kindling by HL7.

the class PageProcessor method rrHeader.

private String rrHeader(String mode) {
    StringBuilder b = new StringBuilder();
    b.append("<ul class=\"nav nav-tabs\">");
    b.append(makeHeaderTab("RelatedResource", "relatedartifact.html", mode == null || "base".equals(mode)));
    b.append(makeHeaderTab("Examples", "relatedartifact-examples.html", mode == null || "examples".equals(mode)));
    b.append(makeHeaderTab("Detailed Descriptions", "relatedartifact-definitions.html", mode == null || "definitions".equals(mode)));
    b.append(makeHeaderTab("Mappings", "relatedartifact-mappings.html", mode == null || "mappings".equals(mode)));
    b.append("</ul>\r\n");
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 2 with RelatedArtifact

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

the class R4CarePlanToCdsCard method convert.

private static List<CdsCard> convert(RequestGroup requestGroup) {
    List<CdsCard> cards = new ArrayList<>();
    // links
    List<CdsCard.Links> links = new ArrayList<>();
    if (requestGroup.hasExtension()) {
        for (Extension extension : requestGroup.getExtension()) {
            CdsCard.Links link = new CdsCard.Links();
            if (extension.getValue() instanceof Attachment) {
                Attachment attachment = (Attachment) extension.getValue();
                if (attachment.hasUrl()) {
                    link.setUrl(attachment.getUrl());
                }
                if (attachment.hasTitle()) {
                    link.setLabel(attachment.getTitle());
                }
                if (attachment.hasExtension()) {
                    link.setType(attachment.getExtensionFirstRep().getValue().primitiveValue());
                }
            } else {
                throw new RuntimeException("Invalid link extension type: " + extension.getValue().fhirType());
            }
            links.add(link);
        }
    }
    if (requestGroup.hasAction()) {
        for (RequestGroup.RequestGroupActionComponent action : requestGroup.getAction()) {
            IParser jsonParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser().setPrettyPrint(true);
            CdsCard card = new CdsCard(jsonParser);
            // basic
            if (action.hasTitle()) {
                card.setSummary(action.getTitle());
            }
            if (action.hasDescription()) {
                card.setDetail(action.getDescription());
            }
            if (action.hasExtension()) {
                card.setIndicator(action.getExtensionFirstRep().getValue().toString());
            }
            // source
            if (action.hasDocumentation()) {
                // Assuming first related artifact has everything
                RelatedArtifact documentation = action.getDocumentationFirstRep();
                CdsCard.Source source = new CdsCard.Source();
                if (documentation.hasDisplay()) {
                    source.setLabel(documentation.getDisplay());
                }
                if (documentation.hasUrl()) {
                    source.setUrl(documentation.getUrl());
                }
                if (documentation.hasDocument() && documentation.getDocument().hasUrl()) {
                    source.setIcon(documentation.getDocument().getUrl());
                }
                card.setSource(source);
            }
            if (action.hasSelectionBehavior()) {
                card.setSelectionBehavior(action.getSelectionBehavior().toCode());
            }
            // suggestions
            // TODO - uuid
            boolean hasSuggestions = false;
            CdsCard.Suggestions suggestions = new CdsCard.Suggestions();
            CdsCard.Suggestions.Action actions = new CdsCard.Suggestions.Action();
            if (action.hasPrefix()) {
                suggestions.setLabel(action.getPrefix());
                hasSuggestions = true;
                if (action.hasDescription()) {
                    actions.setDescription(action.getDescription());
                }
                if (action.hasType() && !action.getType().getCodingFirstRep().getCode().equals("fire-event")) {
                    String code = action.getType().getCodingFirstRep().getCode();
                    actions.setType(CdsCard.Suggestions.Action.ActionType.valueOf(code.equals("remove") ? "delete" : code));
                }
                if (action.hasResource()) {
                    if (actions.getType().name().equalsIgnoreCase("create")) {
                        action.getResourceTarget().setId((String) null);
                    }
                    actions.setResource(action.getResourceTarget());
                }
            }
            if (hasSuggestions) {
                suggestions.addAction(actions);
                card.addSuggestion(suggestions);
            }
            if (!links.isEmpty()) {
                card.setLinks(links);
            }
            cards.add(card);
        }
    }
    return cards;
}
Also used : ArrayList(java.util.ArrayList) Attachment(org.hl7.fhir.r4.model.Attachment) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) Extension(org.hl7.fhir.r4.model.Extension) RequestGroup(org.hl7.fhir.r4.model.RequestGroup) IParser(ca.uhn.fhir.parser.IParser)

Example 3 with RelatedArtifact

use of org.hl7.fhir.r5.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()) {
            // FHIR R4+, resource is defined as a canonical
            String resourceString = relatedArtifact.getResource();
            CanonicalParts parts = Canonicals.getParts(resourceString);
            if (parts.resourceType().equals("Library")) {
                Library lib = search(Library.class, Searches.byCanonical(resourceString), theRequestDetails).firstOrNull();
                if (lib != null) {
                    resources.putIfAbsent(lib.getId(), lib);
                    queue.add(lib);
                }
            }
        }
    }
}
Also used : Library(org.hl7.fhir.r4.model.Library) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) CanonicalParts(org.opencds.cqf.ruler.utility.CanonicalParts)

Example 4 with RelatedArtifact

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

the class Session method resolveActions.

private void resolveActions(List<PlanDefinition.PlanDefinitionActionComponent> actions, Context context, String patientId, RequestGroupBuilder requestGroupBuilder, List<RequestGroup.RequestGroupActionComponent> actionComponents, RequestDetails theRequest) {
    for (PlanDefinition.PlanDefinitionActionComponent action : actions) {
        boolean conditionsMet = true;
        for (PlanDefinition.PlanDefinitionActionConditionComponent condition : action.getCondition()) {
            if (condition.getKind() == PlanDefinition.ActionConditionKind.APPLICABILITY) {
                if (!condition.hasExpression()) {
                    continue;
                }
                if (condition.hasExpression() && !condition.getExpression().hasExpression()) {
                    continue;
                }
                Object result = context.resolveExpressionRef(condition.getExpression().getExpression()).getExpression().evaluate(context);
                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.hasPrefix()) {
                    actionBuilder.buildPrefix(action.getPrefix());
                }
                if (action.hasType()) {
                    actionBuilder.buildType(action.getType());
                }
                if (action.hasDefinition()) {
                    if (action.getDefinitionCanonicalType().getValue().contains("ActivityDefinition")) {
                        ActivityDefinition activityDefinition = this.activityDefinitionDao.read(new IdType("ActivityDefinition", action.getDefinitionCanonicalType().getId()));
                        if (activityDefinition.hasDescription()) {
                            actionBuilder.buildDescripition(activityDefinition.getDescription());
                        }
                        try {
                            this.activityDefinitionApplyProvider.apply(theRequest, new IdType(action.getDefinitionCanonicalType().getId()), 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().getExpression()).evaluate(context);
                                actionBuilder.buildTitle(title);
                            } else if (dynamicValue.getPath().endsWith("description")) {
                                // detail
                                String description = (String) context.resolveExpressionRef(dynamicValue.getExpression().getExpression()).evaluate(context);
                                actionBuilder.buildDescripition(description);
                            } else if (dynamicValue.getPath().endsWith("extension")) {
                                // indicator
                                String extension = (String) context.resolveExpressionRef(dynamicValue.getExpression().getExpression()).evaluate(context);
                                actionBuilder.buildExtension(extension);
                            }
                        }
                    }
                }
                if (!actionBuilder.build().isEmpty()) {
                    actionComponents.add(actionBuilder.build());
                }
                if (action.hasAction()) {
                    resolveActions(action.getAction(), context, patientId, requestGroupBuilder, actionComponents, theRequest);
                }
            }
        }
    }
    requestGroupBuilder.buildAction(new ArrayList<>(actionComponents));
}
Also used : Parameters(org.hl7.fhir.r4.model.Parameters) StringType(org.hl7.fhir.r4.model.StringType) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) IdDt(ca.uhn.fhir.model.primitive.IdDt) RelatedArtifact(org.hl7.fhir.r4.model.RelatedArtifact) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.r4.model.IdType) RequestGroupActionBuilder(org.opencds.cqf.ruler.cr.r4.builder.RequestGroupActionBuilder) AttachmentBuilder(org.opencds.cqf.ruler.cr.r4.builder.AttachmentBuilder) ReferenceBuilder(org.opencds.cqf.ruler.cr.r4.builder.ReferenceBuilder) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) RelatedArtifactBuilder(org.opencds.cqf.ruler.cr.r4.builder.RelatedArtifactBuilder) ActivityDefinition(org.hl7.fhir.r4.model.ActivityDefinition)

Example 5 with RelatedArtifact

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

the class Session method resolveCdsHooksPlanDefinition.

// For library use
public CarePlan resolveCdsHooksPlanDefinition(RequestDetails theRequest, Context context, PlanDefinition planDefinition, String patientId) {
    CarePlanBuilder carePlanBuilder = new CarePlanBuilder();
    RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
    // links
    if (planDefinition.hasRelatedArtifact()) {
        List<Extension> extensions = new ArrayList<>();
        for (RelatedArtifact relatedArtifact : planDefinition.getRelatedArtifact()) {
            AttachmentBuilder attachmentBuilder = new AttachmentBuilder();
            ExtensionBuilder extensionBuilder = new ExtensionBuilder();
            if (relatedArtifact.hasDisplay()) {
                // label
                attachmentBuilder.buildTitle(relatedArtifact.getDisplay());
            }
            if (relatedArtifact.hasUrl()) {
                // url
                attachmentBuilder.buildUrl(relatedArtifact.getUrl());
            }
            if (relatedArtifact.hasExtension()) {
                // type
                attachmentBuilder.buildExtension(relatedArtifact.getExtension());
            }
            extensionBuilder.buildUrl("http://example.org");
            extensionBuilder.buildValue(attachmentBuilder.build());
            extensions.add(extensionBuilder.build());
        }
        requestGroupBuilder.buildExtension(extensions);
    }
    resolveActions(theRequest, planDefinition, planDefinition.getAction(), context, patientId, requestGroupBuilder, new ArrayList<>());
    CarePlanActivityBuilder carePlanActivityBuilder = new CarePlanActivityBuilder();
    carePlanActivityBuilder.buildReferenceTarget(requestGroupBuilder.build());
    carePlanBuilder.buildActivity(carePlanActivityBuilder.build());
    return carePlanBuilder.build();
}
Also used : Extension(org.hl7.fhir.dstu3.model.Extension) AttachmentBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.AttachmentBuilder) CarePlanBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.CarePlanBuilder) RequestGroupBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.RequestGroupBuilder) ArrayList(java.util.ArrayList) ExtensionBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.ExtensionBuilder) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) CarePlanActivityBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.CarePlanActivityBuilder)

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