Search in sources :

Example 1 with CarePlan

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

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

the class PlanDefinitionApplyProviderIT method testPlanDefinitionApplyFormerSmoker.

@Test
public void testPlanDefinitionApplyFormerSmoker() throws Exception {
    DomainResource plandefinition = (DomainResource) planDefinitions.get("lcs-cds-patient-view");
    // Patient First
    uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker/Patient");
    Map<String, IBaseResource> resources = uploadTests("test/plandefinition/LungCancerScreening/Former-Smoker");
    IBaseResource patient = resources.get("Former-Smoker");
    Object isFormerSmoker = planDefinitionApplyProvider.applyPlanDefinition(new SystemRequestDetails(), plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
    assertTrue(isFormerSmoker instanceof CarePlan);
}
Also used : CarePlan(org.hl7.fhir.r4.model.CarePlan) DomainResource(org.hl7.fhir.r4.model.DomainResource) SystemRequestDetails(ca.uhn.fhir.jpa.partition.SystemRequestDetails) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) RestIntegrationTest(org.opencds.cqf.ruler.test.RestIntegrationTest)

Example 3 with CarePlan

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

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

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

Test (org.junit.jupiter.api.Test)14 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)10 CarePlan (org.hl7.fhir.dstu3.model.CarePlan)8 Reference (org.hl7.fhir.dstu3.model.Reference)7 ArrayList (java.util.ArrayList)6 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)5 Reference (org.hl7.fhir.r4.model.Reference)4 Date (java.util.Date)3 Composition (org.hl7.fhir.dstu3.model.Composition)3 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)3 Encounter (org.hl7.fhir.dstu3.model.Encounter)3 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)3 CarePlan (org.hl7.fhir.r4.model.CarePlan)3 CarePlan (org.mitre.synthea.world.concepts.HealthRecord.CarePlan)3 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)2 Operation (ca.uhn.fhir.rest.annotation.Operation)2 JsonObject (com.google.gson.JsonObject)2 IOException (java.io.IOException)2 Bundle (org.hl7.fhir.dstu3.model.Bundle)2 BundleEntryComponent (org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent)2