Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust abnormal flag mapping #7903

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,12 +441,64 @@ public static PersonName consolidateNameArguments(
Map.entry(OTHER, "Other"));
private static final Set<String> ORGANIZATION_TYPE_KEYS = ORGANIZATION_TYPES.keySet();

private static final String DETECTED_SNOMED = "260373001";
private static final String NOT_DETECTED_SNOMED = "260415000";
private static final String INVALID_SNOMED = "455371000124106";
public static final Map<String, SnomedConceptRecord> ABNORMAL_SNOMEDS =
Map.ofEntries(
Map.entry(
DETECTED_SNOMED,
new SnomedConceptRecord("Detected", DETECTED_SNOMED, TestResult.POSITIVE)),
Map.entry(
"720735008",
new SnomedConceptRecord("Presumptive positive", "720735008", TestResult.POSITIVE)),
Map.entry(
"10828004", new SnomedConceptRecord("Positive", "10828004", TestResult.POSITIVE)),
Map.entry(
"11214006", new SnomedConceptRecord("Reactive", "11214006", TestResult.POSITIVE)));

public static final Map<String, SnomedConceptRecord> NORMAL_SNOMEDS =
Map.ofEntries(
Map.entry(
NOT_DETECTED_SNOMED,
new SnomedConceptRecord("Not detected", NOT_DETECTED_SNOMED, TestResult.NEGATIVE)),
Map.entry(
"260385009", new SnomedConceptRecord("Negative", "260385009", TestResult.NEGATIVE)),
Map.entry(
"895231008",
new SnomedConceptRecord(
"Not detected in pooled specimen", "895231008", TestResult.NEGATIVE)),
Map.entry(
"131194007",
new SnomedConceptRecord("Non-Reactive", "131194007", TestResult.NEGATIVE)),
// certain UNDETERMINED codes are also flagged as normal
// https://github.com/CDCgov/prime-reportstream/blob/1ffae4ca0b04cd0aa9f169e26813ecd86df71bb5/prime-router/src/main/kotlin/metadata/Mappers.kt#L768
Map.entry(
"419984006",
new SnomedConceptRecord("Inconclusive", "419984006", TestResult.UNDETERMINED)),
Map.entry(
"42425007",
new SnomedConceptRecord("Equivocal", "42425007", TestResult.UNDETERMINED)),
Map.entry(
"82334004",
new SnomedConceptRecord("Indeterminate", "82334004", TestResult.UNDETERMINED)),
Map.entry(
"373121007",
new SnomedConceptRecord("Test not done", "373121007", TestResult.UNDETERMINED)),
Map.entry(
INVALID_SNOMED,
new SnomedConceptRecord("Invalid result", INVALID_SNOMED, TestResult.UNDETERMINED)),
Map.entry(
"125154007",
new SnomedConceptRecord(
"Specimen unsatisfactory for evaluation", "125154007", TestResult.UNDETERMINED)));

public static final SnomedConceptRecord DETECTED_SNOMED_CONCEPT =
new SnomedConceptRecord("Detected", "260373001", TestResult.POSITIVE);
ABNORMAL_SNOMEDS.get(DETECTED_SNOMED);
private static final SnomedConceptRecord NOT_DETECTED_SNOMED_CONCEPT =
new SnomedConceptRecord("Not detected", "260415000", TestResult.NEGATIVE);
NORMAL_SNOMEDS.get(NOT_DETECTED_SNOMED);
private static final SnomedConceptRecord INVALID_SNOMED_CONCEPT =
new SnomedConceptRecord("Invalid result", "455371000124106", TestResult.UNDETERMINED);
NORMAL_SNOMEDS.get(INVALID_SNOMED);
private static final List<SnomedConceptRecord> RESULTS_SNOMED_CONCEPTS =
List.of(DETECTED_SNOMED_CONCEPT, NOT_DETECTED_SNOMED_CONCEPT, INVALID_SNOMED_CONCEPT);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gov.cdc.usds.simplereport.api.converter;

import static gov.cdc.usds.simplereport.api.Translators.DETECTED_SNOMED_CONCEPT;
import static gov.cdc.usds.simplereport.api.Translators.ABNORMAL_SNOMEDS;
import static gov.cdc.usds.simplereport.api.Translators.FEMALE;
import static gov.cdc.usds.simplereport.api.Translators.GENDER_IDENTITIES;
import static gov.cdc.usds.simplereport.api.Translators.MALE;
import static gov.cdc.usds.simplereport.api.Translators.NON_BINARY;
import static gov.cdc.usds.simplereport.api.Translators.NORMAL_SNOMEDS;
import static gov.cdc.usds.simplereport.api.Translators.OTHER;
import static gov.cdc.usds.simplereport.api.Translators.REFUSED;
import static gov.cdc.usds.simplereport.api.Translators.TRANS_MAN;
Expand Down Expand Up @@ -159,6 +160,7 @@
import org.hl7.fhir.r4.model.Specimen;
import org.hl7.fhir.r4.model.StringType;
import org.hl7.fhir.r4.model.Type;
import org.owasp.encoder.Encode;
import org.springframework.boot.info.GitProperties;
import org.springframework.data.util.Pair;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -753,19 +755,21 @@ public Observation convertToObservation(ConvertToObservationProps props) {
return observation;
}

private Coding convertToAbnormalFlagInterpretation(String resultCode) {
public Coding convertToAbnormalFlagInterpretation(String resultCode) {
Coding abnormalFlag = new Coding();

abnormalFlag.setSystem(ABNORMAL_FLAGS_CODE_SYSTEM);

if (resultCode.equals(DETECTED_SNOMED_CONCEPT.code())) {
if (ABNORMAL_SNOMEDS.keySet().contains(resultCode)) {
abnormalFlag.setCode(ABNORMAL_FLAG_ABNORMAL.code());
abnormalFlag.setDisplay(ABNORMAL_FLAG_ABNORMAL.displayName());
} else {
} else if (NORMAL_SNOMEDS.keySet().contains(resultCode)) {
abnormalFlag.setCode(ABNORMAL_FLAG_NORMAL.code());
abnormalFlag.setDisplay(ABNORMAL_FLAG_NORMAL.displayName());
} else {
log.info("Unsupported SNOMED result code: {}", Encode.forJava(resultCode));
return null;
Comment on lines +770 to +772
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it also makes sense to adjust this bit to not add the interpretation that the abnormal flag coding lives inside. (otherwise it will just be an empty interpretation)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 agree that makes sense to omit the interpretation if it'll be empty anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OO good catch -- thank you!

}

return abnormalFlag;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.apache.commons.io.IOUtils;
import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ContactPoint;
import org.hl7.fhir.r4.model.ContactPoint.ContactPointSystem;
import org.hl7.fhir.r4.model.ContactPoint.ContactPointUse;
Expand Down Expand Up @@ -2045,4 +2046,27 @@ void convertToSpecimen_withoutCollectionCodeAndName_useDefaults() {
.isEqualTo(DEFAULT_LOCATION_CODE);
assertThat(specimen.getCollection().getBodySite().getText()).isEqualTo(DEFAULT_LOCATION_NAME);
}

@Test
void convertToAbnormalFlagInterpretation_withUnsupportedSnomed_returnsNull() {
String snomed = "1111";
Coding actual = fhirConverter.convertToAbnormalFlagInterpretation(snomed);
assertThat(actual).isNull();
}

@ParameterizedTest
@MethodSource("snomedArgs")
void convertToAbnormalFlagInterpretation_matches(
String snomed, String expectedCode, String expectedCodeName) {
Coding actual = fhirConverter.convertToAbnormalFlagInterpretation(snomed);
assertThat(actual.getCode()).isEqualTo(expectedCode);
assertThat(actual.getDisplay()).isEqualTo(expectedCodeName);
}

private static Stream<Arguments> snomedArgs() {
return Stream.of(
arguments("10828004", "A", "Abnormal"),
arguments("131194007", "N", "Normal"),
arguments("455371000124106", "N", "Normal"));
}
}
Loading