Search in sources :

Example 1 with ProblemDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class ProblemService method listActive.

public List<ProblemDto> listActive() {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    Bundle responseBundle = searchProblemQuery(ConditionClinicalStatusCodes.ACTIVE).include(Condition.INCLUDE_EVIDENCE_DETAIL).include(Observation.INCLUDE_DERIVED_FROM.setRecurse(true)).returnBundle(Bundle.class).execute();
    // This is risky but in scope of RI with a very limited number of resources - this will work
    responseBundle = addTasksAndSRsToConditionBundle(responseBundle);
    responseBundle = addGoalsToConditionBundle(responseBundle);
    responseBundle = addQuestionnairesToConditionBundle(responseBundle);
    return new ProblemBundleToDtoConverter().convert(responseBundle);
}
Also used : IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ProblemBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ProblemBundleToDtoConverter)

Example 2 with ProblemDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class ProblemBundleToDtoConverter method conditionInfoToDto.

@Override
protected ProblemDto conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
    // TODO refactor this. Avoid manual casting. Refactor the design of a base class instead.
    Assert.isInstanceOf(ProblemInfoBundleExtractor.ProblemInfoHolder.class, conditionInfo, "conditionInfo must be a ProblemInfoHolder.");
    ProblemInfoBundleExtractor.ProblemInfoHolder probleminfo = (ProblemInfoBundleExtractor.ProblemInfoHolder) conditionInfo;
    Condition condition = probleminfo.getCondition();
    ProblemDto problemDto = super.conditionInfoToDto(probleminfo);
    // Onset must be available for the problem list items.
    if (condition.getOnset() != null) {
        problemDto.setStartDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getOnset()));
    } else {
        problemDto.getErrors().add("Condition is a problem-list-item but an onset property is missing or not of a DateTimeType " + "type.");
    }
    problemDto.getTasks().addAll(probleminfo.getTasks().stream().map(t -> new TaskInfoDto(t.getId(), t.getName(), t.getStatus())).collect(Collectors.toList()));
    problemDto.getGoals().addAll(probleminfo.getGoals().stream().map(t -> new GoalInfoDto(t.getId(), t.getName(), t.getStatus())).collect(Collectors.toList()));
    return problemDto;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) GoalInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalInfoDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TaskInfoDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto) ProblemInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ProblemInfoBundleExtractor) ProblemDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto)

Example 3 with ProblemDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto in project Gravity-SDOH-Exchange-RI by FHIR.

the class ProblemService method listClosed.

public List<ProblemDto> listClosed() {
    Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
    Bundle responseBundle = searchProblemQuery(ConditionClinicalStatusCodes.RESOLVED).include(Condition.INCLUDE_EVIDENCE_DETAIL).include(Observation.INCLUDE_DERIVED_FROM.setRecurse(true)).returnBundle(Bundle.class).execute();
    responseBundle = addQuestionnairesToConditionBundle(responseBundle);
    return new ProblemBundleToDtoConverter().convert(responseBundle);
}
Also used : IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) Bundle(org.hl7.fhir.r4.model.Bundle) ProblemBundleToDtoConverter(org.hl7.gravity.refimpl.sdohexchange.dto.converter.ProblemBundleToDtoConverter)

Example 4 with ProblemDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto 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)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 ProblemBundleToDtoConverter (org.hl7.gravity.refimpl.sdohexchange.dto.converter.ProblemBundleToDtoConverter)3 Condition (org.hl7.fhir.r4.model.Condition)2 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)1 IdType (org.hl7.fhir.r4.model.IdType)1 GoalInfoDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.GoalInfoDto)1 ProblemDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.ProblemDto)1 TaskInfoDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.TaskInfoDto)1 ProblemCreateException (org.hl7.gravity.refimpl.sdohexchange.exception.ProblemCreateException)1 CurrentContextPrepareBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.CurrentContextPrepareBundleExtractor)1 ProblemInfoBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.ProblemInfoBundleExtractor)1 CurrentContextPrepareBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.CurrentContextPrepareBundleFactory)1 ProblemBundleFactory (org.hl7.gravity.refimpl.sdohexchange.fhir.factory.ProblemBundleFactory)1