Merge pull request #2878 from hapifhir/backport-mdm-resource-util-npe
Backport mdm resource util npe
This commit is contained in:
commit
293bbe2a40
|
@ -76,19 +76,19 @@ public final class MdmResourceUtil {
|
||||||
return theBaseResource.getMeta().getTag(theSystem, theCode) != null;
|
return theBaseResource.getMeta().getTag(theSystem, theCode) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean resourceHasTagWithSystem(IBaseResource theBaseResource, String theSystem) {
|
private static boolean resourceHasTagWithSystem(IBaseResource theBaseResource, @Nonnull String theSystem) {
|
||||||
if (theBaseResource == null) {
|
if (theBaseResource == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return theBaseResource.getMeta().getTag().stream().anyMatch(tag -> tag.getSystem().equalsIgnoreCase(theSystem));
|
return theBaseResource.getMeta().getTag().stream().anyMatch(tag -> theSystem.equalsIgnoreCase(tag.getSystem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<? extends IBaseCoding> getTagWithSystem(IBaseResource theResource, String theSystem) {
|
private static Optional<? extends IBaseCoding> getTagWithSystem(IBaseResource theResource, @Nonnull String theSystem) {
|
||||||
return theResource.getMeta().getTag().stream().filter(tag -> tag.getSystem().equalsIgnoreCase(theSystem)).findFirst();
|
return theResource.getMeta().getTag().stream().filter(tag -> theSystem.equalsIgnoreCase(tag.getSystem())).findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeTagWithSystem(IBaseResource theResource, String theSystem) {
|
public static void removeTagWithSystem(IBaseResource theResource, @Nonnull String theSystem) {
|
||||||
theResource.getMeta().getTag().removeIf(tag -> tag.getSystem().equalsIgnoreCase(theSystem));
|
theResource.getMeta().getTag().removeIf(tag -> theSystem.equalsIgnoreCase(tag.getSystem()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package ca.uhn.fhir.mdm.util;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r4.model.Organization;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
class MdmResourceUtilTest {
|
||||||
|
|
||||||
|
//See https://github.com/hapifhir/hapi-fhir/issues/2876
|
||||||
|
@Test
|
||||||
|
public void testNoNpeOnTagWithNoSystem() {
|
||||||
|
//Given
|
||||||
|
Organization organization = new Organization();
|
||||||
|
organization.getMeta().addTag(null, "Some Code", "Some Display");
|
||||||
|
|
||||||
|
boolean hasGoldenRecordTag = MdmResourceUtil.hasGoldenRecordSystemTag(organization);
|
||||||
|
|
||||||
|
assertThat(hasGoldenRecordTag, is(equalTo(false)));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue