Search in sources :

Example 1 with StringTypeDto

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

the class AssessmentResponseToDtoConverter2 method convert.

@Override
public List<AssessmentResponse> convert(AseessmentInfoBundleExtractor.AssessmentInfoHolder infoHolder) {
    return infoHolder.getQuestionnaireResponse().getItem().stream().map(qr -> {
        AssessmentResponse assessmentResponse = new AssessmentResponse();
        assessmentResponse.setQuestion(new StringTypeDto(qr.getText()));
        Type itemAnswer = qr.getAnswerFirstRep().getValue();
        if (itemAnswer instanceof StringType) {
            assessmentResponse.setAnswer(new StringTypeDto(((StringType) itemAnswer).getValue()));
        } else if (itemAnswer instanceof Coding) {
            assessmentResponse.setAnswer(new StringTypeDto(((Coding) itemAnswer).getDisplay()));
        } else {
            assessmentResponse.getErrors().add(String.format("Answer cannot be resolved. %s type is not expected.", itemAnswer.getClass().getSimpleName()));
            assessmentResponse.setAnswer(new StringTypeDto("Answer cannot be parsed."));
        }
        return assessmentResponse;
    }).collect(Collectors.toList());
}
Also used : StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Converter(org.springframework.core.convert.converter.Converter) List(java.util.List) Type(org.hl7.fhir.r4.model.Type) AssessmentResponse(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) AseessmentInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor) Collectors(java.util.stream.Collectors) Type(org.hl7.fhir.r4.model.Type) StringType(org.hl7.fhir.r4.model.StringType) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) StringType(org.hl7.fhir.r4.model.StringType) Coding(org.hl7.fhir.r4.model.Coding) AssessmentResponse(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse)

Example 2 with StringTypeDto

use of org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto 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;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) CodingDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto) ReferenceDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Questionnaire(org.hl7.fhir.r4.model.Questionnaire) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) QuestionnaireResponse(org.hl7.fhir.r4.model.QuestionnaireResponse)

Example 3 with StringTypeDto

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

the class AssessmentResponseToDtoConverter method convert.

@Override
public List<AssessmentResponse> convert(AseessmentInfoBundleExtractor.AssessmentInfoHolder infoHolder) {
    Map<String, String> items = new HashMap<>();
    infoHolder.getQuestionnaireResponse().getItem().forEach(i -> items.put(i.getLinkId(), i.getText()));
    return infoHolder.getObservations().stream().filter(Observation::hasValue).map(o -> {
        AssessmentDto.AssessmentResponse assessmentResponse = new AssessmentDto.AssessmentResponse();
        String code = o.getCode().getCodingFirstRep().getCode();
        String question = items.get("/" + code);
        if (question == null) {
            question = code;
            assessmentResponse.getErrors().add("No question text found. Using a code instead.");
        }
        assessmentResponse.setQuestion(new StringTypeDto(question));
        assessmentResponse.setAnswer(typeToDtoConverter.convert(o.getValue()));
        return assessmentResponse;
    }).collect(Collectors.toList());
}
Also used : StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) Converter(org.springframework.core.convert.converter.Converter) List(java.util.List) AssessmentResponse(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse) Map(java.util.Map) AssessmentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto) HashMap(java.util.HashMap) AseessmentInfoBundleExtractor(org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor) Collectors(java.util.stream.Collectors) Observation(org.hl7.fhir.r4.model.Observation) StringTypeDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto) HashMap(java.util.HashMap) AssessmentResponse(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse) Observation(org.hl7.fhir.r4.model.Observation) AssessmentDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto) AssessmentResponse(org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse)

Aggregations

StringTypeDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.StringTypeDto)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Coding (org.hl7.fhir.r4.model.Coding)2 AssessmentResponse (org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto.AssessmentResponse)2 AseessmentInfoBundleExtractor (org.hl7.gravity.refimpl.sdohexchange.fhir.extract.AseessmentInfoBundleExtractor)2 Converter (org.springframework.core.convert.converter.Converter)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Condition (org.hl7.fhir.r4.model.Condition)1 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)1 Observation (org.hl7.fhir.r4.model.Observation)1 Questionnaire (org.hl7.fhir.r4.model.Questionnaire)1 QuestionnaireResponse (org.hl7.fhir.r4.model.QuestionnaireResponse)1 Reference (org.hl7.fhir.r4.model.Reference)1 StringType (org.hl7.fhir.r4.model.StringType)1 Type (org.hl7.fhir.r4.model.Type)1 AssessmentDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.AssessmentDto)1 CodingDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.CodingDto)1 ReferenceDto (org.hl7.gravity.refimpl.sdohexchange.dto.response.ReferenceDto)1