use of org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthConcernBundleToDtoConverter in project Gravity-SDOH-Exchange-RI by FHIR.
the class GoalBundleToDtoConverter method convert.
@Override
public List<GoalDto> convert(Bundle bundle) {
List<GoalDto> result = FhirUtil.getFromBundle(bundle, Goal.class).stream().map(goal -> {
GoalDto goalDto = new GoalDto();
goalDto.setId(goal.getIdElement().getIdPart());
if (goal.hasDescription() && goal.getDescription().hasText()) {
goalDto.setName(goal.getDescription().getText());
} else {
goalDto.getErrors().add("Goal description.text not found. Name cannot be set.");
}
if (goal.hasAchievementStatus()) {
goalDto.setAchievementStatus(GoalAchievement.fromCode(goal.getAchievementStatus().getCodingFirstRep().getCode()));
} else {
goalDto.getErrors().add("No achievement status available.");
}
// TODO reused from HealthConcernBundleToDtoConverter class. Refactor!
Coding categoryCoding = FhirUtil.findCoding(goal.getCategory(), SDOHMappings.getInstance().getSystem());
// TODO remove this in future. Fow now two different categories might be used before discussed.
if (categoryCoding == null) {
categoryCoding = FhirUtil.findCoding(goal.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
}
if (categoryCoding == null) {
goalDto.getErrors().add("SDOH category is not found.");
} else {
goalDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
}
Optional<Coding> snomedCodeCodingOptional = findCode(goal.getDescription(), System.SNOMED);
if (snomedCodeCodingOptional.isPresent()) {
Coding snomedCodeCoding = snomedCodeCodingOptional.get();
goalDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
} else {
goalDto.getErrors().add("SNOMED-CT code is not found.");
}
if (goal.hasExpressedBy()) {
Reference expressedBy = goal.getExpressedBy();
goalDto.setAddedBy(new ReferenceDto(expressedBy.getReferenceElement().getIdPart(), expressedBy.getDisplay()));
} else {
goalDto.getErrors().add("Goal expressedBy property is missing. addedBy will be null.");
}
goalDto.setStartDate(FhirUtil.toLocalDate(goal.getStartDateType()));
// TODO this is invalid. To clarify!
if (goal.getLifecycleStatus() == Goal.GoalLifecycleStatus.COMPLETED) {
if (goal.hasStatusDate()) {
goalDto.setEndDate(FhirUtil.toLocalDate(goal.getStatusDateElement()));
} else {
goalDto.getErrors().add("Goal statusDate must be set when the lifecycleStatus is COMPLETED. endDate will be null.");
}
}
goalDto.setComments(goal.getNote().stream().map(annotationToDtoConverter::convert).collect(Collectors.toList()));
goalDto.setProblems(goal.getAddresses().stream().filter(ref -> Condition.class.getSimpleName().equals(ref.getReferenceElement().getResourceType())).map(ref -> (Condition) ref.getResource()).map(cond -> new ConditionDto(cond.getIdElement().getIdPart(), codeableConceptToStringConverter.convert(cond.getCode()))).collect(Collectors.toList()));
return goalDto;
}).collect(Collectors.toList());
// TODO refactor. method too long.
// TODO refactor. Almost the same fragmen exists in a ProblemInfoBundleExtractor
Map<String, GoalDto> idToDtoMap = result.stream().collect(Collectors.toMap(g -> g.getId(), Function.identity()));
for (Task task : FhirUtil.getFromBundle(bundle, Task.class)) {
if (!task.hasFocus() || !(task.getFocus().getResource() instanceof ServiceRequest)) {
continue;
}
ServiceRequest sr = (ServiceRequest) task.getFocus().getResource();
sr.getSupportingInfo().stream().filter(ref -> Goal.class.getSimpleName().equals(ref.getReferenceElement().getResourceType()) && idToDtoMap.containsKey(ref.getReferenceElement().getIdPart())).forEach(ref -> idToDtoMap.get(ref.getReferenceElement().getIdPart()).getTasks().add(new TaskInfoDto(task.getIdElement().getIdPart(), task.getDescription(), task.getStatus())));
}
return result;
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthConcernBundleToDtoConverter 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."));
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthConcernBundleToDtoConverter in project Gravity-SDOH-Exchange-RI by FHIR.
the class HealthConcernService method listResolved.
public List<HealthConcernDto> listResolved() {
Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
Bundle responseBundle = searchHealthConcernQuery(ConditionClinicalStatus.RESOLVED).include(Condition.INCLUDE_EVIDENCE_DETAIL).include(Observation.INCLUDE_DERIVED_FROM.setRecurse(true)).returnBundle(Bundle.class).execute();
responseBundle = addQuestionnairesToConditionBundle(responseBundle);
return new HealthConcernBundleToDtoConverter().convert(responseBundle);
}
use of org.hl7.gravity.refimpl.sdohexchange.dto.converter.HealthConcernBundleToDtoConverter in project Gravity-SDOH-Exchange-RI by FHIR.
the class HealthConcernService method listActive.
public List<HealthConcernDto> listActive() {
Assert.notNull(SmartOnFhirContext.get().getPatient(), "Patient id cannot be null.");
Bundle responseBundle = searchHealthConcernQuery(ConditionClinicalStatus.ACTIVE).include(Condition.INCLUDE_EVIDENCE_DETAIL).include(Observation.INCLUDE_DERIVED_FROM.setRecurse(true)).returnBundle(Bundle.class).execute();
responseBundle = addQuestionnairesToConditionBundle(responseBundle);
return new HealthConcernBundleToDtoConverter().convert(responseBundle);
}
Aggregations