use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.GoalPrepareBundleFactory 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."));
}
Aggregations