From d45972abed601f99d0ce4b61e325138a04b65ee8 Mon Sep 17 00:00:00 2001 From: Nick Goupinets Date: Thu, 29 Apr 2021 11:46:09 -0400 Subject: [PATCH] Added geo accuracy code --- .../interceptor/validation/address/IAddressValidator.java | 5 +++++ .../validation/address/impl/LoquateAddressValidator.java | 4 ++++ .../validation/address/impl/LoquateAddressValidatorTest.java | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/IAddressValidator.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/IAddressValidator.java index ca47076ec79..571535a9687 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/IAddressValidator.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/IAddressValidator.java @@ -38,6 +38,11 @@ public interface IAddressValidator { */ public static final String ADDRESS_QUALITY_EXTENSION_URL = "http://hapifhir.org/StructureDefinition/ext-validation-address-quality"; + /** + * URL for an optional geocoding accuracy extensions that may be added to addresses. + */ + public static final String ADDRESS_GEO_ACCURACY_EXTENSION_URL = "http://hapifhir.org/StructureDefinition/ext-validation-address-geo-accuracy"; + /** * URL for an optional address verification extensions that may be added to addresses. */ diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidator.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidator.java index 563cf2af0b7..59e74ff89e7 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidator.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidator.java @@ -43,6 +43,7 @@ import org.springframework.http.ResponseEntity; import javax.annotation.Nullable; import java.math.BigDecimal; +import java.util.Arrays; import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -63,6 +64,7 @@ public class LoquateAddressValidator extends BaseRestfulValidator { public static final String PROPERTY_GEOCODE = "service.geocode"; public static final String LOQUATE_AQI = "AQI"; public static final String LOQUATE_AVC = "AVC"; + public static final String LOQUATE_GEO_ACCURACY = "GeoAccuracy"; 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"; @@ -139,8 +141,10 @@ public class LoquateAddressValidator extends BaseRestfulValidator { helper.setState(getString(match, "AdministrativeArea")); helper.setPostalCode(getString(match, "PostalCode")); helper.setCountry(getString(match, "CountryName")); + addExtension(match, LOQUATE_AQI, ADDRESS_QUALITY_EXTENSION_URL, helper, theFhirContext); addExtension(match, LOQUATE_AVC, ADDRESS_VERIFICATION_CODE_EXTENSION_URL, helper, theFhirContext); + addExtension(match, LOQUATE_GEO_ACCURACY, ADDRESS_GEO_ACCURACY_EXTENSION_URL, helper, theFhirContext); return helper.getAddress(); } diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidatorTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidatorTest.java index e09a37178af..7f7f3f73721 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidatorTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/validation/address/impl/LoquateAddressValidatorTest.java @@ -93,6 +93,7 @@ class LoquateAddressValidatorTest { " {\n" + " \"AQI\": \"A\",\n" + " \"AVC\": \"V44-I44-P6-100\",\n" + + " \"GeoAccuracy\": \"Z1\",\n" + " \"Address\": \"My Valid Address\",\n" + " \"Latitude\": \"-32.94217742803439\",\n" + " \"Longitude\": \"-60.640132034941836\"\n" + @@ -240,6 +241,10 @@ class LoquateAddressValidatorTest { IBaseExtension verificationCode = ExtensionUtil.getExtensionByUrl(address, IAddressValidator.ADDRESS_VERIFICATION_CODE_EXTENSION_URL); assertNotNull(verificationCode); assertEquals("V44-I44-P6-100", verificationCode.getValue().toString()); + + IBaseExtension geoAccuracy = ExtensionUtil.getExtensionByUrl(address, IAddressValidator.ADDRESS_GEO_ACCURACY_EXTENSION_URL); + assertNotNull(geoAccuracy); + assertEquals("Z1", geoAccuracy.getValue().toString()); } @Test