Removed deprecated TerserUtil

This commit is contained in:
Nick Goupinets 2021-03-31 16:07:21 -04:00
parent 7a9514b94a
commit ab8505dfc4
6 changed files with 22 additions and 347 deletions

View File

@ -1,5 +1,25 @@
package ca.uhn.fhir.jpa.dao.mdm;
/*-
* #%L
* HAPI FHIR JPA Server
* %%
* Copyright (C) 2014 - 2021 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

View File

@ -31,7 +31,6 @@ import ca.uhn.fhir.mdm.log.Logs;
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import ca.uhn.fhir.mdm.util.GoldenResourceHelper;
import ca.uhn.fhir.mdm.util.MdmResourceUtil;
import ca.uhn.fhir.mdm.util.TerserUtil;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.slf4j.Logger;

View File

@ -23,7 +23,7 @@ package ca.uhn.fhir.jpa.mdm.svc;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.mdm.api.IMdmSurvivorshipService;
import ca.uhn.fhir.mdm.model.MdmTransactionContext;
import ca.uhn.fhir.mdm.util.TerserUtil;
import ca.uhn.fhir.util.TerserUtil;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -4,9 +4,9 @@ import ca.uhn.fhir.jpa.entity.MdmLink;
import ca.uhn.fhir.mdm.api.MdmLinkSourceEnum;
import ca.uhn.fhir.mdm.api.MdmMatchResultEnum;
import ca.uhn.fhir.mdm.util.MdmResourceUtil;
import ca.uhn.fhir.mdm.util.TerserUtil;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.util.TerserUtil;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.StringType;
import org.junit.jupiter.api.BeforeEach;

View File

@ -1,147 +0,0 @@
package ca.uhn.fhir.mdm.util;
/*-
* #%L
* HAPI FHIR - Master Data Management
* %%
* Copyright (C) 2014 - 2021 Smile CDR, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import ca.uhn.fhir.context.BaseRuntimeChildDefinition;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.mdm.model.CanonicalEID;
import ca.uhn.fhir.util.FhirTerser;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.Logger;
import java.util.Collection;
import java.util.List;
import java.util.function.Predicate;
import static org.slf4j.LoggerFactory.getLogger;
@Deprecated
public final class TerserUtil {
private static final Logger ourLog = getLogger(TerserUtil.class);
public static final Collection<String> IDS_AND_META_EXCLUDES = ca.uhn.fhir.util.TerserUtil.IDS_AND_META_EXCLUDES;
public static final Predicate<String> EXCLUDE_IDS_AND_META = ca.uhn.fhir.util.TerserUtil.EXCLUDE_IDS_AND_META;
private TerserUtil() {
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void cloneEidIntoResource(FhirContext theFhirContext, BaseRuntimeChildDefinition theIdentifierDefinition, IBase theEid, IBase theResourceToCloneEidInto) {
ca.uhn.fhir.util.TerserUtil.cloneEidIntoResource(theFhirContext, theIdentifierDefinition, theEid, theResourceToCloneEidInto);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static boolean hasValues(FhirContext theFhirContext, IBaseResource theResource, String theFieldName) {
return ca.uhn.fhir.util.TerserUtil.hasValues(theFhirContext, theResource, theFieldName);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static List<IBase> getValues(FhirContext theFhirContext, IBaseResource theResource, String theFieldName) {
return ca.uhn.fhir.util.TerserUtil.getValues(theFhirContext, theResource, theFieldName);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void cloneCompositeField(FhirContext theFhirContext, IBaseResource theFrom, IBaseResource theTo, String field) {
ca.uhn.fhir.util.TerserUtil.cloneCompositeField(theFhirContext, theFrom, theTo, field);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void mergeAllFields(FhirContext theFhirContext, IBaseResource theFrom, IBaseResource theTo) {
ca.uhn.fhir.util.TerserUtil.mergeAllFields(theFhirContext, theFrom, theTo);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void replaceFields(FhirContext theFhirContext, IBaseResource theFrom, IBaseResource theTo, Predicate<String> inclusionStrategy) {
ca.uhn.fhir.util.TerserUtil.replaceFields(theFhirContext, theFrom, theTo, inclusionStrategy);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static boolean fieldExists(FhirContext theFhirContext, String theFieldName, IBaseResource theInstance) {
return ca.uhn.fhir.util.TerserUtil.fieldExists(theFhirContext, theFieldName, theInstance);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void replaceField(FhirContext theFhirContext, String theFieldName, IBaseResource theFrom, IBaseResource theTo) {
ca.uhn.fhir.util.TerserUtil.replaceField(theFhirContext, theFieldName, theFrom, theTo);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void replaceField(FhirContext theFhirContext, FhirTerser theTerser, String theFieldName, IBaseResource theFrom, IBaseResource theTo) {
ca.uhn.fhir.util.TerserUtil.replaceField(theFhirContext, theTerser, theFieldName, theFrom, theTo);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void mergeFieldsExceptIdAndMeta(FhirContext theFhirContext, IBaseResource theFrom, IBaseResource theTo) {
ca.uhn.fhir.util.TerserUtil.mergeFieldsExceptIdAndMeta(theFhirContext, theFrom, theTo);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void mergeFields(FhirContext theFhirContext, IBaseResource theFrom, IBaseResource theTo, Predicate<String> inclusionStrategy) {
ca.uhn.fhir.util.TerserUtil.mergeFields(theFhirContext, theFrom, theTo, inclusionStrategy);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void mergeField(FhirContext theFhirContext, String theFieldName, IBaseResource theFrom, IBaseResource theTo) {
ca.uhn.fhir.util.TerserUtil.mergeField(theFhirContext, theFieldName, theFrom, theTo);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static void mergeField(FhirContext theFhirContext, FhirTerser theTerser, String theFieldName, IBaseResource theFrom, IBaseResource theTo) {
ca.uhn.fhir.util.TerserUtil.mergeField(theFhirContext, theTerser, theFieldName, theFrom, theTo);
}
/**
* @deprecated Use {@link ca.uhn.fhir.util.TerserUtil} instead
*/
public static <T extends IBaseResource> T clone(FhirContext theFhirContext, T theInstance) {
return ca.uhn.fhir.util.TerserUtil.clone(theFhirContext, theInstance);
}
}

View File

@ -1,197 +0,0 @@
package ca.uhn.fhir.mdm.util;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.mdm.BaseR4Test;
import org.hl7.fhir.r4.model.DateTimeType;
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Identifier;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
class TerserUtilTest extends BaseR4Test {
@Test
void testCloneEidIntoResource() {
Identifier identifier = new Identifier().setSystem("http://org.com/sys").setValue("123");
Patient p1 = new Patient();
p1.addIdentifier(identifier);
Patient p2 = new Patient();
RuntimeResourceDefinition definition = ourFhirContext.getResourceDefinition(p1);
TerserUtil.cloneEidIntoResource(ourFhirContext, definition.getChildByName("identifier"), identifier, p2);
assertEquals(1, p2.getIdentifier().size());
assertEquals(p1.getIdentifier().get(0).getSystem(), p2.getIdentifier().get(0).getSystem());
assertEquals(p1.getIdentifier().get(0).getValue(), p2.getIdentifier().get(0).getValue());
}
@Test
void testFieldExists() {
assertTrue(TerserUtil.fieldExists(ourFhirContext, "identifier", new Patient()));
assertFalse(TerserUtil.fieldExists(ourFhirContext, "randomFieldName", new Patient()));
}
@Test
void testCloneFields() {
Patient p1 = buildJohny();
p1.addName().addGiven("Sigizmund");
p1.setId("Patient/22");
Patient p2 = new Patient();
TerserUtil.mergeFieldsExceptIdAndMeta(ourFhirContext, p1, p2);
assertTrue(p2.getIdentifier().isEmpty());
assertNull(p2.getId());
assertEquals(1, p2.getName().size());
assertEquals(p1.getName().get(0).getNameAsSingleString(), p2.getName().get(0).getNameAsSingleString());
}
@Test
void testCloneWithNonPrimitives() {
Patient p1 = new Patient();
Patient p2 = new Patient();
p1.addName().addGiven("Joe");
p1.getNameFirstRep().addGiven("George");
assertThat(p1.getName(), hasSize(1));
assertThat(p1.getName().get(0).getGiven(), hasSize(2));
p2.addName().addGiven("Jeff");
p2.getNameFirstRep().addGiven("George");
assertThat(p2.getName(), hasSize(1));
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
TerserUtil.mergeAllFields(ourFhirContext, p1, p2);
assertThat(p2.getName(), hasSize(2));
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
assertThat(p2.getName().get(1).getGiven(), hasSize(2));
}
@Test
void testMergeForAddressWithExtensions() {
Extension ext = new Extension();
ext.setUrl("http://hapifhir.io/extensions/address#create-timestamp");
ext.setValue(new DateTimeType("2021-01-02T11:13:15"));
Patient p1 = new Patient();
p1.addAddress()
.addLine("10 Main Street")
.setCity("Hamilton")
.setState("ON")
.setPostalCode("Z0Z0Z0")
.setCountry("Canada")
.addExtension(ext);
Patient p2 = new Patient();
p2.addAddress().addLine("10 Lenin Street").setCity("Severodvinsk").setCountry("Russia");
TerserUtil.mergeField(ourFhirContext,"address", p1, p2);
assertEquals(2, p2.getAddress().size());
assertEquals("[10 Lenin Street]", p2.getAddress().get(0).getLine().toString());
assertEquals("[10 Main Street]", p2.getAddress().get(1).getLine().toString());
assertTrue(p2.getAddress().get(1).hasExtension());
p1 = new Patient();
p1.addAddress().addLine("10 Main Street").addExtension(ext);
p2 = new Patient();
p2.addAddress().addLine("10 Main Street").addExtension(new Extension("demo", new DateTimeType("2021-01-02")));
TerserUtil.mergeField(ourFhirContext,"address", p1, p2);
assertEquals(2, p2.getAddress().size());
assertTrue(p2.getAddress().get(0).hasExtension());
assertTrue(p2.getAddress().get(1).hasExtension());
}
@Test
void testReplaceForAddressWithExtensions() {
Extension ext = new Extension();
ext.setUrl("http://hapifhir.io/extensions/address#create-timestamp");
ext.setValue(new DateTimeType("2021-01-02T11:13:15"));
Patient p1 = new Patient();
p1.addAddress()
.addLine("10 Main Street")
.setCity("Hamilton")
.setState("ON")
.setPostalCode("Z0Z0Z0")
.setCountry("Canada")
.addExtension(ext);
Patient p2 = new Patient();
p2.addAddress().addLine("10 Lenin Street").setCity("Severodvinsk").setCountry("Russia");
TerserUtil.replaceField(ourFhirContext,"address", p1, p2);
assertEquals(1, p2.getAddress().size());
assertEquals("[10 Main Street]", p2.getAddress().get(0).getLine().toString());
assertTrue(p2.getAddress().get(0).hasExtension());
}
@Test
void testMergeForSimilarAddresses() {
Extension ext = new Extension();
ext.setUrl("http://hapifhir.io/extensions/address#create-timestamp");
ext.setValue(new DateTimeType("2021-01-02T11:13:15"));
Patient p1 = new Patient();
p1.addAddress()
.addLine("10 Main Street")
.setCity("Hamilton")
.setState("ON")
.setPostalCode("Z0Z0Z0")
.setCountry("Canada")
.addExtension(ext);
Patient p2 = new Patient();
p2.addAddress()
.addLine("10 Main Street")
.setCity("Hamilton")
.setState("ON")
.setPostalCode("Z0Z0Z1")
.setCountry("Canada")
.addExtension(ext);
TerserUtil.mergeField(ourFhirContext,"address", p1, p2);
assertEquals(2, p2.getAddress().size());
assertEquals("[10 Main Street]", p2.getAddress().get(0).getLine().toString());
assertEquals("[10 Main Street]", p2.getAddress().get(1).getLine().toString());
assertTrue(p2.getAddress().get(1).hasExtension());
}
@Test
void testCloneWithDuplicateNonPrimitives() {
Patient p1 = new Patient();
Patient p2 = new Patient();
p1.addName().addGiven("Jim");
p1.getNameFirstRep().addGiven("George");
assertThat(p1.getName(), hasSize(1));
assertThat(p1.getName().get(0).getGiven(), hasSize(2));
p2.addName().addGiven("Jim");
p2.getNameFirstRep().addGiven("George");
assertThat(p2.getName(), hasSize(1));
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
TerserUtil.mergeAllFields(ourFhirContext, p1, p2);
assertThat(p2.getName(), hasSize(1));
assertThat(p2.getName().get(0).getGiven(), hasSize(2));
}
}