Fix fhirweb diff template error (#4721)
* Add test to check template returned is not empty * Check operation is diff so web template does not error * Refactor for clarity * add changelog --------- Co-authored-by: David Chen <david.chen@smilecdr.com>
This commit is contained in:
parent
e500b23fe6
commit
89cb179116
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 4721
|
||||
title: "Previously, clicking the '$diff' button on FHIRweb module would direct the user to an empty page. Now it
|
||||
displays the correct page."
|
|
@ -485,6 +485,8 @@ public class BaseController {
|
|||
} else if (theResultType == ResultType.BUNDLE) {
|
||||
resultDescription.append("JSON bundle");
|
||||
riBundle = context.newJsonParser().parseResource(resultBody);
|
||||
} else if (theResultType == ResultType.PARAMETERS) {
|
||||
resultDescription.append("JSON parameters");
|
||||
}
|
||||
break;
|
||||
case XML:
|
||||
|
@ -494,6 +496,8 @@ public class BaseController {
|
|||
} else if (theResultType == ResultType.BUNDLE) {
|
||||
resultDescription.append("XML bundle");
|
||||
riBundle = context.newXmlParser().parseResource(resultBody);
|
||||
} else if (theResultType == ResultType.PARAMETERS) {
|
||||
resultDescription.append("XML parameters");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -549,7 +553,7 @@ public class BaseController {
|
|||
}
|
||||
|
||||
protected enum ResultType {
|
||||
BUNDLE, NONE, RESOURCE, TAGLIST
|
||||
BUNDLE, NONE, RESOURCE, TAGLIST, PARAMETERS
|
||||
}
|
||||
|
||||
public static class CaptureInterceptor implements IClientInterceptor {
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.springframework.ui.ModelMap;
|
|||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
@ -52,8 +53,10 @@ import java.io.StringWriter;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import static ca.uhn.fhir.rest.server.provider.ProviderConstants.DIFF_OPERATION_NAME;
|
||||
import static ca.uhn.fhir.util.UrlUtil.sanitizeUrlPart;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
|
||||
import static org.apache.commons.lang3.StringUtils.defaultString;
|
||||
|
@ -622,7 +625,7 @@ public class Controller extends BaseController {
|
|||
Class<? extends IBaseParameters> parametersType = (Class<? extends IBaseParameters>) getContext(theRequest).getResourceDefinition("Parameters").getImplementingClass();
|
||||
|
||||
StopWatch sw = new StopWatch();
|
||||
ResultType returnsResource = ResultType.BUNDLE;
|
||||
ResultType returnsResource = getReturnedTypeBasedOnOperation(operationName);
|
||||
try {
|
||||
client
|
||||
.operation()
|
||||
|
@ -646,6 +649,9 @@ public class Controller extends BaseController {
|
|||
return "result";
|
||||
}
|
||||
|
||||
private static ResultType getReturnedTypeBasedOnOperation(@Nullable String operationName) {
|
||||
return DIFF_OPERATION_NAME.equals(operationName) ? ResultType.PARAMETERS : ResultType.BUNDLE;
|
||||
}
|
||||
|
||||
|
||||
private void doActionHistory(HttpServletRequest theReq, HomeRequest theRequest, BindingResult theBindingResult, ModelMap theModel, String theMethod, String theMethodDescription) {
|
||||
|
|
|
@ -28,9 +28,12 @@ import org.eclipse.jetty.servlet.ServletHolder;
|
|||
import org.hl7.fhir.instance.model.api.IIdType;
|
||||
import org.hl7.fhir.r4.model.Bundle;
|
||||
import org.hl7.fhir.r4.model.Composition;
|
||||
import org.hl7.fhir.r4.model.Enumerations;
|
||||
import org.hl7.fhir.r4.model.HumanName;
|
||||
import org.hl7.fhir.r4.model.IdType;
|
||||
import org.hl7.fhir.r4.model.InstantType;
|
||||
import org.hl7.fhir.r4.model.OperationOutcome;
|
||||
import org.hl7.fhir.r4.model.Parameters;
|
||||
import org.hl7.fhir.r4.model.Patient;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
@ -195,6 +198,40 @@ public class WebTest {
|
|||
assertThat(summaryPage.asNormalizedText(), containsString("\"diagnostics\": \"VALIDATION FAILURE\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvokeCustomOperation_Diff() throws IOException {
|
||||
registerAndUpdatePatient();
|
||||
|
||||
HtmlPage searchResultPage = searchForPatients();
|
||||
HtmlTable controlsTable = searchResultPage.getHtmlElementById("resultControlsTable");
|
||||
List<HtmlTableRow> controlRows = controlsTable.getBodies().get(0).getRows();
|
||||
HtmlTableCell controlsCell = controlRows.get(0).getCell(0);
|
||||
|
||||
HtmlPage diffPage = controlsCell
|
||||
.getElementsByTagName("button")
|
||||
.stream()
|
||||
.filter(t -> t.asNormalizedText().equals("$diff"))
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.click();
|
||||
|
||||
assertThat(diffPage.asNormalizedText(), containsString("\"resourceType\": \"Parameters\""));
|
||||
}
|
||||
|
||||
private void registerAndUpdatePatient() {
|
||||
Patient p = new Patient();
|
||||
Patient p2 = new Patient();
|
||||
HumanName humanName = new HumanName();
|
||||
humanName.addGiven("Yui");
|
||||
humanName.setFamily("Hirasawa");
|
||||
p2.getName().add(humanName);
|
||||
p.setId("Patient/A");
|
||||
p.getMeta().setLastUpdatedElement(new InstantType("2022-01-01T12:12:12.000Z"));
|
||||
p.setActive(true);
|
||||
IIdType iid = ourPatientProvider.store(p);
|
||||
ourFhirServer.getFhirClient().update().resource(p2).withId(iid).execute();
|
||||
}
|
||||
|
||||
private HtmlPage searchForPatients() throws IOException {
|
||||
// Load home page
|
||||
HtmlPage page = myWebClient.getPage("http://localhost/");
|
||||
|
@ -238,6 +275,12 @@ public class WebTest {
|
|||
throw new PreconditionFailedException("failure", oo);
|
||||
}
|
||||
|
||||
@Operation(name = "diff", typeName = "Patient", idempotent = true)
|
||||
public Parameters diff(@IdParam IIdType theId) {
|
||||
Parameters parameters = new Parameters();
|
||||
return parameters;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class MyServletContextHandler extends ServletContextHandler {
|
||||
|
|
|
@ -31,6 +31,7 @@ public class WebTestFhirTesterConfig {
|
|||
.withBaseUrl("http://localhost:8000")
|
||||
.withName("Localhost Server")
|
||||
.withSearchResultRowOperation("$summary", id -> "Patient".equals(id.getResourceType()))
|
||||
.withSearchResultRowOperation("$diff", id -> id.isVersionIdPartValidLong() && id.getVersionIdPartAsLong() > 1)
|
||||
.withSearchResultRowOperation("$validate", id -> true)
|
||||
.enableDebugTemplates();
|
||||
return retVal;
|
||||
|
|
Loading…
Reference in New Issue