Search in sources :

Example 1 with RequestGroup

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

the class R4CarePlanToCdsCard 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.r4.model.CarePlan) RequestGroup(org.hl7.fhir.r4.model.RequestGroup) ArrayList(java.util.ArrayList)

Example 2 with RequestGroup

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

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

the class Session method applyPlanDefinition.

@Operation(name = "$apply", idempotent = true, type = PlanDefinition.class)
public CarePlan applyPlanDefinition(RequestDetails theRequest, @IdParam IdType theId, @OperationParam(name = "patient") String patientId, @OperationParam(name = "encounter") String encounterId, @OperationParam(name = "practitioner") String practitionerId, @OperationParam(name = "organization") String organizationId, @OperationParam(name = "userType") String userType, @OperationParam(name = "userLanguage") String userLanguage, @OperationParam(name = "userTaskContext") String userTaskContext, @OperationParam(name = "setting") String setting, @OperationParam(name = "settingContext") String settingContext) throws IOException, FHIRException {
    PlanDefinition planDefinition = this.planDefinitionDao.read(theId);
    if (planDefinition == null) {
        throw new IllegalArgumentException("Couldn't find PlanDefinition " + theId);
    }
    logger.info("Performing $apply operation on PlanDefinition/{}", theId);
    CarePlanBuilder builder = new CarePlanBuilder();
    builder.buildInstantiatesCanonical(planDefinition.getUrl()).buildSubject(new Reference(patientId)).buildStatus(CarePlan.CarePlanStatus.DRAFT);
    if (encounterId != null)
        builder.buildEncounter(new Reference(encounterId));
    if (practitionerId != null)
        builder.buildAuthor(new Reference(practitionerId));
    if (organizationId != null)
        builder.buildAuthor(new Reference(organizationId));
    if (userLanguage != null)
        builder.buildLanguage(userLanguage);
    // Each Group of actions shares a RequestGroup
    RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
    Session session = new Session(planDefinition, builder, patientId, encounterId, practitionerId, organizationId, userType, userLanguage, userTaskContext, setting, settingContext, requestGroupBuilder);
    return (CarePlan) ContainedHelper.liftContainedResourcesToParent(resolveActions(session, theRequest));
}
Also used : CarePlan(org.hl7.fhir.r4.model.CarePlan) CarePlanBuilder(org.opencds.cqf.ruler.cr.r4.builder.CarePlanBuilder) Reference(org.hl7.fhir.r4.model.Reference) RequestGroupBuilder(org.opencds.cqf.ruler.cr.r4.builder.RequestGroupBuilder) PlanDefinition(org.hl7.fhir.r4.model.PlanDefinition) Operation(ca.uhn.fhir.rest.annotation.Operation)

Example 4 with RequestGroup

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

the class Session method resolveActions.

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

Example 5 with RequestGroup

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

the class Session method applyPlanDefinition.

@Operation(name = "$apply", idempotent = true, type = PlanDefinition.class)
public CarePlan applyPlanDefinition(RequestDetails theRequest, @IdParam IdType theId, @OperationParam(name = "patient") String patientId, @OperationParam(name = "encounter") String encounterId, @OperationParam(name = "practitioner") String practitionerId, @OperationParam(name = "organization") String organizationId, @OperationParam(name = "userType") String userType, @OperationParam(name = "userLanguage") String userLanguage, @OperationParam(name = "userTaskContext") String userTaskContext, @OperationParam(name = "setting") String setting, @OperationParam(name = "settingContext") String settingContext) throws IOException, FHIRException {
    PlanDefinition planDefinition = this.planDefinitionDao.read(theId);
    if (planDefinition == null) {
        throw new IllegalArgumentException("Couldn't find PlanDefinition " + theId);
    }
    logger.info("Performing $apply operation on PlanDefinition/{}", theId);
    CarePlanBuilder builder = new CarePlanBuilder();
    builder.buildDefinition(new Reference(planDefinition.getIdElement().getIdPart())).buildSubject(new Reference(patientId)).buildStatus(CarePlan.CarePlanStatus.DRAFT);
    if (encounterId != null)
        builder.buildContext(new Reference(encounterId));
    if (practitionerId != null)
        builder.buildAuthor(new Reference(practitionerId));
    if (organizationId != null)
        builder.buildAuthor(new Reference(organizationId));
    if (userLanguage != null)
        builder.buildLanguage(userLanguage);
    // Each Group of actions shares a RequestGroup
    RequestGroupBuilder requestGroupBuilder = new RequestGroupBuilder().buildStatus().buildIntent();
    Session session = new Session(planDefinition, builder, patientId, encounterId, practitionerId, organizationId, userType, userLanguage, userTaskContext, setting, settingContext, requestGroupBuilder);
    return (CarePlan) ContainedHelper.liftContainedResourcesToParent(resolveActions(theRequest, session));
}
Also used : CarePlan(org.hl7.fhir.dstu3.model.CarePlan) CarePlanBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.CarePlanBuilder) Reference(org.hl7.fhir.dstu3.model.Reference) RequestGroupBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.RequestGroupBuilder) PlanDefinition(org.hl7.fhir.dstu3.model.PlanDefinition) Operation(ca.uhn.fhir.rest.annotation.Operation)

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