use of org.hl7.fhir.r4.model.CarePlan in project synthea by synthetichealth.
the class FhirStu3 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle, containing the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR from
* @param stopTime Time the simulation ended
* @return FHIR Bundle containing the Person's health record.
*/
public static Bundle convertToFHIR(Person person, long stopTime) {
Bundle bundle = new Bundle();
if (TRANSACTION_BUNDLE) {
bundle.setType(BundleType.TRANSACTION);
} else {
bundle.setType(BundleType.COLLECTION);
}
BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Entry allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in stu3 don't support Attachments
if (observation.value instanceof Attachment) {
media(person, personEntry, bundle, encounterEntry, observation);
} else {
observation(person, personEntry, bundle, encounterEntry, observation);
}
}
for (Procedure procedure : encounter.procedures) {
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
for (Medication medication : encounter.medications) {
medication(person, personEntry, bundle, encounterEntry, medication);
}
for (HealthRecord.Entry immunization : encounter.immunizations) {
immunization(person, personEntry, bundle, encounterEntry, immunization);
}
for (Report report : encounter.reports) {
report(person, personEntry, bundle, encounterEntry, report);
}
for (CarePlan careplan : encounter.careplans) {
careplan(person, personEntry, bundle, encounterEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
for (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
// one claim per encounter
BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
}
return bundle;
}
use of org.hl7.fhir.r4.model.CarePlan 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();
}
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(Context context, PlanDefinition planDefinition, String patientId, RequestDetails theRequest) {
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(planDefinition.getAction(), context, patientId, requestGroupBuilder, new ArrayList<>(), theRequest);
CarePlanActivityBuilder carePlanActivityBuilder = new CarePlanActivityBuilder();
carePlanActivityBuilder.buildReferenceTarget(requestGroupBuilder.build());
carePlanBuilder.buildActivity(carePlanActivityBuilder.build());
return carePlanBuilder.build();
}
use of org.hl7.fhir.r4.model.CarePlan in project cqf-ruler by DBCG.
the class Session method resolveDefinition.
private Resource resolveDefinition(Session session, PlanDefinition.PlanDefinitionActionComponent action, RequestDetails theRequest) {
Resource result = null;
if (action.hasDefinition()) {
logger.debug("Resolving definition: {}", action.getDefinitionCanonicalType().getValue());
String definition = action.getDefinitionCanonicalType().getValue();
if (definition.contains(session.getPlanDefinition().fhirType())) {
IdType id = new IdType(definition);
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());
}
for (CanonicalType c : plan.getInstantiatesCanonical()) {
session.getCarePlanBuilder().buildInstantiatesCanonical(c.getValueAsString());
}
result = plan;
} catch (IOException e) {
e.printStackTrace();
logger.error("nested plan failed");
}
} else {
try {
if (action.getDefinitionCanonicalType().getValue().startsWith("#")) {
result = this.activityDefinitionApplyProvider.resolveActivityDefinition((ActivityDefinition) resolveContained(session.getPlanDefinition(), action.getDefinitionCanonicalType().getValue()), session.getPatientId(), session.getPractitionerId(), session.getOrganizationId(), theRequest);
} else {
result = this.activityDefinitionApplyProvider.apply(theRequest, new IdType(CanonicalHelper.getId(action.getDefinitionCanonicalType())), 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.getDefinitionCanonicalType().getId());
result.setId(UUID.randomUUID().toString());
}
} 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 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;
}
Aggregations