use of org.hl7.fhir.r5.elementmodel.Property in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConditionBundleToDtoConverterBase method conditionInfoToDto.
protected T conditionInfoToDto(ConditionInfoBundleExtractor.ConditionInfoHolder conditionInfo) {
T conditionDto = newConditionDtoImpl();
Condition condition = conditionInfo.getCondition();
conditionDto.setId(condition.getIdElement().getIdPart());
conditionDto.setName(codeableConceptToStringConverter.convert(condition.getCode()));
Coding categoryCoding = FhirUtil.findCoding(condition.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(condition.getCategory(), "http://hl7.org/fhir/us/sdoh-clinicalcare/CodeSystem/SDOHCC-CodeSystemTemporaryCodes");
}
if (categoryCoding == null) {
conditionDto.getErrors().add("SDOH category is not found.");
} else {
conditionDto.setCategory(new CodingDto(categoryCoding.getCode(), categoryCoding.getDisplay()));
}
Optional<Coding> icdCodeCodingOptional = findCode(condition.getCode(), System.ICD_10);
if (icdCodeCodingOptional.isPresent()) {
Coding icdCodeCoding = icdCodeCodingOptional.get();
conditionDto.setIcdCode(new CodingDto(icdCodeCoding.getCode(), icdCodeCoding.getDisplay()));
} else {
conditionDto.getErrors().add("ICD-10 code is not found.");
}
Optional<Coding> snomedCodeCodingOptional = findCode(condition.getCode(), System.SNOMED);
if (snomedCodeCodingOptional.isPresent()) {
Coding snomedCodeCoding = snomedCodeCodingOptional.get();
conditionDto.setSnomedCode(new CodingDto(snomedCodeCoding.getCode(), snomedCodeCoding.getDisplay()));
} else {
conditionDto.getErrors().add("SNOMED-CT code is not found.");
}
QuestionnaireResponse questionnaireResponse = conditionInfo.getQuestionnaireResponse();
if (questionnaireResponse != null) {
conditionDto.setAssessmentDate(FhirUtil.toLocalDateTime(questionnaireResponse.getAuthoredElement()));
Questionnaire questionnaire = conditionInfo.getQuestionnaire();
if (questionnaire != null) {
conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaire.getTitle()));
} else {
conditionDto.setBasedOn(new ReferenceDto(questionnaireResponse.getIdElement().getIdPart(), questionnaireResponse.getQuestionnaire()));
conditionDto.getErrors().add("Based on QuestionnaireResponse doesn't have a matching Questionnaire to get a title from. Using URL " + "instead.");
}
} else {
conditionDto.setBasedOn(new StringTypeDto(condition.getEvidenceFirstRep().getCodeFirstRep().getText()));
Reference recorder = condition.getRecorder();
conditionDto.setAuthoredBy(new ReferenceDto(recorder.getReferenceElement().getIdPart(), recorder.getDisplay()));
}
// abatement must be available for all resolved condition
if (ConditionClinicalStatusCodes.RESOLVED.toCode().equals(condition.getClinicalStatus().getCodingFirstRep().getCode())) {
if (condition.getAbatement() instanceof DateTimeType) {
conditionDto.setResolutionDate(FhirUtil.toLocalDateTime((DateTimeType) condition.getAbatement()));
} else {
conditionDto.getErrors().add("Condition is resolved but an abatement property is missing or not of a DateTimeType type.");
}
}
return conditionDto;
}
use of org.hl7.fhir.r5.elementmodel.Property 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.fhir.r5.elementmodel.Property in project Gravity-SDOH-Exchange-RI by FHIR.
the class OrganizationToDtoConverter method convert.
@Override
public OrganizationDto convert(Organization org) {
String orgId = org.getIdElement().getIdPart();
OrganizationDto orgDto = new OrganizationDto(orgId);
orgDto.setName(org.getName());
// We are interested only in CBO/CP types. Other are ignored.
Coding coding = FhirUtil.findCoding(org.getType(), OrganizationTypeCode.SYSTEM);
if (coding == null) {
orgDto.getErrors().add(String.format("Organization with id '%s' has no coding with system '%s' within a 'type' property. Such organizations " + "are " + "not expected in this context.", orgId, OrganizationTypeCode.SYSTEM));
} else {
try {
orgDto.setType(OrganizationTypeCode.fromCode(coding.getCode()));
} catch (FHIRException exc) {
orgDto.getErrors().add(String.format("OrganizationTypeCode code '%s' cannot be resolved for Organization with id '%s'.", coding.getCode(), orgId));
}
}
return orgDto;
}
use of org.hl7.fhir.r5.elementmodel.Property 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;
}
use of org.hl7.fhir.r5.elementmodel.Property in project org.hl7.fhir.core by hapifhir.
the class ISO21090Importer method produceProperties.
private void produceProperties(List<ElementDefinition> elements, String name, List<Property> properties, boolean attrMode, boolean snapshot) throws FHIRFormatError {
for (Property p : properties) {
if (p.isIsattr() == attrMode) {
ElementDefinition ed = new ElementDefinition();
elements.add(ed);
ed.setPath(name + "." + p.getName());
if (p.getType().startsWith("xsd:"))
ToolingExtensions.addStringExtension(ed.addType(), ToolingExtensions.EXT_XML_TYPE, p.getType());
else
ed.addType().setCode(p.getType());
ed.setMin(p.getMin());
ed.setMax(p.getMax() == Integer.MAX_VALUE ? "*" : Integer.toString(p.getMax()));
ed.setDefinition(p.getDoco());
if (p.isIsattr())
ed.addRepresentation(PropertyRepresentation.XMLATTR);
if (p.getBinding() != null)
ed.getBinding().setStrength(BindingStrength.REQUIRED).setValueSet(new UriType("http://hl7.org/fhir/iso21090/ValueSet/" + p.getBinding()));
if (snapshot)
ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());
}
}
}
Aggregations