use of org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent in project synthea by synthetichealth.
the class FhirR4 method carePlan.
/**
* Map the given CarePlan to a FHIR CarePlan resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the CarePlan to
* @param encounterEntry Current Encounter entry
* @param provider The current provider
* @param carePlan The CarePlan to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent carePlan(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Provider provider, BundleEntryComponent careTeamEntry, CarePlan carePlan) {
org.hl7.fhir.r4.model.CarePlan careplanResource = new org.hl7.fhir.r4.model.CarePlan();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-careplan");
careplanResource.setMeta(meta);
careplanResource.addCategory(mapCodeToCodeableConcept(new Code("http://hl7.org/fhir/us/core/CodeSystem/careplan-category", "assess-plan", null), null));
}
String narrative = "Care Plan for ";
careplanResource.setIntent(CarePlanIntent.ORDER);
careplanResource.setSubject(new Reference(personEntry.getFullUrl()));
careplanResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
careplanResource.addCareTeam(new Reference(careTeamEntry.getFullUrl()));
Code code = carePlan.codes.get(0);
careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
narrative += code.display + ".";
CarePlanActivityStatus activityStatus;
CodeableConcept goalStatus = new CodeableConcept();
goalStatus.getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/goal-achievement");
Period period = new Period().setStart(new Date(carePlan.start));
careplanResource.setPeriod(period);
if (carePlan.stop != 0L) {
period.setEnd(new Date(carePlan.stop));
careplanResource.setStatus(CarePlanStatus.COMPLETED);
activityStatus = CarePlanActivityStatus.COMPLETED;
goalStatus.getCodingFirstRep().setCode("achieved");
} else {
careplanResource.setStatus(CarePlanStatus.ACTIVE);
activityStatus = CarePlanActivityStatus.INPROGRESS;
goalStatus.getCodingFirstRep().setCode("in-progress");
}
if (!carePlan.activities.isEmpty()) {
narrative += "<br/>Activities: <ul>";
String locationUrl = findLocationUrl(provider, bundle);
for (Code activity : carePlan.activities) {
narrative += "<li>" + code.display + "</li>";
CarePlanActivityComponent activityComponent = new CarePlanActivityComponent();
CarePlanActivityDetailComponent activityDetailComponent = new CarePlanActivityDetailComponent();
activityDetailComponent.setStatus(activityStatus);
activityDetailComponent.setLocation(new Reference().setReference(locationUrl).setDisplay(provider.name));
activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
activityComponent.setDetail(activityDetailComponent);
careplanResource.addActivity(activityComponent);
}
narrative += "</ul>";
}
if (!carePlan.reasons.isEmpty()) {
// Only one element in list
Code reason = carePlan.reasons.get(0);
narrative += "<br/>Care plan is meant to treat " + reason.display + ".";
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
careplanResource.addAddresses().setReference(entry.getFullUrl());
}
}
}
}
for (JsonObject goal : carePlan.goals) {
BundleEntryComponent goalEntry = careGoal(rand, bundle, personEntry, carePlan.start, goalStatus, goal);
careplanResource.addGoal().setReference(goalEntry.getFullUrl());
}
careplanResource.setText(new Narrative().setStatus(NarrativeStatus.GENERATED).setDiv(new XhtmlNode(NodeType.Element).setValue(narrative)));
return newEntry(rand, bundle, careplanResource);
}
use of org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent in project synthea by synthetichealth.
the class FhirStu3 method careplan.
/**
* Map the given CarePlan to a FHIR CarePlan resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the CarePlan to
* @param encounterEntry Current Encounter entry
* @param carePlan The CarePlan to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent careplan(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, CarePlan carePlan) {
org.hl7.fhir.dstu3.model.CarePlan careplanResource = new org.hl7.fhir.dstu3.model.CarePlan();
careplanResource.setIntent(CarePlanIntent.ORDER);
careplanResource.setSubject(new Reference(personEntry.getFullUrl()));
careplanResource.setContext(new Reference(encounterEntry.getFullUrl()));
Code code = carePlan.codes.get(0);
careplanResource.addCategory(mapCodeToCodeableConcept(code, SNOMED_URI));
CarePlanActivityStatus activityStatus;
GoalStatus goalStatus;
Period period = new Period().setStart(new Date(carePlan.start));
careplanResource.setPeriod(period);
if (carePlan.stop != 0L) {
period.setEnd(new Date(carePlan.stop));
careplanResource.setStatus(CarePlanStatus.COMPLETED);
activityStatus = CarePlanActivityStatus.COMPLETED;
goalStatus = GoalStatus.ACHIEVED;
} else {
careplanResource.setStatus(CarePlanStatus.ACTIVE);
activityStatus = CarePlanActivityStatus.INPROGRESS;
goalStatus = GoalStatus.INPROGRESS;
}
if (!carePlan.activities.isEmpty()) {
for (Code activity : carePlan.activities) {
CarePlanActivityComponent activityComponent = new CarePlanActivityComponent();
CarePlanActivityDetailComponent activityDetailComponent = new CarePlanActivityDetailComponent();
activityDetailComponent.setStatus(activityStatus);
activityDetailComponent.setCode(mapCodeToCodeableConcept(activity, SNOMED_URI));
activityComponent.setDetail(activityDetailComponent);
careplanResource.addActivity(activityComponent);
}
}
if (!carePlan.reasons.isEmpty()) {
// Only one element in list
Code reason = carePlan.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
careplanResource.addAddresses().setReference(entry.getFullUrl());
}
}
}
}
for (JsonObject goal : carePlan.goals) {
BundleEntryComponent goalEntry = caregoal(rand, bundle, goalStatus, goal);
careplanResource.addGoal().setReference(goalEntry.getFullUrl());
}
return newEntry(rand, bundle, careplanResource);
}
Aggregations