Search in sources :

Example 1 with CurrentContextPrepareBundleFactory

use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory 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."));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CurrentContextPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory) CurrentContextPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) HealthConcernCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException) HealthConcernBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthConcernBundleToDtoConverter) CurrentContextPrepareInfoHolder(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor.CurrentContextPrepareInfoHolder) ConditionBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ConditionBundleFactory) IdType(org.hl7.fhir.r4.model.IdType)

Example 2 with CurrentContextPrepareBundleFactory

use of org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory 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."));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CurrentContextPrepareBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory) ProblemCreateException(org.hl7.gravity.refimpl.sdohexchange.exception.ProblemCreateException) ProblemBundleFactory(org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ProblemBundleFactory) CurrentContextPrepareBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ProblemBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ProblemBundleToDtoConverter) IdType(org.hl7.fhir.r4.model.IdType)

Aggregations

IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)2 Bundle (org.hl7.fhir.r4.model.Bundle)2 Condition (org.hl7.fhir.r4.model.Condition)2 IdType (org.hl7.fhir.r4.model.IdType)2 CurrentContextPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor)2 CurrentContextPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory)2 HealthConcernBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthConcernBundleToDtoConverter)1 ProblemBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.ProblemBundleToDtoConverter)1 HealthConcernCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.HealthConcernCreateException)1 ProblemCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.ProblemCreateException)1 CurrentContextPrepareInfoHolder (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor.CurrentContextPrepareInfoHolder)1 ConditionBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ConditionBundleFactory)1 ProblemBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ProblemBundleFactory)1