Fix web testing UI to handle CapabilityStatement correctly
This commit is contained in:
parent
964919d880
commit
2a94242f22
|
@ -29,6 +29,9 @@ import org.apache.http.client.methods.HttpRequestBase;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.entity.HttpEntityWrapper;
|
import org.apache.http.entity.HttpEntityWrapper;
|
||||||
import org.apache.http.message.BasicHeader;
|
import org.apache.http.message.BasicHeader;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent;
|
||||||
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestComponent;
|
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestComponent;
|
||||||
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceComponent;
|
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceComponent;
|
||||||
import org.hl7.fhir.dstu3.model.DecimalType;
|
import org.hl7.fhir.dstu3.model.DecimalType;
|
||||||
|
@ -48,6 +51,7 @@ import ca.uhn.fhir.model.api.IResource;
|
||||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||||
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
|
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
|
||||||
import ca.uhn.fhir.model.primitive.DecimalDt;
|
import ca.uhn.fhir.model.primitive.DecimalDt;
|
||||||
|
import ca.uhn.fhir.parser.IParser;
|
||||||
import ca.uhn.fhir.rest.client.GenericClient;
|
import ca.uhn.fhir.rest.client.GenericClient;
|
||||||
import ca.uhn.fhir.rest.client.IClientInterceptor;
|
import ca.uhn.fhir.rest.client.IClientInterceptor;
|
||||||
import ca.uhn.fhir.rest.client.apache.ApacheHttpRequest;
|
import ca.uhn.fhir.rest.client.apache.ApacheHttpRequest;
|
||||||
|
@ -449,21 +453,42 @@ public class BaseController {
|
||||||
CaptureInterceptor interceptor = new CaptureInterceptor();
|
CaptureInterceptor interceptor = new CaptureInterceptor();
|
||||||
GenericClient client = theRequest.newClient(theServletRequest, getContext(theRequest), myConfig, interceptor);
|
GenericClient client = theRequest.newClient(theServletRequest, getContext(theRequest), myConfig, interceptor);
|
||||||
|
|
||||||
org.hl7.fhir.dstu3.model.Conformance conformance;
|
org.hl7.fhir.dstu3.model.Conformance conformance = null;
|
||||||
|
org.hl7.fhir.dstu3.model.CapabilityStatement capabilityStatement = new CapabilityStatement();
|
||||||
try {
|
try {
|
||||||
conformance = client.fetchConformance().ofType(org.hl7.fhir.dstu3.model.Conformance.class).execute();
|
capabilityStatement = client.fetchConformance().ofType(org.hl7.fhir.dstu3.model.CapabilityStatement.class).execute();
|
||||||
} catch (Exception e) {
|
} catch (Exception ex) {
|
||||||
ourLog.warn("Failed to load conformance statement", e);
|
try {
|
||||||
theModel.put("errorMsg", "Failed to load conformance statement, error was: " + e.toString());
|
conformance = client.fetchConformance().ofType(org.hl7.fhir.dstu3.model.Conformance.class).execute();
|
||||||
conformance = new org.hl7.fhir.dstu3.model.Conformance();
|
} catch (Exception e) {
|
||||||
|
ourLog.warn("Failed to load conformance statement", e);
|
||||||
|
theModel.put("errorMsg", "Failed to load conformance statement, error was: " + e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
theModel.put("jsonEncodedConf", getContext(theRequest).newJsonParser().encodeResourceToString(conformance));
|
if (conformance != null) {
|
||||||
|
theModel.put("jsonEncodedConf", getContext(theRequest).newJsonParser().encodeResourceToString(conformance));
|
||||||
|
} else {
|
||||||
|
theModel.put("jsonEncodedConf", getContext(theRequest).newJsonParser().encodeResourceToString(capabilityStatement));
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, Number> resourceCounts = new HashMap<String, Number>();
|
Map<String, Number> resourceCounts = new HashMap<String, Number>();
|
||||||
long total = 0;
|
long total = 0;
|
||||||
for (ConformanceRestComponent nextRest : conformance.getRest()) {
|
|
||||||
for (ConformanceRestResourceComponent nextResource : nextRest.getResource()) {
|
if (conformance != null) {
|
||||||
|
for (ConformanceRestComponent nextRest : conformance.getRest()) {
|
||||||
|
for (ConformanceRestResourceComponent nextResource : nextRest.getResource()) {
|
||||||
|
List<Extension> exts = nextResource.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
||||||
|
if (exts != null && exts.size() > 0) {
|
||||||
|
Number nextCount = ((DecimalType) (exts.get(0).getValue())).getValueAsNumber();
|
||||||
|
resourceCounts.put(nextResource.getTypeElement().getValue(), nextCount);
|
||||||
|
total += nextCount.longValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CapabilityStatementRestComponent nextRest : capabilityStatement.getRest()) {
|
||||||
|
for (CapabilityStatementRestResourceComponent nextResource : nextRest.getResource()) {
|
||||||
List<Extension> exts = nextResource.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
List<Extension> exts = nextResource.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
||||||
if (exts != null && exts.size() > 0) {
|
if (exts != null && exts.size() > 0) {
|
||||||
Number nextCount = ((DecimalType) (exts.get(0).getValue())).getValueAsNumber();
|
Number nextCount = ((DecimalType) (exts.get(0).getValue())).getValueAsNumber();
|
||||||
|
@ -472,13 +497,38 @@ public class BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
theModel.put("resourceCounts", resourceCounts);
|
theModel.put("resourceCounts", resourceCounts);
|
||||||
|
|
||||||
if (total > 0) {
|
if (total > 0) {
|
||||||
for (ConformanceRestComponent nextRest : conformance.getRest()) {
|
if (conformance != null) {
|
||||||
Collections.sort(nextRest.getResource(), new Comparator<ConformanceRestResourceComponent>() {
|
for (ConformanceRestComponent nextRest : conformance.getRest()) {
|
||||||
|
Collections.sort(nextRest.getResource(), new Comparator<ConformanceRestResourceComponent>() {
|
||||||
|
@Override
|
||||||
|
public int compare(ConformanceRestResourceComponent theO1, ConformanceRestResourceComponent theO2) {
|
||||||
|
DecimalType count1 = new DecimalType();
|
||||||
|
List<Extension> count1exts = theO1.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
||||||
|
if (count1exts != null && count1exts.size() > 0) {
|
||||||
|
count1 = (DecimalType) count1exts.get(0).getValue();
|
||||||
|
}
|
||||||
|
DecimalType count2 = new DecimalType();
|
||||||
|
List<Extension> count2exts = theO2.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
||||||
|
if (count2exts != null && count2exts.size() > 0) {
|
||||||
|
count2 = (DecimalType) count2exts.get(0).getValue();
|
||||||
|
}
|
||||||
|
int retVal = count2.compareTo(count1);
|
||||||
|
if (retVal == 0) {
|
||||||
|
retVal = theO1.getTypeElement().getValue().compareTo(theO2.getTypeElement().getValue());
|
||||||
|
}
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CapabilityStatementRestComponent nextRest : capabilityStatement.getRest()) {
|
||||||
|
Collections.sort(nextRest.getResource(), new Comparator<CapabilityStatementRestResourceComponent>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ConformanceRestResourceComponent theO1, ConformanceRestResourceComponent theO2) {
|
public int compare(CapabilityStatementRestResourceComponent theO1, CapabilityStatementRestResourceComponent theO2) {
|
||||||
DecimalType count1 = new DecimalType();
|
DecimalType count1 = new DecimalType();
|
||||||
List<Extension> count1exts = theO1.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
List<Extension> count1exts = theO1.getExtensionsByUrl(RESOURCE_COUNT_EXT_URL);
|
||||||
if (count1exts != null && count1exts.size() > 0) {
|
if (count1exts != null && count1exts.size() > 0) {
|
||||||
|
@ -499,10 +549,15 @@ public class BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
theModel.put("conf", conformance);
|
|
||||||
theModel.put("requiredParamExtension", ExtensionConstants.PARAM_IS_REQUIRED);
|
theModel.put("requiredParamExtension", ExtensionConstants.PARAM_IS_REQUIRED);
|
||||||
|
|
||||||
return conformance;
|
if (conformance != null) {
|
||||||
|
theModel.put("conf", conformance);
|
||||||
|
return conformance;
|
||||||
|
}
|
||||||
|
|
||||||
|
theModel.put("conf", capabilityStatement);
|
||||||
|
return capabilityStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String logPrefix(ModelMap theModel) {
|
protected String logPrefix(ModelMap theModel) {
|
||||||
|
@ -556,7 +611,8 @@ public class BaseController {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processAndAddLastClientInvocation(GenericClient theClient, ResultType theResultType, ModelMap theModelMap, long theLatency, String outcomeDescription, CaptureInterceptor theInterceptor, HomeRequest theRequest) {
|
protected void processAndAddLastClientInvocation(GenericClient theClient, ResultType theResultType, ModelMap theModelMap, long theLatency, String outcomeDescription,
|
||||||
|
CaptureInterceptor theInterceptor, HomeRequest theRequest) {
|
||||||
try {
|
try {
|
||||||
ApacheHttpRequest lastRequest = theInterceptor.getLastRequest();
|
ApacheHttpRequest lastRequest = theInterceptor.getLastRequest();
|
||||||
HttpResponse lastResponse = theInterceptor.getLastResponse();
|
HttpResponse lastResponse = theInterceptor.getLastResponse();
|
||||||
|
|
|
@ -16,6 +16,10 @@ import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent;
|
||||||
|
import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent;
|
||||||
import org.hl7.fhir.dstu3.model.CodeType;
|
import org.hl7.fhir.dstu3.model.CodeType;
|
||||||
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestComponent;
|
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestComponent;
|
||||||
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceComponent;
|
import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceComponent;
|
||||||
|
@ -813,6 +817,10 @@ public class Controller extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean extractSearchParamsDstu3(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, List<List<String>> queryIncludes) {
|
private boolean extractSearchParamsDstu3(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, List<List<String>> queryIncludes) {
|
||||||
|
if (theConformance instanceof org.hl7.fhir.dstu3.model.CapabilityStatement) {
|
||||||
|
return extractSearchParamsDstu3CapabilityStatement(theConformance, resourceName, includes, theRevIncludes, sortParams, queries, haveSearchParams, queryIncludes);
|
||||||
|
}
|
||||||
|
|
||||||
org.hl7.fhir.dstu3.model.Conformance conformance = (org.hl7.fhir.dstu3.model.Conformance) theConformance;
|
org.hl7.fhir.dstu3.model.Conformance conformance = (org.hl7.fhir.dstu3.model.Conformance) theConformance;
|
||||||
for (ConformanceRestComponent nextRest : conformance.getRest()) {
|
for (ConformanceRestComponent nextRest : conformance.getRest()) {
|
||||||
for (ConformanceRestResourceComponent nextRes : nextRest.getResource()) {
|
for (ConformanceRestResourceComponent nextRes : nextRest.getResource()) {
|
||||||
|
@ -848,6 +856,42 @@ public class Controller extends BaseController {
|
||||||
return haveSearchParams;
|
return haveSearchParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean extractSearchParamsDstu3CapabilityStatement(IBaseResource theConformance, String resourceName, TreeSet<String> includes, TreeSet<String> theRevIncludes, TreeSet<String> sortParams, List<RestQuery> queries, boolean haveSearchParams, List<List<String>> queryIncludes) {
|
||||||
|
CapabilityStatement conformance = (org.hl7.fhir.dstu3.model.CapabilityStatement) theConformance;
|
||||||
|
for (CapabilityStatementRestComponent nextRest : conformance.getRest()) {
|
||||||
|
for (CapabilityStatementRestResourceComponent nextRes : nextRest.getResource()) {
|
||||||
|
if (nextRes.getTypeElement().getValue().equals(resourceName)) {
|
||||||
|
for (StringType next : nextRes.getSearchInclude()) {
|
||||||
|
if (next.isEmpty() == false) {
|
||||||
|
includes.add(next.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (CapabilityStatementRestResourceSearchParamComponent next : nextRes.getSearchParam()) {
|
||||||
|
if (next.getTypeElement().getValue() != org.hl7.fhir.dstu3.model.Enumerations.SearchParamType.COMPOSITE) {
|
||||||
|
sortParams.add(next.getNameElement().getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nextRes.getSearchParam().size() > 0) {
|
||||||
|
haveSearchParams = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// It's a different resource from the one we're searching, so
|
||||||
|
// scan for revinclude candidates
|
||||||
|
for (CapabilityStatementRestResourceSearchParamComponent next : nextRes.getSearchParam()) {
|
||||||
|
if (next.getTypeElement().getValue() == org.hl7.fhir.dstu3.model.Enumerations.SearchParamType.REFERENCE) {
|
||||||
|
// for (CodeType nextTargetType : next.getTarget()) {
|
||||||
|
// if (nextTargetType.getValue().equals(resourceName)) {
|
||||||
|
// theRevIncludes.add(nextRes.getTypeElement().getValue() + ":" + next.getName());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return haveSearchParams;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean handleSearchParam(String paramIdxString, HttpServletRequest theReq, IQuery<?> theQuery, JsonWriter theClientCodeJsonWriter) throws IOException {
|
private boolean handleSearchParam(String paramIdxString, HttpServletRequest theReq, IQuery<?> theQuery, JsonWriter theClientCodeJsonWriter) throws IOException {
|
||||||
String nextName = theReq.getParameter("param." + paramIdxString + ".name");
|
String nextName = theReq.getParameter("param." + paramIdxString + ".name");
|
||||||
if (isBlank(nextName)) {
|
if (isBlank(nextName)) {
|
||||||
|
|
|
@ -45,6 +45,11 @@ public class FhirTesterConfig {
|
||||||
.withBaseUrl("http://fhirtest.uhn.ca/baseDstu2")
|
.withBaseUrl("http://fhirtest.uhn.ca/baseDstu2")
|
||||||
.withName("Public HAPI Test Server")
|
.withName("Public HAPI Test Server")
|
||||||
.allowsApiKey()
|
.allowsApiKey()
|
||||||
|
.addServer()
|
||||||
|
.withId("home3")
|
||||||
|
.withFhirVersion(FhirVersionEnum.DSTU3)
|
||||||
|
.withBaseUrl("http://fhirtest.uhn.ca/baseDstu3")
|
||||||
|
.withName("Public HAPI Test Server (STU3)")
|
||||||
.addServer()
|
.addServer()
|
||||||
.withId("home")
|
.withId("home")
|
||||||
.withFhirVersion(FhirVersionEnum.DSTU2)
|
.withFhirVersion(FhirVersionEnum.DSTU2)
|
||||||
|
|
|
@ -163,7 +163,13 @@
|
||||||
</action>
|
</action>
|
||||||
<action type="add">
|
<action type="add">
|
||||||
ErrorHandler is now called (resulting in a warning by default, but can also be an exception) when arsing JSON if
|
ErrorHandler is now called (resulting in a warning by default, but can also be an exception) when arsing JSON if
|
||||||
the resource ID is not a JSON string, or an object is found where an array is expected (e.g. repeating field)
|
the resource ID is not a JSON string, or an object is found where an array is expected (e.g. repeating field). Thanks
|
||||||
|
to Jenni Syed of Cerner for providing a test case!
|
||||||
|
</action>
|
||||||
|
<action type="fix">
|
||||||
|
Fix Web Testing UI to be able to handle STU3 servers which
|
||||||
|
return CapabilityStatement instead of the previously used
|
||||||
|
"Conformance" resource
|
||||||
</action>
|
</action>
|
||||||
</release>
|
</release>
|
||||||
<release version="2.1" date="2016-11-11">
|
<release version="2.1" date="2016-11-11">
|
||||||
|
|
Loading…
Reference in New Issue