Skip to content

Commit 577bc7a

Browse files
authored
Move SPM segment to the last order group within HL7 message (#9363)
1 parent 67477ac commit 577bc7a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

backend/src/main/java/gov/cdc/usds/simplereport/api/converter/HL7Converter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ public ORU_R01 createLabReportMessage(
251251
// in a message as long as each specimen is associated with only one observation request (aka
252252
// test ordered LOINC). With how the app currently works, we will only ever have one specimen
253253
// in the entire HL7 message. That is only due to how the app is currently designed, not a
254-
// constraint of HL7.
254+
// constraint of HL7. This SPM segment should be attached to the last order group.
255255
// See page 83, HL7 v2.5.1 IG
256-
if (orderObservationIndex == 0) {
256+
if (orderObservationIndex == testOrderLoincToTestDetailsMap.size() - 1) {
257257
SPM specimen = orderGroup.getSPECIMEN().getSPM();
258258
populateSpecimen(specimen, 1, specimenId, specimenInput);
259259
}

backend/src/test/java/gov/cdc/usds/simplereport/api/converter/HL7ConverterTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ void createLabReportMessage_fromTestEvent_multiplex_onDeviceWithNoMultiplexTestO
223223
Parser parser = hapiContext.getPipeParser();
224224
String encodedMessage = parser.encode(message);
225225
assertThat(StringUtils.countMatches(encodedMessage, "OBR|")).isEqualTo(2);
226+
227+
assertThat(StringUtils.countMatches(encodedMessage, "SPM|")).isEqualTo(1);
228+
String[] lines = encodedMessage.replace("\r", "\n").split("\n");
229+
assertThat(lines[lines.length - 1]).contains("SPM|");
226230
}
227231

228232
@Test

0 commit comments

Comments
 (0)