Skip to content

Commit

Permalink
Map syphilis history to FHIR
Browse files Browse the repository at this point in the history
  • Loading branch information
emyl3 committed Sep 26, 2024
1 parent 00710d9 commit ca770c0
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
import static gov.cdc.usds.simplereport.api.model.TestEventExport.DEFAULT_LOCATION_NAME;
import static gov.cdc.usds.simplereport.api.model.TestEventExport.FALLBACK_DEFAULT_TEST_MINUTES;
import static gov.cdc.usds.simplereport.api.model.TestEventExport.UNKNOWN_ADDRESS_INDICATOR;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.NO_SYPHILIS_HISTORY_SNOMED;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.YES_SYPHILIS_HISTORY_SNOMED;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.genderIdentityDisplaySet;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.genderIdentitySnomedSet;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.getResidenceTypeMap;
Expand Down Expand Up @@ -865,6 +867,19 @@ public Observation convertToAOEPregnancyObservation(String pregnancyStatusSnomed
pregnancyStatusValueCode);
}

public Observation convertToAOESyphilisHistoryObservation(String syphilisHistory) {
CodeableConcept observationCode =
createSNOMEDConcept(YES_SYPHILIS_HISTORY_SNOMED, "History of syphilis");
Boolean hasHistory = null;
if (syphilisHistory.equalsIgnoreCase(YES_SYPHILIS_HISTORY_SNOMED)) {
hasHistory = true;
} else if (syphilisHistory.equalsIgnoreCase(NO_SYPHILIS_HISTORY_SNOMED)) {
hasHistory = false;
}
return createAOEObservation(
uuidGenerator.randomUUID().toString(), observationCode, createYesNoUnkConcept(hasHistory));
}

public Observation convertToAOEYesNoUnkObservation(
Boolean isObserved, String observationLoinc, String observationDisplayText) {
CodeableConcept observationCode =
Expand Down Expand Up @@ -991,6 +1006,10 @@ public Set<Observation> convertToAOEObservations(
observations.addAll(convertToAOEGenderOfSexualPartnersObservation(sexualPartners));
}

if (surveyData.getSyphilisHistory() != null) {
observations.add(convertToAOESyphilisHistoryObservation(surveyData.getSyphilisHistory()));
}

return observations;
}

Expand Down Expand Up @@ -1629,7 +1648,7 @@ public Bundle createFhirBundle(ConditionAgnosticCreateFhirBundleProps props) {

var bundle =
new Bundle()
.setType(Bundle.BundleType.MESSAGE)
.setType(BundleType.MESSAGE)
.setTimestamp(currentDate)
.setIdentifier(new Identifier().setValue(props.getDiagnosticReport().getId()));

Expand All @@ -1638,7 +1657,7 @@ public Bundle createFhirBundle(ConditionAgnosticCreateFhirBundleProps props) {
entryList.forEach(
pair ->
bundle.addEntry(
new Bundle.BundleEntryComponent()
new BundleEntryComponent()
.setFullUrl(pair.getFirst())
.setResource(pair.getSecond())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import static gov.cdc.usds.simplereport.api.model.TestEventExport.DEFAULT_LOCATION_CODE;
import static gov.cdc.usds.simplereport.api.model.TestEventExport.DEFAULT_LOCATION_NAME;
import static gov.cdc.usds.simplereport.api.model.TestEventExport.UNKNOWN_ADDRESS_INDICATOR;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.NO_SYPHILIS_HISTORY_SNOMED;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.PREGNANT_UNKNOWN_SNOMED;
import static gov.cdc.usds.simplereport.db.model.PersonUtils.YES_SYPHILIS_HISTORY_SNOMED;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.from;
import static org.junit.jupiter.params.provider.Arguments.arguments;
Expand Down Expand Up @@ -1238,22 +1240,53 @@ void convertToAoeObservation_genderOfSexualPartners_matchesJson() throws IOExcep
JSONAssert.assertEquals(expectedSerialized, actualSerialized, true);
}

@Test
void convertToAoeObservation_syphilisHistory_matchesJson() throws IOException {
AskOnEntrySurvey answers =
AskOnEntrySurvey.builder()
.pregnancy(null)
.syphilisHistory(YES_SYPHILIS_HISTORY_SNOMED)
.symptoms(null)
.genderOfSexualPartners(null)
.symptomOnsetDate(null)
.noSymptoms(false)
.build();

String testId = "fakeId";

Set<Observation> actual =
fhirConverter.convertToAOEObservations(
testId, answers, new Person("first", "last", "middle", "suffix", null));

String actualSerialized =
actual.stream().map(parser::encodeResourceToString).collect(Collectors.toSet()).toString();
String expectedSerialized =
IOUtils.toString(
Objects.requireNonNull(
getClass()
.getClassLoader()
.getResourceAsStream("fhir/observationSyphilisHistory.json")),
StandardCharsets.UTF_8);
JSONAssert.assertEquals(expectedSerialized, actualSerialized, true);
}

@Test
void convertToAoeObservation_allAOE_matchesJson() throws IOException {
List<String> sexualPartners = List.of("male", "female");
AskOnEntrySurvey answers =
AskOnEntrySurvey.builder()
.pregnancy(PREGNANT_UNKNOWN_SNOMED)
.syphilisHistory(null)
.syphilisHistory(NO_SYPHILIS_HISTORY_SNOMED)
.symptoms(Map.of("fake", true))
.symptomOnsetDate(LocalDate.of(2023, 3, 4))
.genderOfSexualPartners(null)
.genderOfSexualPartners(sexualPartners)
.noSymptoms(false)
.build();

String testId = "fakeId";

var birthDate = LocalDate.of(2022, 12, 13);
var person =
LocalDate birthDate = LocalDate.of(2022, 12, 13);
Person person =
new Person(
null,
null,
Expand All @@ -1277,11 +1310,11 @@ void convertToAoeObservation_allAOE_matchesJson() throws IOException {
"English",
null);

var actual = fhirConverter.convertToAOEObservations(testId, answers, person);
Set<Observation> actual = fhirConverter.convertToAOEObservations(testId, answers, person);

String actualSerialized =
actual.stream().map(parser::encodeResourceToString).collect(Collectors.toSet()).toString();
var expectedSerialized =
String expectedSerialized =
IOUtils.toString(
Objects.requireNonNull(
getClass().getClassLoader().getResourceAsStream("fhir/observationAllAoe.json")),
Expand Down
113 changes: 113 additions & 0 deletions backend/src/test/resources/fhir/observationAllAoe.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,79 @@
[
{
"resourceType": "Observation",
"id": "8526bd3b-42e4-3a6f-88ff-3fc43b69dc20",
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "81959-9",
"display": "Public health laboratory ask at order entry panel"
}
]
}
}
],
"status": "final",
"code": {
"coding": [
{
"system": "http://simplereport.gov/",
"code": "SR0001",
"display": "What is the gender of their sexual partners"
}
],
"text": "What is the gender of their sexual partners"
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "446151000124109",
"display": "Male gender identity"
}
]
}
},
{
"resourceType": "Observation",
"id": "8526bd3b-42e4-3a6f-88ff-3fc43b69dc20",
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "81959-9",
"display": "Public health laboratory ask at order entry panel"
}
]
}
}
],
"status": "final",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "1087151000119108",
"display": "History of syphilis"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://terminology.hl7.org/ValueSet/v2-0136",
"code": "N",
"display": "No"
}
]
}
},
{
"resourceType": "Observation",
"id": "5f3026ea-845b-3649-8b62-d3dbfd3e7b62",
Expand Down Expand Up @@ -37,6 +112,44 @@
]
}
},
{
"resourceType": "Observation",
"id": "8526bd3b-42e4-3a6f-88ff-3fc43b69dc20",
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "81959-9",
"display": "Public health laboratory ask at order entry panel"
}
]
}
}
],
"status": "final",
"code": {
"coding": [
{
"system": "http://simplereport.gov/",
"code": "SR0001",
"display": "What is the gender of their sexual partners"
}
],
"text": "What is the gender of their sexual partners"
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "446141000124107",
"display": "Female gender identity"
}
]
}
},
{
"resourceType": "Observation",
"id": "07099f95-8754-3317-8e87-e1c4717c1af1",
Expand Down
77 changes: 77 additions & 0 deletions backend/src/test/resources/fhir/observationSyphilisHistory.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[
{
"resourceType": "Observation",
"id": "5f3026ea-845b-3649-8b62-d3dbfd3e7b62",
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "81959-9",
"display": "Public health laboratory ask at order entry panel"
}
]
}
}
],
"status": "final",
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "95419-8",
"display": "Has symptoms related to condition of interest"
}
],
"text": "Has symptoms related to condition of interest"
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://terminology.hl7.org/CodeSystem/v3-NullFlavor",
"code": "UNK",
"display": "unknown"
}
]
}
},
{
"resourceType": "Observation",
"id": "8526bd3b-42e4-3a6f-88ff-3fc43b69dc20",
"identifier": [
{
"use": "official",
"type": {
"coding": [
{
"system": "http://loinc.org",
"code": "81959-9",
"display": "Public health laboratory ask at order entry panel"
}
]
}
}
],
"status": "final",
"code": {
"coding": [
{
"system": "http://snomed.info/sct",
"code": "1087151000119108",
"display": "History of syphilis"
}
]
},
"valueCodeableConcept": {
"coding": [
{
"system": "http://terminology.hl7.org/ValueSet/v2-0136",
"code": "Y",
"display": "Yes"
}
]
}
}
]

0 comments on commit ca770c0

Please sign in to comment.