Skip to content

Commit

Permalink
fix null race pointer (#7209)
Browse files Browse the repository at this point in the history
* fix null race pointer

* add regression test
  • Loading branch information
fzhao99 authored Jan 26, 2024
1 parent b852969 commit 0831949
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,20 +330,21 @@ public Address convertToAddress(
return address;
}

public Extension convertToRaceExtension(@NotNull String race) {
public Extension convertToRaceExtension(String race) {
var ext = new Extension();
ext.setUrl(RACE_EXTENSION_URL);
var codeable = new CodeableConcept();
var coding = codeable.addCoding();
String raceKey = race.toLowerCase();
if (StringUtils.isNotBlank(race) && PersonUtils.raceMap.containsKey(raceKey)) {
boolean isParseableRace =
StringUtils.isNotBlank(race) && PersonUtils.raceMap.containsKey(race.toLowerCase());
if (isParseableRace) {
if (MappingConstants.UNKNOWN_STRING.equalsIgnoreCase(race)
|| "refused".equalsIgnoreCase(race)) {
coding.setSystem(NULL_CODE_SYSTEM);
} else {
coding.setSystem(RACE_CODING_SYSTEM);
}
coding.setCode(PersonUtils.raceMap.get(raceKey));
coding.setCode(PersonUtils.raceMap.get(race.toLowerCase()));
codeable.setText(race);
} else {
coding.setSystem(NULL_CODE_SYSTEM);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov.cdc.usds.simplereport.api.converter;

import static gov.cdc.usds.simplereport.api.converter.FhirConstants.NOTE_TYPE_EXTENSION_URL;
import static gov.cdc.usds.simplereport.api.converter.FhirConstants.NULL_CODE_SYSTEM;
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;
Expand All @@ -12,6 +13,7 @@
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.model.api.TemporalPrecisionEnum;
import ca.uhn.fhir.parser.IParser;
import gov.cdc.usds.simplereport.api.MappingConstants;
import gov.cdc.usds.simplereport.db.model.DeviceType;
import gov.cdc.usds.simplereport.db.model.DeviceTypeDisease;
import gov.cdc.usds.simplereport.db.model.Facility;
Expand Down Expand Up @@ -307,6 +309,18 @@ void convertToRaceArgs_matches(
assertThat(codeableConcept.getText()).isEqualTo(expectedText);
}

@Test
void convertToRaceNull_convertsGracefully() {
var actual = fhirConverter.convertToRaceExtension(null);
var codeableConcept = actual.castToCodeableConcept(actual.getValue());
var code = codeableConcept.getCoding();

assertThat(code).hasSize(1);
assertThat(code.get(0).getSystem()).isEqualTo(NULL_CODE_SYSTEM);
assertThat(code.get(0).getCode()).isEqualTo(MappingConstants.UNK_CODE);
assertThat(codeableConcept.getText()).isEqualTo(MappingConstants.UNKNOWN_STRING);
}

private static Stream<Arguments> raceArgs() {
return Stream.of(
arguments("native", raceCodeSystem, "1002-5", "native"),
Expand Down

0 comments on commit 0831949

Please sign in to comment.