Search in sources :

Example 16 with Goal

use of org.hl7.fhir.r4.model.Goal in project synthea by synthetichealth.

the class FhirR4 method careGoal.

/**
 * Map the JsonObject into a FHIR Goal resource, and add it to the given Bundle.
 * @param rand Source of randomness to use when generating ids etc
 * @param bundle The Bundle to add to
 * @param goalStatus The GoalStatus
 * @param goal The JsonObject
 * @return The added Entry
 */
private static BundleEntryComponent careGoal(RandomNumberGenerator rand, Bundle bundle, BundleEntryComponent personEntry, long carePlanStart, CodeableConcept goalStatus, JsonObject goal) {
    String resourceID = rand.randUUID().toString();
    Goal goalResource = new Goal();
    if (USE_US_CORE_IG) {
        Meta meta = new Meta();
        meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-goal");
        goalResource.setMeta(meta);
    }
    goalResource.setLifecycleStatus(GoalLifecycleStatus.ACCEPTED);
    goalResource.setAchievementStatus(goalStatus);
    goalResource.setId(resourceID);
    goalResource.setSubject(new Reference(personEntry.getFullUrl()));
    if (goal.has("text")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        descriptionCodeableConcept.setText(goal.get("text").getAsString());
        goalResource.setDescription(descriptionCodeableConcept);
    } else if (goal.has("codes")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        JsonObject code = goal.get("codes").getAsJsonArray().get(0).getAsJsonObject();
        descriptionCodeableConcept.addCoding().setSystem(LOINC_URI).setCode(code.get("code").getAsString()).setDisplay(code.get("display").getAsString());
        descriptionCodeableConcept.setText(code.get("display").getAsString());
        goalResource.setDescription(descriptionCodeableConcept);
    } else if (goal.has("observation")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        // build up our own text from the observation condition, similar to the graphviz logic
        JsonObject logic = goal.get("observation").getAsJsonObject();
        String[] text = { logic.get("codes").getAsJsonArray().get(0).getAsJsonObject().get("display").getAsString(), logic.get("operator").getAsString(), logic.get("value").getAsString() };
        descriptionCodeableConcept.setText(String.join(" ", text));
        goalResource.setDescription(descriptionCodeableConcept);
    }
    goalResource.addTarget().setMeasure(goalResource.getDescription()).setDue(new DateType(new Date(carePlanStart + Utilities.convertTime("days", 30))));
    if (goal.has("addresses")) {
        for (JsonElement reasonElement : goal.get("addresses").getAsJsonArray()) {
            if (reasonElement instanceof JsonObject) {
                JsonObject reasonObject = reasonElement.getAsJsonObject();
                String reasonCode = reasonObject.get("codes").getAsJsonObject().get("SNOMED-CT").getAsJsonArray().get(0).getAsString();
                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 (reasonCode.equals(coding.getCode())) {
                            goalResource.addAddresses().setReference(entry.getFullUrl());
                        }
                    }
                }
            }
        }
    }
    return newEntry(rand, bundle, goalResource);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) JsonObject(com.google.gson.JsonObject) Date(java.util.Date) Goal(org.hl7.fhir.r4.model.Goal) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) JsonElement(com.google.gson.JsonElement) DateType(org.hl7.fhir.r4.model.DateType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 17 with Goal

use of org.hl7.fhir.r4.model.Goal 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);
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Meta(org.hl7.fhir.r4.model.Meta) Reference(org.hl7.fhir.r4.model.Reference) DocumentReference(org.hl7.fhir.r4.model.DocumentReference) Period(org.hl7.fhir.r4.model.Period) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) CarePlanActivityDetailComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityDetailComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) CarePlanActivityStatus(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityStatus) CarePlanActivityComponent(org.hl7.fhir.r4.model.CarePlan.CarePlanActivityComponent) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 18 with Goal

use of org.hl7.fhir.r4.model.Goal 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);
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) Reference(org.hl7.fhir.dstu3.model.Reference) Period(org.hl7.fhir.dstu3.model.Period) JsonObject(com.google.gson.JsonObject) Code(org.mitre.synthea.world.concepts.HealthRecord.Code) Date(java.util.Date) CarePlanActivityDetailComponent(org.hl7.fhir.dstu3.model.CarePlan.CarePlanActivityDetailComponent) CarePlan(org.mitre.synthea.world.concepts.HealthRecord.CarePlan) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) GoalStatus(org.hl7.fhir.dstu3.model.Goal.GoalStatus) Coding(org.hl7.fhir.dstu3.model.Coding) CarePlanActivityStatus(org.hl7.fhir.dstu3.model.CarePlan.CarePlanActivityStatus) CarePlanActivityComponent(org.hl7.fhir.dstu3.model.CarePlan.CarePlanActivityComponent)

Example 19 with Goal

use of org.hl7.fhir.r4.model.Goal in project synthea by synthetichealth.

the class FhirStu3 method caregoal.

/**
 * Map the JsonObject into a FHIR Goal resource, and add it to the given Bundle.
 * @param rand Source of randomness to use when generating ids etc
 * @param bundle The Bundle to add to
 * @param goalStatus The GoalStatus
 * @param goal The JsonObject
 * @return The added Entry
 */
private static BundleEntryComponent caregoal(RandomNumberGenerator rand, Bundle bundle, GoalStatus goalStatus, JsonObject goal) {
    String resourceID = rand.randUUID().toString();
    org.hl7.fhir.dstu3.model.Goal goalResource = new org.hl7.fhir.dstu3.model.Goal();
    goalResource.setStatus(goalStatus);
    goalResource.setId(resourceID);
    if (goal.has("text")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        descriptionCodeableConcept.setText(goal.get("text").getAsString());
        goalResource.setDescription(descriptionCodeableConcept);
    } else if (goal.has("codes")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        JsonObject code = goal.get("codes").getAsJsonArray().get(0).getAsJsonObject();
        descriptionCodeableConcept.addCoding().setSystem(LOINC_URI).setCode(code.get("code").getAsString()).setDisplay(code.get("display").getAsString());
        descriptionCodeableConcept.setText(code.get("display").getAsString());
        goalResource.setDescription(descriptionCodeableConcept);
    } else if (goal.has("observation")) {
        CodeableConcept descriptionCodeableConcept = new CodeableConcept();
        // build up our own text from the observation condition, similar to the graphviz logic
        JsonObject logic = goal.get("observation").getAsJsonObject();
        String[] text = { logic.get("codes").getAsJsonArray().get(0).getAsJsonObject().get("display").getAsString(), logic.get("operator").getAsString(), logic.get("value").getAsString() };
        descriptionCodeableConcept.setText(String.join(" ", text));
        goalResource.setDescription(descriptionCodeableConcept);
    }
    if (goal.has("addresses")) {
        for (JsonElement reasonElement : goal.get("addresses").getAsJsonArray()) {
            if (reasonElement instanceof JsonObject) {
                JsonObject reasonObject = reasonElement.getAsJsonObject();
                String reasonCode = reasonObject.get("codes").getAsJsonObject().get("SNOMED-CT").getAsJsonArray().get(0).getAsString();
                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 (reasonCode.equals(coding.getCode())) {
                            goalResource.addAddresses().setReference(entry.getFullUrl());
                        }
                    }
                }
            }
        }
    }
    return newEntry(rand, bundle, goalResource);
}
Also used : Condition(org.hl7.fhir.dstu3.model.Condition) JsonObject(com.google.gson.JsonObject) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) Coding(org.hl7.fhir.dstu3.model.Coding) JsonElement(com.google.gson.JsonElement) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 20 with Goal

use of org.hl7.fhir.r4.model.Goal in project Gravity-SDOH-Exchange-RI by FHIR.

the class SupportService method listGoals.

public List<GoalInfoDto> listGoals() {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    Bundle goalsBundle = ehrClient.search().forResource(Goal.class).sort().descending(Constants.PARAM_LASTUPDATED).where(Goal.PATIENT.hasId(SmartOnFhirContext.get().getPatient())).where(new StringClientParam(Constants.PARAM_PROFILE).matches().value(SDOHProfiles.GOAL)).where(Goal.LIFECYCLE_STATUS.exactly().code(Goal.GoalLifecycleStatus.ACTIVE.toCode())).returnBundle(Bundle.class).execute();
    return FhirUtil.getFromBundle(goalsBundle, Goal.class).stream().map(goal -> new GoalToInfoDtoConverter().convert(goal)).collect(Collectors.toList());
}
Also used : Constants(ca.uhn.fhir.rest.api.Constants) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) Condition(org.hl7.fhir.r4.model.Condition) UsCoreConditionCategory(org.hl7.gravity.refimpl.sdohexchange.fhir.UsCoreConditionCategory) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) GoalToInfoDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.GoalToInfoDtoConverter) Task(org.hl7.fhir.r5.model.Task) TaskQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.TaskQueryFactory) Strings(com.google.common.base.Strings) GoalInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalInfoDto) Service(org.springframework.stereotype.Service) GoalQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.GoalQueryFactory) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) HealthcareServiceBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthcareServiceBundleToDtoConverter) SDOHProfiles(org.hl7.gravity.refimpl.sdohexchange.fhir.SDOHProfiles) HealthConcernQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.HealthConcernQueryFactory) HealthcareServiceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.HealthcareServiceDto) OrganizationDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.OrganizationDto) OrganizationToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.OrganizationToDtoConverter) Goal(org.hl7.fhir.r4.model.Goal) IQuery(ca.uhn.fhir.rest.gclient.IQuery) ConditionClinicalStatusCodes(org.hl7.gravity.refimpl.sdohexchange.fhir.ConditionClinicalStatusCodes) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) ActiveResourcesDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ActiveResourcesDto) Collectors(java.util.stream.Collectors) Organization(org.hl7.fhir.r4.model.Organization) List(java.util.List) SmartOnFhirContext(com.healthlx.smartonfhir.core.SmartOnFhirContext) HealthcareService(org.hl7.fhir.r4.model.HealthcareService) ConditionToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ConditionToDtoConverter) Bundle(org.hl7.fhir.r4.model.Bundle) ConditionDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ConditionDto) OrganizationTypeCode(org.hl7.gravity.refimpl.sdohexchange.codes.OrganizationTypeCode) ProblemQueryFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.query.ProblemQueryFactory) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) FhirUtil(org.hl7.gravity.refimpl.sdohexchange.util.FhirUtil) Assert(org.springframework.util.Assert) Goal(org.hl7.fhir.r4.model.Goal) StringClientParam(ca.uhn.fhir.rest.gclient.StringClientParam) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) GoalToInfoDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.GoalToInfoDtoConverter)

Aggregations

Goal (org.hl7.fhir.r4.model.Goal)11 Bundle (org.hl7.fhir.r4.model.Bundle)8 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)6 Condition (org.hl7.fhir.r4.model.Condition)6 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)6 Date (java.util.Date)5 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)5 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)5 JsonObject (com.google.gson.JsonObject)4 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 IdType (org.hl7.fhir.r4.model.IdType)4 Reference (org.hl7.fhir.r4.model.Reference)4 List (java.util.List)3 Coding (org.hl7.fhir.r4.model.Coding)3 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)3 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)2 JsonElement (com.google.gson.JsonElement)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2