Skip to content

Commit

Permalink
apply correct behavior for defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
fzhao99 committed Nov 16, 2023
1 parent cbeed3b commit 1236666
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,32 +613,49 @@ public Device convertToDevice(
return device;
}

// https://github.com/CDCgov/prime-simplereport/pull/6955#discussion_r1395360817
private Specimen setCollectionCodingAndName(Specimen specimen, ConvertToSpecimenProps props) {
boolean collectionCodeProvided = StringUtils.isNotBlank(props.getCollectionCode());
boolean collectionLocationNameProvided = StringUtils.isNotBlank(props.getCollectionName());

String collectionCodeToSet = DEFAULT_LOCATION_CODE;
String collectionLocationNameToSet = null;

if (collectionCodeProvided && !collectionLocationNameProvided) {
collectionCodeToSet = props.getCollectionCode();
} else if (collectionCodeProvided && collectionLocationNameProvided) {
collectionCodeToSet = props.getCollectionCode();
collectionLocationNameToSet = props.getCollectionName();
} else {
collectionLocationNameToSet = DEFAULT_LOCATION_NAME;
}

Specimen.SpecimenCollectionComponent collection = specimen.getCollection();
CodeableConcept collectionCodeableConcept = collection.getBodySite();
Coding collectionCoding = collectionCodeableConcept.addCoding();
collectionCoding.setSystem(SNOMED_CODE_SYSTEM);
collectionCoding.setCode(collectionCodeToSet);
collectionCodeableConcept.setText(collectionLocationNameToSet);

return specimen;
}

public Specimen convertToSpecimen(ConvertToSpecimenProps props) {
var specimen = new Specimen();
Specimen specimen = new Specimen();
specimen.setId(props.getId());
specimen.addIdentifier().setValue(props.getIdentifier());

var collection = specimen.getCollection();
var collectionCodeableConcept = collection.getBodySite();
var collectionCoding = collectionCodeableConcept.addCoding();
collectionCoding.setSystem(SNOMED_CODE_SYSTEM);
collectionCoding.setCode(
Optional.of(props)
.map(ConvertToSpecimenProps::getCollectionCode)
.orElse(DEFAULT_LOCATION_CODE));
collectionCodeableConcept.setText(
Optional.of(props)
.map(ConvertToSpecimenProps::getCollectionName)
.orElse(DEFAULT_LOCATION_NAME));
specimen = setCollectionCodingAndName(specimen, props);

if (StringUtils.isNotBlank(props.getSpecimenCode())) {
var codeableConcept = specimen.getType();
var coding = codeableConcept.addCoding();
CodeableConcept codeableConcept = specimen.getType();
Coding coding = codeableConcept.addCoding();
coding.setSystem(SNOMED_CODE_SYSTEM);
coding.setCode(props.getSpecimenCode());
codeableConcept.setText(props.getSpecimenName());
}
if (props.getCollectionDate() != null) {
Specimen.SpecimenCollectionComponent collection = specimen.getCollection();
collection.setCollected(convertToDateTimeType(props.getCollectionDate()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1747,4 +1747,50 @@ void createFhirBundle_TestEvent_matchesJson() throws IOException {

JSONAssert.assertEquals(expectedSerialized, actualSerialized, JSONCompareMode.NON_EXTENSIBLE);
}

// https://github.com/CDCgov/prime-simplereport/pull/6955#discussion_r1395360817
@Test
void convertToSpecimen_withCollectionCodeAndName_useProvided() {
ConvertToSpecimenProps props =
ConvertToSpecimenProps.builder()
.collectionCode("Some collection code")
.collectionName("Some collection name")
.build();

Specimen specimen = fhirConverter.convertToSpecimen(props);
assertThat(specimen.getCollection().getBodySite().getCodingFirstRep().getCode())
.isEqualTo("Some collection code");
assertThat(specimen.getCollection().getBodySite().getText()).isEqualTo("Some collection name");
}

@Test
void convertToSpecimen_withCollectionCodeAndWithoutName_setsCodeButLeavesNameBlank() {
ConvertToSpecimenProps props =
ConvertToSpecimenProps.builder().collectionCode("Some collection code").build();

Specimen specimen = fhirConverter.convertToSpecimen(props);
assertThat(specimen.getCollection().getBodySite().getCodingFirstRep().getCode())
.isEqualTo("Some collection code");
assertThat(specimen.getCollection().getBodySite().getText()).isBlank();
}

@Test
void convertToSpecimen_withoutCollectionCodeAndWithName_useDefaults() {
ConvertToSpecimenProps props =
ConvertToSpecimenProps.builder().collectionName("Some collection name").build();

Specimen specimen = fhirConverter.convertToSpecimen(props);
assertThat(specimen.getCollection().getBodySite().getCodingFirstRep().getCode())
.isEqualTo(DEFAULT_LOCATION_CODE);
assertThat(specimen.getCollection().getBodySite().getText()).isEqualTo(DEFAULT_LOCATION_NAME);
}

@Test
void convertToSpecimen_withoutCollectionCodeAndName_useDefaults() {
ConvertToSpecimenProps props = ConvertToSpecimenProps.builder().build();
Specimen specimen = fhirConverter.convertToSpecimen(props);
assertThat(specimen.getCollection().getBodySite().getCodingFirstRep().getCode())
.isEqualTo(DEFAULT_LOCATION_CODE);
assertThat(specimen.getCollection().getBodySite().getText()).isEqualTo(DEFAULT_LOCATION_NAME);
}
}

0 comments on commit 1236666

Please sign in to comment.