Added avc code to the interceptors
This commit is contained in:
parent
a1604c95c9
commit
418c1aa2c6
|
@ -38,6 +38,11 @@ public interface IAddressValidator {
|
||||||
*/
|
*/
|
||||||
public static final String ADDRESS_QUALITY_EXTENSION_URL = "http://hapifhir.org/StructureDefinition/ext-validation-address-quality";
|
public static final String ADDRESS_QUALITY_EXTENSION_URL = "http://hapifhir.org/StructureDefinition/ext-validation-address-quality";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URL for address verification extensions that may be added to addresses.
|
||||||
|
*/
|
||||||
|
public static final String ADDRESS_VERIFICATION_CODE_EXTENSION_URL = "http://hapifhir.org/StructureDefinition/ext-validation-address-verification";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* FHIR Geolocation extension URL
|
* FHIR Geolocation extension URL
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -21,7 +21,6 @@ package ca.uhn.fhir.rest.server.interceptor.validation.address.impl;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import ca.uhn.fhir.context.FhirContext;
|
import ca.uhn.fhir.context.FhirContext;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.validation.address.AddressValidationException;
|
|
||||||
import ca.uhn.fhir.rest.server.interceptor.validation.address.AddressValidationResult;
|
import ca.uhn.fhir.rest.server.interceptor.validation.address.AddressValidationResult;
|
||||||
import ca.uhn.fhir.rest.server.interceptor.validation.helpers.AddressHelper;
|
import ca.uhn.fhir.rest.server.interceptor.validation.helpers.AddressHelper;
|
||||||
import ca.uhn.fhir.util.ExtensionUtil;
|
import ca.uhn.fhir.util.ExtensionUtil;
|
||||||
|
@ -48,6 +47,9 @@ import java.util.Properties;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static ca.uhn.fhir.rest.server.interceptor.validation.address.IAddressValidator.ADDRESS_QUALITY_EXTENSION_URL;
|
||||||
|
import static ca.uhn.fhir.rest.server.interceptor.validation.address.IAddressValidator.ADDRESS_VERIFICATION_CODE_EXTENSION_URL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For more details regarind the API refer to
|
* For more details regarind the API refer to
|
||||||
* <a href="https://www.loqate.com/resources/support/cleanse-api/international-batch-cleanse/">
|
* <a href="https://www.loqate.com/resources/support/cleanse-api/international-batch-cleanse/">
|
||||||
|
@ -60,6 +62,7 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
|
||||||
|
|
||||||
public static final String PROPERTY_GEOCODE = "service.geocode";
|
public static final String PROPERTY_GEOCODE = "service.geocode";
|
||||||
public static final String LOQUATE_AQI = "AQI";
|
public static final String LOQUATE_AQI = "AQI";
|
||||||
|
public static final String LOQUATE_AVC = "AVC";
|
||||||
|
|
||||||
protected 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";
|
protected static final String DEFAULT_DATA_CLEANSE_ENDPOINT = "https://api.addressy.com/Cleansing/International/Batch/v1.00/json4.ws";
|
||||||
|
@ -102,17 +105,17 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValid(JsonNode theMatch) {
|
protected boolean isValid(JsonNode theMatch) {
|
||||||
String addressQualityIndex = getAqi(theMatch);
|
String addressQualityIndex = getField(theMatch, LOQUATE_AQI);
|
||||||
return "A".equals(addressQualityIndex) || "B".equals(addressQualityIndex);
|
return "A".equals(addressQualityIndex) || "B".equals(addressQualityIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAqi(JsonNode theMatch) {
|
private String getField(JsonNode theMatch, String theFieldName) {
|
||||||
String addressQualityIndex = null;
|
String field = null;
|
||||||
if (theMatch.has(LOQUATE_AQI)) {
|
if (theMatch.has(theFieldName)) {
|
||||||
addressQualityIndex = theMatch.get(LOQUATE_AQI).asText();
|
field = theMatch.get(theFieldName).asText();
|
||||||
}
|
}
|
||||||
ourLog.debug("Address quality index {}", addressQualityIndex);
|
ourLog.debug("Found {}={}", theFieldName, field);
|
||||||
return addressQualityIndex;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IBase toAddress(JsonNode match, FhirContext theFhirContext) {
|
protected IBase toAddress(JsonNode match, FhirContext theFhirContext) {
|
||||||
|
@ -136,21 +139,23 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
|
||||||
helper.setState(getString(match, "AdministrativeArea"));
|
helper.setState(getString(match, "AdministrativeArea"));
|
||||||
helper.setPostalCode(getString(match, "PostalCode"));
|
helper.setPostalCode(getString(match, "PostalCode"));
|
||||||
helper.setCountry(getString(match, "CountryName"));
|
helper.setCountry(getString(match, "CountryName"));
|
||||||
toQualityIndex(match, helper, theFhirContext);
|
addExtension(match, LOQUATE_AQI, ADDRESS_QUALITY_EXTENSION_URL, helper, theFhirContext);
|
||||||
|
addExtension(match, LOQUATE_AVC, ADDRESS_VERIFICATION_CODE_EXTENSION_URL, helper, theFhirContext);
|
||||||
|
|
||||||
return helper.getAddress();
|
return helper.getAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toQualityIndex(JsonNode theMatch, AddressHelper theHelper, FhirContext theFhirContext) {
|
private void addExtension(JsonNode theMatch, String theMatchField, String theExtUrl, AddressHelper theHelper, FhirContext theFhirContext) {
|
||||||
String addressQuality = getAqi(theMatch);
|
String addressQuality = getField(theMatch, theMatchField);
|
||||||
if (StringUtils.isEmpty(addressQuality)) {
|
if (StringUtils.isEmpty(addressQuality)) {
|
||||||
ourLog.debug("AQI is not provided on {}", theMatch);
|
ourLog.debug("{} is not found in {}", theMatchField, theMatch);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IBase address = theHelper.getAddress();
|
IBase address = theHelper.getAddress();
|
||||||
ExtensionUtil.clearExtensionsByUrl(address, ADDRESS_QUALITY_EXTENSION_URL);
|
ExtensionUtil.clearExtensionsByUrl(address, theExtUrl);
|
||||||
IBaseExtension addressQualityExt = ExtensionUtil.addExtension(address, ADDRESS_QUALITY_EXTENSION_URL);
|
|
||||||
|
IBaseExtension addressQualityExt = ExtensionUtil.addExtension(address, theExtUrl);
|
||||||
addressQualityExt.setValue(TerserUtil.newElement(theFhirContext, "string", addressQuality));
|
addressQualityExt.setValue(TerserUtil.newElement(theFhirContext, "string", addressQuality));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +222,7 @@ public class LoquateAddressValidator extends BaseRestfulValidator {
|
||||||
if (StringUtils.isEmpty(theText)) {
|
if (StringUtils.isEmpty(theText)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
theText = theText.replaceAll("\\s\\s", ", ");
|
theText = theText.replaceAll("\\s\\s", ", ");
|
||||||
Matcher m = myCommaPattern.matcher(theText);
|
Matcher m = myCommaPattern.matcher(theText);
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
|
|
|
@ -92,6 +92,7 @@ class LoquateAddressValidatorTest {
|
||||||
" \"Matches\": [\n" +
|
" \"Matches\": [\n" +
|
||||||
" {\n" +
|
" {\n" +
|
||||||
" \"AQI\": \"A\",\n" +
|
" \"AQI\": \"A\",\n" +
|
||||||
|
" \"AVC\": \"V44-I44-P6-100\",\n" +
|
||||||
" \"Address\": \"My Valid Address\",\n" +
|
" \"Address\": \"My Valid Address\",\n" +
|
||||||
" \"Latitude\": \"-32.94217742803439\",\n" +
|
" \"Latitude\": \"-32.94217742803439\",\n" +
|
||||||
" \"Longitude\": \"-60.640132034941836\"\n" +
|
" \"Longitude\": \"-60.640132034941836\"\n" +
|
||||||
|
@ -219,7 +220,7 @@ class LoquateAddressValidatorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccessfulResponsesWithGeocode() throws Exception {
|
public void testSuccessfulResponsesWithGeocodeAndQuality() throws Exception {
|
||||||
myValidator.getProperties().setProperty(PROPERTY_GEOCODE, "true");
|
myValidator.getProperties().setProperty(PROPERTY_GEOCODE, "true");
|
||||||
AddressValidationResult res = myValidator.getValidationResult(new AddressValidationResult(),
|
AddressValidationResult res = myValidator.getValidationResult(new AddressValidationResult(),
|
||||||
new ObjectMapper().readTree(RESPONSE_VALID_ADDRESS_W_GEO), ourCtx);
|
new ObjectMapper().readTree(RESPONSE_VALID_ADDRESS_W_GEO), ourCtx);
|
||||||
|
@ -235,6 +236,10 @@ class LoquateAddressValidatorTest {
|
||||||
IBaseExtension quality = ExtensionUtil.getExtensionByUrl(address, IAddressValidator.ADDRESS_QUALITY_EXTENSION_URL);
|
IBaseExtension quality = ExtensionUtil.getExtensionByUrl(address, IAddressValidator.ADDRESS_QUALITY_EXTENSION_URL);
|
||||||
assertNotNull(quality);
|
assertNotNull(quality);
|
||||||
assertEquals("A", quality.getValue().toString());
|
assertEquals("A", quality.getValue().toString());
|
||||||
|
|
||||||
|
IBaseExtension verificationCode = ExtensionUtil.getExtensionByUrl(address, IAddressValidator.ADDRESS_VERIFICATION_CODE_EXTENSION_URL);
|
||||||
|
assertNotNull(verificationCode);
|
||||||
|
assertEquals("V44-I44-P6-100", verificationCode.getValue().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue