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;
}
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));
}
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);
}
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;
}
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;
}
Aggregations