use of org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException 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."));
}
use of org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException in project Gravity-SDOH-Exchange-RI by FHIR.
the class HealthConcernService method create.
public HealthConcernDto create(NewHealthConcernDto newHealthConcernDto, UserDto user) {
Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
CurrentContextPrepareBundleFactory healthConcernPrepareBundleFactory = new CurrentContextPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId());
Bundle healthConcernRelatedResources = ehrClient.transaction().withBundle(healthConcernPrepareBundleFactory.createPrepareBundle()).execute();
CurrentContextPrepareInfoHolder healthConcernPrepareInfoHolder = new CurrentContextPrepareBundleExtractor().extract(healthConcernRelatedResources);
ConditionBundleFactory bundleFactory = new ConditionBundleFactory();
bundleFactory.setName(newHealthConcernDto.getName());
bundleFactory.setBasedOnText(newHealthConcernDto.getBasedOnText());
String category = newHealthConcernDto.getCategory();
bundleFactory.setCategory(sdohMappings.findCategoryCoding(category));
bundleFactory.setConditionType(UsCoreConditionCategory.HEALTHCONCERN);
bundleFactory.setIcdCode(sdohMappings.findCoding(category, Condition.class, System.ICD_10, newHealthConcernDto.getIcdCode()));
bundleFactory.setSnomedCode(sdohMappings.findCoding(category, Condition.class, System.SNOMED, newHealthConcernDto.getSnomedCode()));
bundleFactory.setPatient(healthConcernPrepareInfoHolder.getPatient());
bundleFactory.setPractitioner(healthConcernPrepareInfoHolder.getPractitioner());
Bundle healthConcernCreateBundle = ehrClient.transaction().withBundle(bundleFactory.createBundle()).execute();
IdType healthConcernId = FhirUtil.getFromResponseBundle(healthConcernCreateBundle, Condition.class);
Bundle responseBundle = searchHealthConcernQuery(ConditionClinicalStatus.ACTIVE).where(Condition.RES_ID.exactly().code(healthConcernId.getIdPart())).returnBundle(Bundle.class).execute();
return new HealthConcernBundleToDtoConverter().convert(responseBundle).stream().findFirst().orElseThrow(() -> new HealthConcernCreateException("Health Concern is not found in the response bundle."));
}
Aggregations