From 7905e9d9186cee7a80335907799abb32a94b6b62 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Fri, 6 Mar 2015 09:53:50 -0500 Subject: [PATCH] Add support for quantity search params in tester UI --- .../.settings/org.eclipse.jdt.core.prefs | 6 +- .../main/java/ca/uhn/fhir/to/Controller.java | 50 ++- .../WEB-INF/hapi-fhir-tester-config.xml | 2 +- .../webapp/WEB-INF/templates/resource.html | 1 + .../src/main/webapp/js/RestfulTester.js | 322 ++++++++++-------- .../ca/uhn/fhir/jpa/test/OverlayTestApp.java | 11 +- src/changes/changes.xml | 7 +- 7 files changed, 250 insertions(+), 149 deletions(-) diff --git a/hapi-fhir-jpaserver-base/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-jpaserver-base/.settings/org.eclipse.jdt.core.prefs index 42246e57dab..d535869bf65 100644 --- a/hapi-fhir-jpaserver-base/.settings/org.eclipse.jdt.core.prefs +++ b/hapi-fhir-jpaserver-base/.settings/org.eclipse.jdt.core.prefs @@ -7,9 +7,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -97,4 +97,4 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.6 +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java index fabc1701bc6..ed39a577546 100644 --- a/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java +++ b/hapi-fhir-testpage-overlay/src/main/java/ca/uhn/fhir/to/Controller.java @@ -64,6 +64,9 @@ import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.gclient.ICreateTyped; import ca.uhn.fhir.rest.gclient.IQuery; import ca.uhn.fhir.rest.gclient.IUntypedQuery; +import ca.uhn.fhir.rest.gclient.NumberClientParam.IMatches; +import ca.uhn.fhir.rest.gclient.QuantityClientParam; +import ca.uhn.fhir.rest.gclient.QuantityClientParam.IAndUnits; import ca.uhn.fhir.rest.gclient.StringClientParam; import ca.uhn.fhir.rest.gclient.TokenClientParam; import ca.uhn.fhir.rest.server.Constants; @@ -961,12 +964,17 @@ public class Controller { List values; boolean addToWhere = true; if ("token".equals(nextType)) { - if (isBlank(parts.get(2))) { + if (isBlank(parts.get(1))) { return true; } - values = Collections.singletonList(StringUtils.join(parts, "")); addToWhere = false; - theQuery.where(new TokenClientParam(nextName + nextQualifier).exactly().systemAndCode(parts.get(0), parts.get(2))); + if (isBlank(parts.get(0))) { + values = Collections.singletonList(parts.get(1)); + theQuery.where(new TokenClientParam(nextName + nextQualifier).exactly().code(parts.get(1))); + } else { + values = Collections.singletonList(parts.get(0) + "|" + parts.get(1)); + theQuery.where(new TokenClientParam(nextName + nextQualifier).exactly().systemAndCode(parts.get(0), parts.get(1))); + } } else if ("date".equals(nextType)) { values = new ArrayList(); if (isNotBlank(parts.get(1))) { @@ -975,6 +983,42 @@ public class Controller { if (isNotBlank(parts.get(3))) { values.add(StringUtils.join(parts.get(2), parts.get(3))); } + if (values.isEmpty()) { + return true; + } + } else if ("quantity".equals(nextType)) { + values = new ArrayList(); + addToWhere = false; + + QuantityClientParam param = new QuantityClientParam(nextName); + IMatches matcher; + if ("~".equals(parts.get(0))) { + matcher = param.approximately(); + } else if ("=".equals(parts.get(0))) { + matcher = param.exactly(); + } else if (">=".equals(parts.get(0))) { + matcher = param.greaterThanOrEquals(); + } else if ("<=".equals(parts.get(0))) { + matcher = param.lessThanOrEquals(); + } else if (">".equals(parts.get(0))) { + matcher = param.greaterThan(); + } else if ("<".equals(parts.get(0))) { + matcher = param.lessThan(); + } else { + throw new Error("Unknown qualifier: " + parts.get(0)); + } + IAndUnits number = matcher.number(parts.get(1)); + + if (isBlank(parts.get(3))) { + theQuery.where(number.andNoUnits()); + } else if (isBlank(parts.get(2))) { + theQuery.where(number.andUnits(parts.get(3))); + } else { + theQuery.where(number.andUnits(parts.get(2), parts.get(3))); + } + + values.add(parts.get(0) + parts.get(1) + "|" + parts.get(2) + "|" + parts.get(3)); + if (values.isEmpty()) { return true; } diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml index 532ffeca6f4..c0fb3ef2ed0 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/hapi-fhir-tester-config.xml @@ -12,7 +12,7 @@ home , DSTU1 , Localhost Server DSTU1 , http://localhost:8887/fhir/contextDstu1 - home_dev , DEV , Localhost Server DEV , http://localhost:8887/fhir/contextDev + home_d2 , DSTU2 , Localhost Server DSTU2 , http://localhost:8887/fhir/contextDstu2 hi , DSTU1 , Health Intersections , http://fhir.healthintersections.com.au/open furore , DSTU1 , Spark - Furore Reference Server , http://spark.furore.com/fhir blaze , DSTU1 , Blaze (Orion Health) , https://fhir.orionhealth.com/blaze/fhir diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/resource.html b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/resource.html index 421944f1c77..fe677e6e7b4 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/resource.html +++ b/hapi-fhir-testpage-overlay/src/main/webapp/WEB-INF/templates/resource.html @@ -113,6 +113,7 @@ }); $("#outerForm").attr("action", "search").submit(); }); + $('#search-btn').button('reset');
diff --git a/hapi-fhir-testpage-overlay/src/main/webapp/js/RestfulTester.js b/hapi-fhir-testpage-overlay/src/main/webapp/js/RestfulTester.js index 035251568eb..6510aa7d7f4 100644 --- a/hapi-fhir-testpage-overlay/src/main/webapp/js/RestfulTester.js +++ b/hapi-fhir-testpage-overlay/src/main/webapp/js/RestfulTester.js @@ -61,123 +61,120 @@ function updateSearchDateQualifier(qualifierBtn, qualifierInput, qualifier) { } function addSearchControls(theConformance, theSearchParamType, theSearchParamName, theSearchParamChain, theSearchParamTarget, theContainerRowNum, theRowNum) { - + var addNameAndType = true; - if (theSearchParamType == 'id') { - $('#search-param-rowopts-' + theContainerRowNum).append( - $('
', { 'class': 'col-sm-3' }).append( + if (theSearchParamType == 'id') { + $('#search-param-rowopts-' + theContainerRowNum).append( + $('
', { 'class': 'col-sm-3' }).append( $('', { id: 'param.' + theRowNum + '.0', placeholder: 'id', type: 'text', 'class': 'form-control' }) ) - ); - } else if (theSearchParamType == 'token') { - $('#search-param-rowopts-' + theContainerRowNum).append( - $('
', { 'class': 'col-sm-3' }).append( - $('', { id: 'param.' + theRowNum + '.0', placeholder: 'system/namespace', type: 'text', 'class': 'form-control' }) + ); + } else if (theSearchParamType == 'token') { + $('#search-param-rowopts-' + theContainerRowNum).append( + $('
', { 'class': 'col-sm-3' }).append( + $('', { id: 'param.' + theRowNum + '.0', placeholder: 'system/namespace', type: 'text', 'class': 'form-control' }) ), - $('
', { 'class': 'col-sm-3' }).append( - $('', { id: 'param.' + theRowNum + '.1', type: 'hidden', value: '|' }), - $('', { id: 'param.' + theRowNum + '.2', placeholder: 'value', type: 'text', 'class': 'form-control' }) + $('
', { 'class': 'col-sm-3' }).append( + $('', { id: 'param.' + theRowNum + '.1', placeholder: 'value', type: 'text', 'class': 'form-control' }) ) - ); - } else if (theSearchParamType == 'string') { - var placeholderText = 'value'; - var qualifiers = new Array(); - qualifiers.push(new Object()); - qualifiers[0].name='Matches'; - qualifiers[0].value=''; - qualifiers.push(new Object()); - qualifiers[1].name='Exactly'; - qualifiers[1].value=':exact'; - - var qualifierInput = $('', { id: 'param.' + theRowNum + '.qualifier', type: 'hidden' }); - $('#search-param-rowopts-' + theContainerRowNum).append( - qualifierInput - ); - - var matchesLabel = $('' + qualifiers[0].name + ''); - var qualifierDropdown = $('
    ', {'class':'dropdown-menu', role:'menu'}); - for (var i = 0; i < qualifiers.length; i++) { - var nextLink = $('' + qualifiers[i].name+''); - var qualName = qualifiers[i].name; - var nextValue = qualifiers[i].value; - qualifierDropdown.append($('
  • ').append(nextLink)); - nextLink.click(function(){ - qualifierInput.val(nextValue); - matchesLabel.text(qualName); - }); - } - - $('#search-param-rowopts-' + theContainerRowNum).append( - $('
    ', { 'class': 'col-sm-5 input-group' }).append( - $('
    ', {'class':'input-group-btn'}).append( - $('