Coord extraction implemented

This commit is contained in:
Ken Stevens 2020-01-21 10:17:49 -05:00
parent c0e929dacb
commit dd137a0a30
3 changed files with 67 additions and 5 deletions

View File

@ -3467,6 +3467,23 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test {
assertThat(ids.toString(), ids, contains("Patient/AA", "Patient/AB", "Patient/BA", "Patient/BB"));
}
@Test
public void testNearSearch() {
Location loc = new Location();
double latitude = 1000.0;
double longitude = 2000.0;
Location.LocationPositionComponent position = new Location.LocationPositionComponent().setLatitude(latitude).setLongitude(longitude);
loc.setPosition(position);
IIdType locId = myLocationDao.create(loc).getId().toUnqualifiedVersionless();
SearchParameterMap map = new SearchParameterMap();
map.add(Location.SP_NEAR, new TokenParam(latitude + ":" + longitude));
map.add(Location.SP_NEAR_DISTANCE, new QuantityParam(10L));
List<String> ids = toUnqualifiedVersionlessIdValues(myLocationDao.search(map));
assertThat(ids, contains(locId));
}
private String toStringMultiline(List<?> theResults) {
StringBuilder b = new StringBuilder();
for (Object next : theResults) {

View File

@ -43,6 +43,7 @@ import ca.uhn.fhir.model.primitive.BoundCodeDt;
import ca.uhn.fhir.rest.api.RestSearchParameterTypeEnum;
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import org.apache.commons.lang3.ObjectUtils;
import org.hl7.fhir.dstu3.model.Location;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBase;
import org.hl7.fhir.instance.model.api.IBaseEnumeration;
@ -337,7 +338,16 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor
@Override
public SearchParamSet<ResourceIndexedSearchParamCoords> extractSearchParamCoords(IBaseResource theResource) {
return new SearchParamSet<>();
IExtractor<ResourceIndexedSearchParamCoords> extractor = (params, searchParam, value, path) -> {
if (value.getClass().equals(myLocationPositionDefinition.getImplementingClass())) {
String resourceType = toRootTypeName(theResource);
addCoords_Position(resourceType, params, searchParam, value);
} else {
addUnexpectedDatatypeWarning(params, searchParam, value);
}
};
return extractSearchParams(theResource, extractor, RestSearchParameterTypeEnum.TOKEN);
}
@Override
@ -403,10 +413,11 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor
public SearchParamSet<ResourceIndexedSearchParamQuantity> extractSearchParamQuantity(IBaseResource theResource) {
IExtractor<ResourceIndexedSearchParamQuantity> extractor = (params, searchParam, value, path) -> {
if (value.getClass().equals(myLocationPositionDefinition.getImplementingClass())) {
ourLog.warn("Position search not currently supported, not indexing location");
return;
}
// FIXME KHS
// if (value.getClass().equals(myLocationPositionDefinition.getImplementingClass())) {
// ourLog.warn("Position search not currently supported, not indexing location");
// return;
// }
String nextType = toRootTypeName(value);
String resourceType = toRootTypeName(theResource);
@ -711,6 +722,22 @@ public abstract class BaseSearchParamExtractor implements ISearchParamExtractor
}
// FIXME KHS split this class up
private void addCoords_Position(String theResourceType, SearchParamSet<ResourceIndexedSearchParamCoords> theParams, RuntimeSearchParam theSearchParam, IBase theValue) {
BigDecimal latitude = null;
BigDecimal longitude = null;
if (theValue instanceof Location.LocationPositionComponent) {
Location.LocationPositionComponent value = (Location.LocationPositionComponent) theValue;
latitude = value.getLatitude();
longitude = value.getLongitude();
}
// KHS we only accept coordinates when both are present
if (latitude != null && longitude != null) {
ResourceIndexedSearchParamCoords nextEntity = new ResourceIndexedSearchParamCoords(theResourceType, theSearchParam.getName(), latitude.doubleValue(), longitude.doubleValue());
theParams.add(nextEntity);
}
}
private void addString_HumanName(String theResourceType, Set<ResourceIndexedSearchParamString> theParams, RuntimeSearchParam theSearchParam, IBase theValue) {
List<String> families = extractValuesAsStrings(myHumanNameFamilyValueChild, theValue);
for (String next : families) {

View File

@ -185,6 +185,24 @@ public class SearchParamExtractorDstu3Test {
}
}
@Test
public void testParamCoords() {
Location loc = new Location();
double latitude = 1000.0;
double longitude = 2000.0;
Location.LocationPositionComponent position = new Location.LocationPositionComponent().setLatitude(latitude).setLongitude(longitude);
loc.setPosition(position);
ISearchParamRegistry searchParamRegistry = new MySearchParamRegistry();
SearchParamExtractorDstu3 extractor = new SearchParamExtractorDstu3(new ModelConfig(), ourCtx, ourValidationSupport, searchParamRegistry);
extractor.start();
Set<ResourceIndexedSearchParamCoords> coords = extractor.extractSearchParamCoords(loc);
assertEquals(1, coords.size());
ResourceIndexedSearchParamCoords coord = coords.iterator().next();
assertEquals(latitude, coord.getLatitude(), 0.0);
assertEquals(longitude, coord.getLongitude(), 0.0);
}
private static class MySearchParamRegistry implements ISearchParamRegistry {