Updated address and field validation handling
This commit is contained in:
parent
961f16a1be
commit
902cd94ca2
|
@ -29,6 +29,9 @@ import ca.uhn.fhir.interceptor.api.Pointcut;
|
||||||
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.ConfigLoader;
|
import ca.uhn.fhir.rest.server.interceptor.ConfigLoader;
|
||||||
import ca.uhn.fhir.util.ExtensionUtil;
|
import ca.uhn.fhir.util.ExtensionUtil;
|
||||||
|
import ca.uhn.fhir.util.FhirTerser;
|
||||||
|
import ca.uhn.fhir.util.TerserUtil;
|
||||||
|
import ca.uhn.fhir.util.TerserUtilHelper;
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
import org.hl7.fhir.instance.model.api.IBase;
|
import org.hl7.fhir.instance.model.api.IBase;
|
||||||
import org.hl7.fhir.instance.model.api.IBaseResource;
|
import org.hl7.fhir.instance.model.api.IBaseResource;
|
||||||
|
@ -137,6 +140,8 @@ public class AddressValidatingInterceptor {
|
||||||
|
|
||||||
ExtensionUtil.setExtensionAsString(theFhirContext, theAddress, IAddressValidator.ADDRESS_VALIDATION_EXTENSION_URL,
|
ExtensionUtil.setExtensionAsString(theFhirContext, theAddress, IAddressValidator.ADDRESS_VALIDATION_EXTENSION_URL,
|
||||||
validationResult.isValid() ? IAddressValidator.EXT_VALUE_VALID : IAddressValidator.EXT_VALUE_INVALID);
|
validationResult.isValid() ? IAddressValidator.EXT_VALUE_VALID : IAddressValidator.EXT_VALUE_INVALID);
|
||||||
|
|
||||||
|
theFhirContext.newTerser().cloneInto(validationResult.getValidatedAddress(), theAddress, true);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ourLog.warn("Unable to validate address", ex);
|
ourLog.warn("Unable to validate address", ex);
|
||||||
ExtensionUtil.setExtensionAsString(theFhirContext, theAddress, IAddressValidator.ADDRESS_VALIDATION_EXTENSION_URL, IAddressValidator.EXT_UNABLE_TO_VALIDATE);
|
ExtensionUtil.setExtensionAsString(theFhirContext, theAddress, IAddressValidator.ADDRESS_VALIDATION_EXTENSION_URL, IAddressValidator.EXT_UNABLE_TO_VALIDATE);
|
||||||
|
|
|
@ -51,10 +51,9 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(LoquateAddressValidator.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(LoquateAddressValidator.class);
|
||||||
|
|
||||||
private static final String[] DUPLICATE_FIELDS_IN_ADDRESS_LINES = {"Locality", "AdministrativeArea", "PostalCode"};
|
protected static final String[] DUPLICATE_FIELDS_IN_ADDRESS_LINES = {"Locality", "AdministrativeArea", "PostalCode"};
|
||||||
|
protected static final String DEFAULT_DATA_CLEANSE_ENDPOINT = "https://api.addressy.com/Cleansing/International/Batch/v1.00/json4.ws";
|
||||||
private static final String DEFAULT_DATA_CLEANSE_ENDPOINT = "https://api.addressy.com/Cleansing/International/Batch/v1.00/json4.ws";
|
protected static final int MAX_ADDRESS_LINES = 8;
|
||||||
private static final int MAX_ADDRESS_LINES = 8;
|
|
||||||
|
|
||||||
public LoquateAddressValidator(Properties theProperties) {
|
public LoquateAddressValidator(Properties theProperties) {
|
||||||
super(theProperties);
|
super(theProperties);
|
||||||
|
|
|
@ -41,6 +41,8 @@ import java.util.Map;
|
||||||
@Interceptor
|
@Interceptor
|
||||||
public class FieldValidatingInterceptor {
|
public class FieldValidatingInterceptor {
|
||||||
|
|
||||||
|
public static final String FHIR_PATH_VALUE = "value";
|
||||||
|
|
||||||
public enum ValidatorType {
|
public enum ValidatorType {
|
||||||
EMAIL;
|
EMAIL;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +97,7 @@ public class FieldValidatingInterceptor {
|
||||||
List<IBase> fields = fhirPath.evaluate(theResource, e.getKey(), IBase.class);
|
List<IBase> fields = fhirPath.evaluate(theResource, e.getKey(), IBase.class);
|
||||||
for (IBase field : fields) {
|
for (IBase field : fields) {
|
||||||
|
|
||||||
List<IPrimitiveType> values = fhirPath.evaluate(field, "value", IPrimitiveType.class);
|
List<IPrimitiveType> values = fhirPath.evaluate(field, FHIR_PATH_VALUE, IPrimitiveType.class);
|
||||||
boolean isValid = true;
|
boolean isValid = true;
|
||||||
for (IPrimitiveType value : values) {
|
for (IPrimitiveType value : values) {
|
||||||
String valueAsString = value.getValueAsString();
|
String valueAsString = value.getValueAsString();
|
||||||
|
|
|
@ -94,6 +94,18 @@ class LoquateAddressValidatorTest {
|
||||||
myValidator = new LoquateAddressValidator(myProperties);
|
myValidator = new LoquateAddressValidator(myProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEndpointOverride() {
|
||||||
|
assertEquals(LoquateAddressValidator.DEFAULT_DATA_CLEANSE_ENDPOINT, myValidator.getApiEndpoint());
|
||||||
|
|
||||||
|
myProperties = new Properties();
|
||||||
|
myProperties.setProperty(LoquateAddressValidator.PROPERTY_SERVICE_KEY, "MY_KEY");
|
||||||
|
myProperties.setProperty(LoquateAddressValidator.PROPERTY_SERVICE_ENDPOINT, "HTTP://MY_ENDPOINT/LOQUATE");
|
||||||
|
myValidator = new LoquateAddressValidator(myProperties);
|
||||||
|
|
||||||
|
assertEquals("HTTP://MY_ENDPOINT/LOQUATE", myValidator.getApiEndpoint());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidInit() {
|
public void testInvalidInit() {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -86,7 +86,7 @@ class FieldValidatingInterceptorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomInvalidValidation() {
|
public void testCustomInvalidValidation() {
|
||||||
myInterceptor.getConfig().put("telecom.where(system='phone').value", "ClassThatDoesntExist");
|
myInterceptor.getConfig().put("telecom.where(system='phone')", "ClassThatDoesntExist");
|
||||||
try {
|
try {
|
||||||
myInterceptor.handleRequest(newRequestDetails(), new Person());
|
myInterceptor.handleRequest(newRequestDetails(), new Person());
|
||||||
fail();
|
fail();
|
||||||
|
@ -96,7 +96,7 @@ class FieldValidatingInterceptorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCustomValidation() {
|
public void testCustomValidation() {
|
||||||
myInterceptor.getConfig().put("telecom.where(system='phone').value", EmptyValidator.class.getName());
|
myInterceptor.getConfig().put("telecom.where(system='phone')", EmptyValidator.class.getName());
|
||||||
|
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
person.addTelecom().setSystem(ContactPoint.ContactPointSystem.EMAIL).setValue("email@email.com");
|
person.addTelecom().setSystem(ContactPoint.ContactPointSystem.EMAIL).setValue("email@email.com");
|
||||||
|
@ -118,8 +118,8 @@ class FieldValidatingInterceptorTest {
|
||||||
person.addTelecom().setSystem(ContactPoint.ContactPointSystem.PHONE).setValue(" ");
|
person.addTelecom().setSystem(ContactPoint.ContactPointSystem.PHONE).setValue(" ");
|
||||||
try {
|
try {
|
||||||
myInterceptor.handleRequest(newRequestDetails(), person);
|
myInterceptor.handleRequest(newRequestDetails(), person);
|
||||||
fail();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
fail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue