Search in sources :

Example 11 with RequestGroup

use of org.hl7.fhir.dstu3.model.RequestGroup in project cqf-ruler by DBCG.

the class Session method resolveActions.

private CarePlan resolveActions(Session session, RequestDetails theRequest) {
    RequestGroup theRequestGroup = session.getRequestGroupBuilder().build();
    for (PlanDefinition.PlanDefinitionActionComponent action : session.getPlanDefinition().getAction()) {
        // TODO - Apply input/output dataRequirements?
        if (meetsConditions(session, action, theRequest)) {
            Resource result = resolveDefinition(session, action, theRequest);
            RequestGroupActionComponent currentActionTarget = null;
            if (result != null) {
                currentActionTarget = new RequestGroupActionBuilder().buildResource(new Reference("#" + result.getId())).build();
                session.getRequestGroupBuilder().buildContained(result).addAction(currentActionTarget);
            }
            resolveDynamicActions(session, action, currentActionTarget, theRequest);
        }
    }
    if (theRequestGroup.getId() == null) {
        theRequestGroup.setId(UUID.randomUUID().toString());
    }
    session.getCarePlanBuilder().buildContained(theRequestGroup).buildActivity(new CarePlanActivityBuilder().buildReference(new Reference("#" + theRequestGroup.getId())).build());
    return session.getCarePlan();
}
Also used : RequestGroupActionComponent(org.hl7.fhir.r4.model.RequestGroup.RequestGroupActionComponent) RequestGroupActionBuilder(org.opencds.cqf.ruler.cr.r4.builder.RequestGroupActionBuilder) RequestGroup(org.hl7.fhir.r4.model.RequestGroup) Reference(org.hl7.fhir.r4.model.Reference) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) CarePlanActivityBuilder(org.opencds.cqf.ruler.cr.r4.builder.CarePlanActivityBuilder)

Example 12 with RequestGroup

use of org.hl7.fhir.dstu3.model.RequestGroup in project cqf-ruler by DBCG.

the class STU3CarePlanToCdsCard 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.DSTU3).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.hasLabel()) {
                suggestions.setLabel(action.getLabel());
                hasSuggestions = true;
                if (action.hasDescription()) {
                    actions.setDescription(action.getDescription());
                }
                if (action.hasType() && !action.getType().getCode().equals("fire-event")) {
                    String code = action.getType().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.dstu3.model.Attachment) RelatedArtifact(org.hl7.fhir.dstu3.model.RelatedArtifact) Extension(org.hl7.fhir.dstu3.model.Extension) RequestGroup(org.hl7.fhir.dstu3.model.RequestGroup) IParser(ca.uhn.fhir.parser.IParser)

Example 13 with RequestGroup

use of org.hl7.fhir.dstu3.model.RequestGroup in project cqf-ruler by DBCG.

the class STU3CarePlanToCdsCard method convert.

public static List<CdsCard> convert(CarePlan carePlan) {
    List<CdsCard> cards = new ArrayList<>();
    for (CarePlan.CarePlanActivityComponent activity : carePlan.getActivity()) {
        if (activity.getReferenceTarget() != null && activity.getReferenceTarget() instanceof RequestGroup) {
            RequestGroup requestGroup = (RequestGroup) activity.getReferenceTarget();
            cards = convert(requestGroup);
        }
    }
    return cards;
}
Also used : CarePlan(org.hl7.fhir.dstu3.model.CarePlan) RequestGroup(org.hl7.fhir.dstu3.model.RequestGroup) ArrayList(java.util.ArrayList)

Example 14 with RequestGroup

use of org.hl7.fhir.dstu3.model.RequestGroup in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeRequestGroupRequestGroupActionComponent.

protected void composeRequestGroupRequestGroupActionComponent(Complex parent, String parentType, String name, RequestGroup.RequestGroupActionComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "action", name, element, index);
    if (element.hasLabelElement())
        composeString(t, "RequestGroup", "label", element.getLabelElement(), -1);
    if (element.hasTitleElement())
        composeString(t, "RequestGroup", "title", element.getTitleElement(), -1);
    if (element.hasDescriptionElement())
        composeString(t, "RequestGroup", "description", element.getDescriptionElement(), -1);
    if (element.hasTextEquivalentElement())
        composeString(t, "RequestGroup", "textEquivalent", element.getTextEquivalentElement(), -1);
    for (int i = 0; i < element.getCode().size(); i++) composeCodeableConcept(t, "RequestGroup", "code", element.getCode().get(i), i);
    for (int i = 0; i < element.getDocumentation().size(); i++) composeRelatedArtifact(t, "RequestGroup", "documentation", element.getDocumentation().get(i), i);
    for (int i = 0; i < element.getCondition().size(); i++) composeRequestGroupRequestGroupActionConditionComponent(t, "RequestGroup", "condition", element.getCondition().get(i), i);
    for (int i = 0; i < element.getRelatedAction().size(); i++) composeRequestGroupRequestGroupActionRelatedActionComponent(t, "RequestGroup", "relatedAction", element.getRelatedAction().get(i), i);
    if (element.hasTiming())
        composeType(t, "RequestGroup", "timing", element.getTiming(), -1);
    for (int i = 0; i < element.getParticipant().size(); i++) composeReference(t, "RequestGroup", "participant", element.getParticipant().get(i), i);
    if (element.hasType())
        composeCoding(t, "RequestGroup", "type", element.getType(), -1);
    if (element.hasGroupingBehaviorElement())
        composeEnum(t, "RequestGroup", "groupingBehavior", element.getGroupingBehaviorElement(), -1);
    if (element.hasSelectionBehaviorElement())
        composeEnum(t, "RequestGroup", "selectionBehavior", element.getSelectionBehaviorElement(), -1);
    if (element.hasRequiredBehaviorElement())
        composeEnum(t, "RequestGroup", "requiredBehavior", element.getRequiredBehaviorElement(), -1);
    if (element.hasPrecheckBehaviorElement())
        composeEnum(t, "RequestGroup", "precheckBehavior", element.getPrecheckBehaviorElement(), -1);
    if (element.hasCardinalityBehaviorElement())
        composeEnum(t, "RequestGroup", "cardinalityBehavior", element.getCardinalityBehaviorElement(), -1);
    if (element.hasResource())
        composeReference(t, "RequestGroup", "resource", element.getResource(), -1);
    for (int i = 0; i < element.getAction().size(); i++) composeRequestGroupRequestGroupActionComponent(t, "RequestGroup", "action", element.getAction().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 15 with RequestGroup

use of org.hl7.fhir.dstu3.model.RequestGroup in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeRequestGroup.

protected void composeRequestGroup(Complex parent, String parentType, String name, RequestGroup element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "RequestGroup", name, element, index);
    for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "RequestGroup", "identifier", element.getIdentifier().get(i), i);
    for (int i = 0; i < element.getInstantiatesCanonical().size(); i++) composeCanonical(t, "RequestGroup", "instantiatesCanonical", element.getInstantiatesCanonical().get(i), i);
    for (int i = 0; i < element.getInstantiatesUri().size(); i++) composeUri(t, "RequestGroup", "instantiatesUri", element.getInstantiatesUri().get(i), i);
    for (int i = 0; i < element.getBasedOn().size(); i++) composeReference(t, "RequestGroup", "basedOn", element.getBasedOn().get(i), i);
    for (int i = 0; i < element.getReplaces().size(); i++) composeReference(t, "RequestGroup", "replaces", element.getReplaces().get(i), i);
    if (element.hasGroupIdentifier())
        composeIdentifier(t, "RequestGroup", "groupIdentifier", element.getGroupIdentifier(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "RequestGroup", "status", element.getStatusElement(), -1);
    if (element.hasIntentElement())
        composeEnum(t, "RequestGroup", "intent", element.getIntentElement(), -1);
    if (element.hasPriorityElement())
        composeEnum(t, "RequestGroup", "priority", element.getPriorityElement(), -1);
    if (element.hasCode())
        composeCodeableConcept(t, "RequestGroup", "code", element.getCode(), -1);
    if (element.hasSubject())
        composeReference(t, "RequestGroup", "subject", element.getSubject(), -1);
    if (element.hasEncounter())
        composeReference(t, "RequestGroup", "encounter", element.getEncounter(), -1);
    if (element.hasAuthoredOnElement())
        composeDateTime(t, "RequestGroup", "authoredOn", element.getAuthoredOnElement(), -1);
    if (element.hasAuthor())
        composeReference(t, "RequestGroup", "author", element.getAuthor(), -1);
    for (int i = 0; i < element.getReasonCode().size(); i++) composeCodeableConcept(t, "RequestGroup", "reasonCode", element.getReasonCode().get(i), i);
    for (int i = 0; i < element.getReasonReference().size(); i++) composeReference(t, "RequestGroup", "reasonReference", element.getReasonReference().get(i), i);
    for (int i = 0; i < element.getNote().size(); i++) composeAnnotation(t, "RequestGroup", "note", element.getNote().get(i), i);
    for (int i = 0; i < element.getAction().size(); i++) composeRequestGroupRequestGroupActionComponent(t, "RequestGroup", "action", element.getAction().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Aggregations

ArrayList (java.util.ArrayList)4 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 RequestGroup (org.hl7.fhir.dstu3.model.RequestGroup)3 RequestGroup (org.hl7.fhir.r4.model.RequestGroup)3 IParser (ca.uhn.fhir.parser.IParser)2 Operation (ca.uhn.fhir.rest.annotation.Operation)2 CarePlan (org.hl7.fhir.dstu3.model.CarePlan)2 PlanDefinition (org.hl7.fhir.dstu3.model.PlanDefinition)2 Reference (org.hl7.fhir.dstu3.model.Reference)2 CarePlan (org.hl7.fhir.r4.model.CarePlan)2 PlanDefinition (org.hl7.fhir.r4.model.PlanDefinition)2 Reference (org.hl7.fhir.r4.model.Reference)2 Attachment (org.hl7.fhir.dstu3.model.Attachment)1 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)1 Extension (org.hl7.fhir.dstu3.model.Extension)1 RelatedArtifact (org.hl7.fhir.dstu3.model.RelatedArtifact)1 RequestGroupActionComponent (org.hl7.fhir.dstu3.model.RequestGroup.RequestGroupActionComponent)1 Resource (org.hl7.fhir.dstu3.model.Resource)1 Attachment (org.hl7.fhir.r4.model.Attachment)1