Search in sources :

Example 6 with CarePlan

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

the class Session method resolveDefinition.

private Resource resolveDefinition(RequestDetails theRequest, Session session, PlanDefinition.PlanDefinitionActionComponent action) {
    Resource result = null;
    if (action.hasDefinition()) {
        logger.debug("Resolving definition: {}", action.getDefinition().getReference());
        Reference definition = action.getDefinition();
        if (definition.getId().contains(session.getPlanDefinition().fhirType())) {
            IdType id = new IdType(definition.getId());
            CarePlan plan;
            try {
                plan = applyPlanDefinition(theRequest, id, session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), session.getUserType(), session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
                if (plan.getId() == null) {
                    plan.setId(UUID.randomUUID().toString());
                }
                // Add an action to the request group which points to this CarePlan
                session.getRequestGroupBuilder().buildContained(plan).addAction(new RequestGroupActionBuilder().buildResource(new Reference("#" + plan.getId())).build());
                for (Reference r : plan.getDefinition()) {
                    session.getCarePlanBuilder().buildDefinition(r);
                }
                result = plan;
            } catch (IOException e) {
                e.printStackTrace();
                logger.error("nested plan failed");
            }
        } else {
            try {
                if (action.getDefinition().getReferenceElement().getIdPart().startsWith("#")) {
                    result = this.activityDefinitionApplyProvider.resolveActivityDefinition((ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinition().getReferenceElement().getIdPart()), session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest);
                } else {
                    result = this.activityDefinitionApplyProvider.apply(theRequest, new IdType(action.getDefinition().getReferenceElement().getIdPart()), session.getPatientId(), session.getEncounterId(), session.getPractitionerId(), session.getOrganizationId(), null, session.getUserLanguage(), session.getUserTaskContext(), session.getSetting(), session.getSettingContext());
                }
                if (result.getId() == null) {
                    logger.warn("ActivityDefinition {} returned resource with no id, setting one", action.getDefinition().getReferenceElement().getIdPart());
                    result.setId(UUID.randomUUID().toString());
                }
                session.getRequestGroupBuilder().buildContained(result).addAction(new RequestGroupActionBuilder().buildResource(new Reference("#" + result.getId())).build());
            } catch (Exception e) {
                logger.error("ERROR: ActivityDefinition {} could not be applied and threw exception {}", action.getDefinition(), e.toString());
            }
        }
    }
    return result;
}
Also used : RequestGroupActionBuilder(org.opencds.cqf.ruler.cr.dstu3.builder.RequestGroupActionBuilder) CarePlan(org.hl7.fhir.dstu3.model.CarePlan) Reference(org.hl7.fhir.dstu3.model.Reference) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) Resource(org.hl7.fhir.dstu3.model.Resource) IOException(java.io.IOException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.dstu3.model.IdType) ActivityDefinition(org.hl7.fhir.dstu3.model.ActivityDefinition)

Example 7 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.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)

Example 8 with CarePlan

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

the class PlanDefinitionApplyProviderIT method testPlanDefinitionApplyRec10NoScreenings.

@Test
public void testPlanDefinitionApplyRec10NoScreenings() throws Exception {
    DomainResource plandefinition = (DomainResource) planDefinitions.get("opioidcds-10");
    // Patient First
    uploadTests("test/plandefinition/Rec10/Patient");
    Map<String, IBaseResource> resources = uploadTests("test/plandefinition/Rec10");
    IBaseResource patient = resources.get("example-rec-10-no-screenings");
    Object recommendation = planDefinitionApplyProvider.applyPlanDefinition(new SystemRequestDetails(), plandefinition.getIdElement(), patient.getIdElement().getIdPart(), null, null, null, null, null, null, null, null);
    assertTrue(recommendation instanceof CarePlan);
}
Also used : CarePlan(org.hl7.fhir.dstu3.model.CarePlan) DomainResource(org.hl7.fhir.dstu3.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 9 with CarePlan

use of org.hl7.fhir.r4.model.CarePlan in project integration-adaptor-111 by nhsconnect.

the class CompositionMapper method mapComposition.

public Composition mapComposition(POCDMT000002UK01ClinicalDocument1 clinicalDocument, Encounter encounter, List<CarePlan> carePlans, List<QuestionnaireResponse> questionnaireResponseList, ReferralRequest referralRequest, List<PractitionerRole> practitionerRoles) {
    Composition composition = new Composition();
    composition.setIdElement(resourceUtil.newRandomUuid());
    Identifier docIdentifier = new Identifier();
    docIdentifier.setUse(USUAL);
    docIdentifier.setValue(clinicalDocument.getSetId().getRoot());
    composition.setTitle(COMPOSITION_TITLE).setType(createCodeableConcept()).setStatus(FINAL).setEncounter(resourceUtil.createReference(encounter)).setSubject(encounter.getSubject()).setDateElement(DateUtil.parse(clinicalDocument.getEffectiveTime().getValue())).setIdentifier(docIdentifier);
    if (clinicalDocument.getConfidentialityCode().isSetCode()) {
        composition.setConfidentiality(Composition.DocumentConfidentiality.valueOf(clinicalDocument.getConfidentialityCode().getCode()));
    }
    if (isNotEmpty(clinicalDocument.getRelatedDocumentArray()) && clinicalDocument.getRelatedDocumentArray(0).getParentDocument().getIdArray(0).isSetRoot()) {
        Identifier relatedDocIdentifier = new Identifier();
        relatedDocIdentifier.setUse(USUAL);
        relatedDocIdentifier.setValue(clinicalDocument.getRelatedDocumentArray(0).getParentDocument().getIdArray(0).getRoot());
        composition.addRelatesTo().setCode(Composition.DocumentRelationshipType.REPLACES).setTarget(relatedDocIdentifier);
    }
    practitionerRoles.stream().forEach(it -> composition.addAuthor(it.getPractitioner()));
    if (clinicalDocument.getComponent().isSetStructuredBody()) {
        for (POCDMT000002UK01Component3 component3 : clinicalDocument.getComponent().getStructuredBody().getComponentArray()) {
            SectionComponent sectionComponent = new SectionComponent();
            addSectionChildren(sectionComponent, component3.getSection());
            composition.addSection(sectionComponent);
        }
    }
    for (CarePlan carePlan : carePlans) {
        composition.addSection(buildSectionComponentFromResource(carePlan));
    }
    if (!referralRequest.isEmpty()) {
        composition.addSection(buildSectionComponentFromResource(referralRequest));
    }
    if (questionnaireResponseList != null) {
        addPathwaysToSection(composition, questionnaireResponseList);
    }
    return composition;
}
Also used : Composition(org.hl7.fhir.dstu3.model.Composition) CarePlan(org.hl7.fhir.dstu3.model.CarePlan) Identifier(org.hl7.fhir.dstu3.model.Identifier) POCDMT000002UK01Component3(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Component3) SectionComponent(org.hl7.fhir.dstu3.model.Composition.SectionComponent)

Example 10 with CarePlan

use of org.hl7.fhir.r4.model.CarePlan in project integration-adaptor-111 by nhsconnect.

the class CarePlanMapper method createCarePlanFromSection.

public CarePlan createCarePlanFromSection(POCDMT000002UK01Section cpSection, Encounter encounter, Condition condition) {
    CarePlan carePlan = new CarePlan();
    carePlan.setIdElement(resourceUtil.newRandomUuid());
    carePlan.setIntent(PLAN).setSubject(encounter.getSubject()).setSubjectTarget(encounter.getSubjectTarget()).setStatus(COMPLETED).setContextTarget(encounter).setContext(resourceUtil.createReference(encounter)).setPeriod(encounter.getPeriod()).addAddresses(resourceUtil.createReference(condition));
    if (cpSection.isSetLanguageCode()) {
        carePlan.setLanguage(nodeUtil.getNodeValueString(cpSection.getLanguageCode()));
    }
    if (cpSection.isSetTitle()) {
        carePlan.setTitle(nodeUtil.getNodeValueString(cpSection.getTitle()));
    }
    if (cpSection.getText().sizeOfContentArray() > 0) {
        String cpTextContent = nodeUtil.getNodeValueString(cpSection.getText().getContentArray(0));
        carePlan.setDescription(cpTextContent);
    }
    if (encounter.hasLocation()) {
        List<Reference> authorList = new ArrayList<>();
        for (Encounter.EncounterLocationComponent author : encounter.getLocation()) {
            if (author.hasLocation()) {
                Location location = (Location) author.getLocation().getResource();
                if (location.hasManagingOrganization()) {
                    authorList.add(location.getManagingOrganization());
                }
            }
        }
        carePlan.setAuthor(authorList);
    }
    return carePlan;
}
Also used : CarePlan(org.hl7.fhir.dstu3.model.CarePlan) Reference(org.hl7.fhir.dstu3.model.Reference) ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.dstu3.model.Encounter) Location(org.hl7.fhir.dstu3.model.Location)

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