Starting work on consolidating params

This commit is contained in:
jamesagnew 2014-07-19 12:10:43 -04:00
parent 84af486d51
commit 6aa3560564
3 changed files with 84 additions and 2 deletions

View File

@ -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<String> myValues;
public StringParam(String theParamName) {
myParamName = theParamName;
myExact=false;
myValues = null;
}
/**
* Provides the list of string tokens supplied for this
* @return
*/
public List<String> getValues() {
return myValues;
}
public void setValues(List<String> 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));
}
/**

View File

@ -324,4 +324,30 @@ public class ParameterUtil {
};
}
public static List<String> splitParameterString(String theInput){
ArrayList<String> retVal = new ArrayList<String>();
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;
}
}

View File

@ -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();