fix terserutil clear (#5473)

* fix test

* review
This commit is contained in:
Ken Stevens 2023-11-21 11:39:18 -05:00 committed by GitHub
parent 6abfed603e
commit d5a1b0cdf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -348,7 +348,7 @@ public final class TerserUtil {
public static void clearField(FhirContext theFhirContext, IBaseResource theResource, String theFieldName) {
BaseRuntimeChildDefinition childDefinition =
getBaseRuntimeChildDefinition(theFhirContext, theFieldName, theResource);
clear(childDefinition.getAccessor().getValues(theResource));
childDefinition.getMutator().setValue(theResource, null);
}
/**

View File

@ -4,6 +4,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import org.hl7.fhir.instance.model.api.IBaseBackboneElement;
import org.hl7.fhir.r4.model.Address;
import org.hl7.fhir.r4.model.Claim;
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.DateType;
import org.hl7.fhir.r4.model.Enumerations;
@ -13,6 +14,7 @@ import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Organization;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.PrimitiveType;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.Test;
@ -570,6 +572,25 @@ class TerserUtilTest {
assertEquals("Test", p1.getAddress().get(1).getCity());
}
@Test
void testRemoveByFhirPath() {
// arrange
Claim claimWithReferences = createClaim();
claimWithReferences.setPatient(new Reference("Patient/123"));
String fhirPath = "patient";
assertTrue(claimWithReferences.hasPatient());
//act
TerserUtil.clearFieldByFhirPath(ourFhirContext, claimWithReferences, fhirPath);
//assert
assertFalse(claimWithReferences.hasPatient());
}
static Claim createClaim() {
Claim claim = new Claim();
claim.setStatus(Claim.ClaimStatus.ACTIVE);
return claim;
}
@Test
public void testSetField() {
Patient p1 = new Patient();