1 package ca.uhn.fhir.rest.gclient;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.List;
24
25 import org.apache.commons.lang3.StringUtils;
26
27 import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
28 import ca.uhn.fhir.rest.param.ParameterUtil;
29
30 class TokenCriterion implements ICriterion<TokenClientParam>, ICriterionInternal {
31
32 private String myValue;
33 private String myName;
34
35 public TokenCriterion(String theName, String theSystem, String theCode) {
36 myName = theName;
37 myValue=toValue(theSystem, theCode);
38 }
39
40 private String toValue(String theSystem, String theCode) {
41 String system = ParameterUtil.escape(theSystem);
42 String code = ParameterUtil.escape(theCode);
43 String value;
44 if (StringUtils.isNotBlank(system)) {
45 value = system + "|" + StringUtils.defaultString(code);
46 } else if (system == null) {
47 value = StringUtils.defaultString(code);
48 } else {
49 value = "|" + StringUtils.defaultString(code);
50 }
51 return value;
52 }
53
54 public TokenCriterion(String theParamName, List<IdentifierDt> theValue) {
55 myName=theParamName;
56 StringBuilder b = new StringBuilder();
57 for (IdentifierDt next : theValue) {
58 if (next.getSystem().isEmpty() && next.getValue().isEmpty()) {
59 continue;
60 }
61 if (b.length() > 0) {
62 b.append(',');
63 }
64 b.append(toValue(next.getSystem().getValueAsString(), next.getValue().getValue()));
65 }
66 myValue = b.toString();
67 }
68
69 @Override
70 public String getParameterValue() {
71 return myValue;
72 }
73
74 @Override
75 public String getParameterName() {
76 return myName;
77 }
78
79 }