diff --git a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/RemovePatientNameTypeCode.java b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/RemovePatientNameTypeCode.java index 22aa2e109..eaf44962d 100644 --- a/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/RemovePatientNameTypeCode.java +++ b/etor/src/main/java/gov/hhs/cdc/trustedintermediary/etor/ruleengine/transformation/custom/RemovePatientNameTypeCode.java @@ -12,6 +12,8 @@ public class RemovePatientNameTypeCode implements CustomFhirTransformation { @Override public void transform(final FhirResource resource, final Map args) { Bundle bundle = (Bundle) resource.getUnderlyingResource(); - HapiHelper.removePID5_7Extension(bundle); + // Need to set the value for extension to empty instead of removing the extension, + // otherwise RS will set its own value in its place + HapiHelper.setPID5_7ExtensionValue(bundle, null); } } diff --git a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java index 746bb72b7..cb113e0a7 100644 --- a/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java +++ b/shared/src/main/java/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelper.java @@ -272,10 +272,12 @@ public static Extension getPID5Extension(Bundle bundle) { return name.getExtensionByUrl(HapiHelper.EXTENSION_XPN_HUMAN_NAME_URL); } - public static void removePID5_7Extension(Bundle bundle) { + public static void setPID5_7ExtensionValue(Bundle bundle, String value) { Extension extension = getPID5Extension(bundle); if (extension != null && extension.hasExtension(HapiHelper.EXTENSION_XPN7_URL)) { - extension.removeExtension(HapiHelper.EXTENSION_XPN7_URL); + extension + .getExtensionByUrl(HapiHelper.EXTENSION_XPN7_URL) + .setValue(new StringType(value)); } } diff --git a/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy b/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy index 8532a9d18..d8684a5db 100644 --- a/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy +++ b/shared/src/test/groovy/gov/hhs/cdc/trustedintermediary/external/hapi/HapiHelperTest.groovy @@ -457,7 +457,7 @@ class HapiHelperTest extends Specification { when: def bundle = new Bundle() - HapiHelper.removePID5_7Extension(bundle) + HapiHelper.setPID5_7ExtensionValue(bundle, null) then: HapiHelper.getPID5Extension(bundle) == null @@ -465,7 +465,7 @@ class HapiHelperTest extends Specification { when: HapiFhirHelper.createPIDPatient(bundle) HapiFhirHelper.setPID5Extension(bundle) - HapiHelper.removePID5_7Extension(bundle) + HapiHelper.setPID5_7ExtensionValue(bundle, null) then: HapiFhirHelper.getPID5_7Value(bundle) == null @@ -478,7 +478,7 @@ class HapiHelperTest extends Specification { HapiFhirHelper.getPID5_7Value(bundle) == pid5_7 when: - HapiHelper.removePID5_7Extension(bundle) + HapiHelper.setPID5_7ExtensionValue(bundle, null) then: HapiHelper.getPID5Extension(bundle) != null