respect status code set in providers
This commit is contained in:
parent
3e417ad0d1
commit
7fc2e461bf
|
@ -57,7 +57,6 @@ import org.hl7.fhir.instance.model.api.IIdType;
|
||||||
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
import org.hl7.fhir.instance.model.api.IPrimitiveType;
|
||||||
import org.hl7.fhir.r4.model.Identifier;
|
import org.hl7.fhir.r4.model.Identifier;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -262,7 +261,7 @@ public abstract class BaseJpaResourceProviderPatient<T extends IBaseResource> ex
|
||||||
@Operation(
|
@Operation(
|
||||||
name = ProviderConstants.OPERATION_MERGE,
|
name = ProviderConstants.OPERATION_MERGE,
|
||||||
canonicalUrl = "http://hl7.org/fhir/OperationDefinition/Patient-merge")
|
canonicalUrl = "http://hl7.org/fhir/OperationDefinition/Patient-merge")
|
||||||
public void patientMerge(
|
public IBaseParameters patientMerge(
|
||||||
HttpServletRequest theServletRequest,
|
HttpServletRequest theServletRequest,
|
||||||
HttpServletResponse theServletResponse,
|
HttpServletResponse theServletResponse,
|
||||||
ServletRequestDetails theRequestDetails,
|
ServletRequestDetails theRequestDetails,
|
||||||
|
@ -277,8 +276,7 @@ public abstract class BaseJpaResourceProviderPatient<T extends IBaseResource> ex
|
||||||
@OperationParam(name = ProviderConstants.OPERATION_MERGE_PREVIEW, typeName = "boolean", max = 1)
|
@OperationParam(name = ProviderConstants.OPERATION_MERGE_PREVIEW, typeName = "boolean", max = 1)
|
||||||
IPrimitiveType<Boolean> thePreview,
|
IPrimitiveType<Boolean> thePreview,
|
||||||
@OperationParam(name = ProviderConstants.OPERATION_MERGE_RESULT_PATIENT, max = 1)
|
@OperationParam(name = ProviderConstants.OPERATION_MERGE_RESULT_PATIENT, max = 1)
|
||||||
IBaseResource theResultPatient)
|
IBaseResource theResultPatient) {
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
startRequest(theServletRequest);
|
startRequest(theServletRequest);
|
||||||
try {
|
try {
|
||||||
|
@ -302,15 +300,8 @@ public abstract class BaseJpaResourceProviderPatient<T extends IBaseResource> ex
|
||||||
ParametersUtil.addParameterToParameters(fhirContext, retVal, "outcome", mergeOutcome.getOperationOutcome());
|
ParametersUtil.addParameterToParameters(fhirContext, retVal, "outcome", mergeOutcome.getOperationOutcome());
|
||||||
|
|
||||||
theServletResponse.setStatus(mergeOutcome.getHttpStatusCode());
|
theServletResponse.setStatus(mergeOutcome.getHttpStatusCode());
|
||||||
// TODO Emre: we are writing the response to directly, otherwise the response status we set above is
|
|
||||||
// ignored. CDA Import operation does it this way too, but what if the client requests xml response?
|
return retVal;
|
||||||
// there needs to be a better way to do this
|
|
||||||
theServletResponse.setContentType(Constants.CT_JSON);
|
|
||||||
fhirContext
|
|
||||||
.newJsonParser()
|
|
||||||
.setPrettyPrint(true)
|
|
||||||
.encodeResourceToWriter(retVal, theServletResponse.getWriter());
|
|
||||||
theServletResponse.getWriter().close();
|
|
||||||
} finally {
|
} finally {
|
||||||
endRequest(theServletRequest);
|
endRequest(theServletRequest);
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,16 +277,27 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi
|
||||||
When we write directly to an HttpServletResponse, the invocation returns null. However, we still want to invoke
|
When we write directly to an HttpServletResponse, the invocation returns null. However, we still want to invoke
|
||||||
the SERVER_OUTGOING_RESPONSE pointcut.
|
the SERVER_OUTGOING_RESPONSE pointcut.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// if the response status code is set by the method, respect it. Otherwise, use the default 200.
|
||||||
|
int responseCode = Constants.STATUS_HTTP_200_OK;
|
||||||
|
if (theRequest instanceof ServletRequestDetails) {
|
||||||
|
HttpServletResponse servletResponse = ((ServletRequestDetails) theRequest).getServletResponse();
|
||||||
|
if (servletResponse != null && servletResponse.getStatus() > 0) {
|
||||||
|
responseCode = servletResponse.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (response == null) {
|
if (response == null) {
|
||||||
ResponseDetails responseDetails = new ResponseDetails();
|
ResponseDetails responseDetails = new ResponseDetails();
|
||||||
responseDetails.setResponseCode(Constants.STATUS_HTTP_200_OK);
|
responseDetails.setResponseCode(responseCode);
|
||||||
callOutgoingResponseHook(theRequest, responseDetails);
|
callOutgoingResponseHook(theRequest, responseDetails);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
Set<SummaryEnum> summaryMode = RestfulServerUtils.determineSummaryMode(theRequest);
|
Set<SummaryEnum> summaryMode = RestfulServerUtils.determineSummaryMode(theRequest);
|
||||||
ResponseDetails responseDetails = new ResponseDetails();
|
ResponseDetails responseDetails = new ResponseDetails();
|
||||||
responseDetails.setResponseResource(response);
|
responseDetails.setResponseResource(response);
|
||||||
responseDetails.setResponseCode(Constants.STATUS_HTTP_200_OK);
|
responseDetails.setResponseCode(responseCode);
|
||||||
|
|
||||||
if (!callOutgoingResponseHook(theRequest, responseDetails)) {
|
if (!callOutgoingResponseHook(theRequest, responseDetails)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue