Skip to content

Commit

Permalink
Merge pull request tech-by-design#988 from sabith-nadakkavil/csvConve…
Browse files Browse the repository at this point in the history
…rsion

fix: Mapping for scores code changes tech-by-design#745
  • Loading branch information
ratheesh-kr authored Jan 3, 2025
2 parents a869e93 + 5ded0f9 commit 45cad9a
Showing 1 changed file with 42 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.Meta;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Quantity;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.ResourceType;
import org.slf4j.Logger;
Expand Down Expand Up @@ -152,25 +153,50 @@ public List<BundleEntryComponent> convert(
observation.setIssued(DateUtil.convertStringToDate(data.getRecordedTime()));
questionAndAnswerCode.put(data.getQuestionCode(), data.getAnswerCode());

QUESTION_CODE_REF_MAP.forEach((key, value) -> {
if (key.equals(data.getQuestionCode())) {
List<Reference> derivedFromRefs = screeningObservationDataList.stream()
.filter(obs -> value.contains(obs.getQuestionCode()))
.map(obs -> {
String derivedFromId = CsvConversionUtil.sha256(
obs.getQuestionCodeDisplay()
.replace(" ", "") +
obs.getQuestionCode()
+ obs.getEncounterId());

return new Reference("Observation/" + derivedFromId);
})
.collect(Collectors.toList());
derivedFromMap.put(observationId, derivedFromRefs);
switch (data.getQuestionCode()) {
case "95614-4" -> { // Interpersonal safety
CodeableConcept coding = new CodeableConcept();
coding.addCoding(new Coding("http://unitsofmeasure.org", null,
"{Number}"));
coding.setText(data.getAnswerCodeDescription());
observation.setValue(coding);

}
case "77594-0" -> { // Physical Activity
Quantity quantity = new Quantity();
quantity.setValue(Double.parseDouble(data.getAnswerCodeDescription()));
quantity.setUnit("minutes per week");
quantity.setSystem("http://unitsofmeasure.org");
observation.setValue(quantity);
}

case "71969-0" -> { // Mental state
CodeableConcept coding = new CodeableConcept();
coding.addCoding(new Coding("http://unitsofmeasure.org", null,
"{Number}"));
coding.setText(data.getAnswerCodeDescription());
observation.setValue(coding);

}
default -> {
}

});
}

if (QUESTION_CODE_REF_MAP.containsKey(data.getQuestionCode())) {
Set<String> questionCodeSet = QUESTION_CODE_REF_MAP.get(data.getQuestionCode());
List<Reference> derivedFromRefs = screeningObservationDataList.stream()
.filter(obs -> questionCodeSet.contains(obs.getQuestionCode()))
.map(obs -> {
String derivedFromId = CsvConversionUtil.sha256(
obs.getQuestionCodeDisplay().replace(" ", "") +
obs.getQuestionCode()
+ obs.getEncounterId());
return new Reference("Observation/" + derivedFromId);
})
.collect(Collectors.toList());
derivedFromMap.put(observationId, derivedFromRefs);
}
List<Reference> derivedRefs = derivedFromMap.get(observationId);

if (derivedRefs != null && !derivedRefs.isEmpty()) {
Expand Down

0 comments on commit 45cad9a

Please sign in to comment.