Search in sources :

Example 1 with GoalPrepareBundleExtractor

use of org.hl7.gravity.refimpl.sdohexchange.fhir.extract.GoalPrepareBundleExtractor in project Gravity-SDOH-Exchange-RI by FHIR.

the class GoalService method create.

public GoalDto create(NewGoalDto newGoalDto, UserDto user) {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    GoalPrepareBundleFactory goalPrepareBundleFactory = new GoalPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId(), newGoalDto.getProblemIds());
    Bundle goalRelatedResources = ehrClient.transaction().withBundle(goalPrepareBundleFactory.createPrepareBundle()).execute();
    GoalPrepareBundleExtractor.GoalPrepareInfoHolder goalPrepareInfoHolder = new GoalPrepareBundleExtractor().extract(goalRelatedResources);
    GoalBundleFactory bundleFactory = new GoalBundleFactory();
    bundleFactory.setName(newGoalDto.getName());
    String category = newGoalDto.getCategory();
    bundleFactory.setCategory(sdohMappings.findCategoryCoding(category));
    bundleFactory.setSnomedCode(sdohMappings.findCoding(category, Goal.class, System.SNOMED, newGoalDto.getSnomedCode()));
    bundleFactory.setAchievementStatus(newGoalDto.getAchievementStatus());
    bundleFactory.setPatient(goalPrepareInfoHolder.getPatient());
    bundleFactory.setPractitioner(goalPrepareInfoHolder.getPractitioner());
    bundleFactory.setUser(user);
    bundleFactory.setComment(newGoalDto.getComment());
    bundleFactory.setProblems(goalPrepareInfoHolder.getProblems(newGoalDto.getProblemIds()));
    bundleFactory.setStartDate(newGoalDto.getStart());
    Bundle goalCreateBundle = ehrClient.transaction().withBundle(bundleFactory.createPrepareBundle()).execute();
    IdType goalId = FhirUtil.getFromResponseBundle(goalCreateBundle, Goal.class);
    Bundle responseBundle = searchGoalQuery(Goal.GoalLifecycleStatus.ACTIVE).where(Condition.RES_ID.exactly().code(goalId.getIdPart())).returnBundle(Bundle.class).execute();
    Bundle merged = addConditionsToGoalBundle(responseBundle);
    return new GoalBundleToDtoConverter().convert(merged).stream().findFirst().orElseThrow(() -> new HealthConcernCreateException("goal is not found in the response bundle."));
}
Also used : GoalPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.GoalPrepareBundleFactory) Goal(org.hl7.fhir.r4.model.Goal) GoalBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.GoalBundleFactory) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) HealthConcernCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException) GoalBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.GoalBundleToDtoConverter) GoalPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.GoalPrepareBundleExtractor) IdType(org.hl7.fhir.r4.model.IdType)

Aggregations

IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)1 Bundle (org.hl7.fhir.r4.model.Bundle)1 Goal (org.hl7.fhir.r4.model.Goal)1 IdType (org.hl7.fhir.r4.model.IdType)1 GoalBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.GoalBundleToDtoConverter)1 HealthConcernCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException)1 GoalPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.GoalPrepareBundleExtractor)1 GoalBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.GoalBundleFactory)1 GoalPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.GoalPrepareBundleFactory)1