use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ProblemBundleFactory in project Gravity-SDOH-Exchange-RI by FHIR.
the class ProblemService method create.
public ProblemDto create(NewProblemDto newProblemDto, UserDto user) {
Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
CurrentContextPrepareBundleFactory currentContextPrepareBundleFactory = new CurrentContextPrepareBundleFactory(SmartOnFhirContext.get().getPatient(), user.getId());
Bundle problemRelatedResources = ehrClient.transaction().withBundle(currentContextPrepareBundleFactory.createPrepareBundle()).execute();
CurrentContextPrepareBundleExtractor.CurrentContextPrepareInfoHolder currentContextPrepareInfoHolder = new CurrentContextPrepareBundleExtractor().extract(problemRelatedResources);
ProblemBundleFactory bundleFactory = new ProblemBundleFactory();
bundleFactory.setName(newProblemDto.getName());
bundleFactory.setBasedOnText(newProblemDto.getBasedOnText());
bundleFactory.setStartDate(newProblemDto.getStartDate());
String category = newProblemDto.getCategory();
bundleFactory.setCategory(sdohMappings.findCategoryCoding(category));
bundleFactory.setConditionType(UsCoreConditionCategory.PROBLEMLISTITEM);
bundleFactory.setIcdCode(sdohMappings.findCoding(category, Condition.class, System.ICD_10, newProblemDto.getIcdCode()));
bundleFactory.setSnomedCode(sdohMappings.findCoding(category, Condition.class, System.SNOMED, newProblemDto.getSnomedCode()));
bundleFactory.setPatient(currentContextPrepareInfoHolder.getPatient());
bundleFactory.setPractitioner(currentContextPrepareInfoHolder.getPractitioner());
Bundle problemCreateBundle = ehrClient.transaction().withBundle(bundleFactory.createBundle()).execute();
IdType problemId = FhirUtil.getFromResponseBundle(problemCreateBundle, Condition.class);
Bundle responseBundle = searchProblemQuery(ConditionClinicalStatusCodes.ACTIVE).where(Condition.RES_ID.exactly().code(problemId.getIdPart())).returnBundle(Bundle.class).execute();
return new ProblemBundleToDtoConverter().convert(responseBundle).stream().findFirst().orElseThrow(() -> new ProblemCreateException("Problem is not found in the response bundle."));
}
Aggregations