From 6aa356056476caecc866d02c31cdc07b4d4a0c05 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Sat, 19 Jul 2014 12:10:43 -0400 Subject: [PATCH] Starting work on consolidating params --- .../ca/uhn/fhir/rest/gclient/StringParam.java | 45 ++++++++++++++++++- .../ca/uhn/fhir/rest/param/ParameterUtil.java | 26 +++++++++++ .../uhn/fhir/jpa/dao/FhirResourceDaoTest.java | 15 ++++++- 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/StringParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/StringParam.java index 342d7661ae8..9fda94c433e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/StringParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/StringParam.java @@ -20,15 +20,58 @@ package ca.uhn.fhir.rest.gclient; * #L% */ +import static org.apache.commons.lang3.StringUtils.*; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.rest.param.ParameterUtil; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; public class StringParam implements IParam { - private String myParamName; + private final String myParamName; + private final boolean myExact; + private List myValues; public StringParam(String theParamName) { myParamName = theParamName; + myExact=false; + myValues = null; + } + + /** + * Provides the list of string tokens supplied for this + * @return + */ + public List getValues() { + return myValues; + } + + public void setValues(List theValues) { + myValues = theValues; + } + + public boolean isExact() { + return myExact; + } + + public StringParam(String theParamName, String theQualifier, String theParamValue) { + myParamName = theParamName; + + if (Constants.PARAMQUALIFIER_STRING_EXACT.equals(theQualifier)) { + myExact = true; + }else if (isNotBlank(theQualifier)) { + throw new InvalidRequestException("Illegal parameter qualifier: " + theParamName + theQualifier); + }else { + myExact = false; + } + + myValues = Collections.unmodifiableList(ParameterUtil.splitParameterString(theParamValue)); + } /** diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java index 4f6439a4cce..e0ea0c3232c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/param/ParameterUtil.java @@ -324,4 +324,30 @@ public class ParameterUtil { }; } + + public static List splitParameterString(String theInput){ + ArrayList retVal = new ArrayList(); + if (theInput!=null) { + StringBuilder b = new StringBuilder(); + for (int i = 0; i < theInput.length(); i++) { + char next = theInput.charAt(i); + if (next == ',') { + if (i == 0 || theInput.charAt(i-1) != '\\') { + b.append(next); + } else { + if (b.length() > 0) { + retVal.add(b.toString()); + b.setLength(0); + } + } + } + } + if (b.length() > 0) { + retVal.add(b.toString()); + } + } + return retVal; + } + + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java index 38867b232dd..f4b90b41b3e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoTest.java @@ -47,6 +47,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.gclient.TokenParam; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.IdentifierListParam; import ca.uhn.fhir.rest.param.QualifiedDateParam; @@ -206,8 +207,9 @@ public class FhirResourceDaoTest { @Test public void testSearchTokenParam() { Patient patient = new Patient(); - patient.addIdentifier("urn:system", "testSearchTokenParam001"); + patient.addIdentifier().setSystem("urn:system").setValue("testSearchTokenParam001"); patient.addName().addFamily("Tester").addGiven("testSearchTokenParam1"); + patient.addCommunication().setText("testSearchTokenParamComText").addCoding().setCode("testSearchTokenParamCode").setSystem("testSearchTokenParamSystem").setDisplay("testSearchTokenParamDisplay"); ourPatientDao.create(patient); patient = new Patient(); @@ -227,6 +229,17 @@ public class FhirResourceDaoTest { IBundleProvider retrieved = ourPatientDao.search(map); assertEquals(1, retrieved.size()); } + { + SearchParameterMap map = new SearchParameterMap(); + map.add(Patient.SP_LANGUAGE, new IdentifierDt("testSearchTokenParamSystem", "testSearchTokenParamCode")); + assertEquals(1, ourPatientDao.search(map).size()); + } + { + SearchParameterMap map = new SearchParameterMap(); +// map.add(Patient.SP_LANGUAGE, new TokenParam(Patient.SP_LANGUAGE).exactly().systemAndCode("testSearchTokenParamSystem", "testSearchTokenParamCode")); +// map.add(Patient.SP_LANGUAGE, new IdentifierDt("testSearchTokenParamSystem", "testSearchTokenParamCode")); + assertEquals(1, ourPatientDao.search(map).size()); + } { SearchParameterMap map = new SearchParameterMap(); IdentifierListParam listParam = new IdentifierListParam();