@Override public Object invokeServer(IRestfulServer<?> theServer, RequestDetails theRequest) throws BaseServerResponseException, IOException { Object[] params = createParametersForServerRequest(theRequest); addParametersForServerRequest(theRequest, params); /* * No need to catch and handle exceptions here, we already handle them one level up including invoking interceptors * on them */ MethodOutcome response; Object methodReturn = invokeServerMethod(theServer, theRequest, params); if (methodReturn instanceof IBaseOperationOutcome) { response = new MethodOutcome(); response.setOperationOutcome((IBaseOperationOutcome) methodReturn); } else { response = (MethodOutcome) methodReturn; } if (response != null && response.getId() != null && response.getId().hasResourceType()) { if (getContext().getResourceDefinition(response.getId().getResourceType()) == null) { throw new InternalErrorException("Server method returned invalid resource ID: " + response.getId().getValue()); } } IBaseOperationOutcome outcome = response != null ? response.getOperationOutcome() : null; IBaseResource resource = response != null ? response.getResource() : null; return returnResponse(theServer, theRequest, response, outcome, resource); }
.execute(); if (Boolean.TRUE.equals(methodOutcome.getCreated())) { ourLog.info("Created new ConceptMap: {}", methodOutcome.getId().getValue()); } else { ourLog.info("Updated existing ConceptMap: {}", methodOutcome.getId().getValue()); .execute(); if (Boolean.TRUE.equals(methodOutcome.getCreated())) { ourLog.info("Created new ConceptMap: {}", methodOutcome.getId().getValue()); } else { ourLog.info("Updated existing ConceptMap: {}", methodOutcome.getId().getValue());
@Create public MethodOutcome create(@ResourceParam T theResource) { long idPart = myNextId++; String idPartAsString = Long.toString(idPart); Long versionIdPart = 1L; IIdType id = store(theResource, idPartAsString, versionIdPart); myCreateCount.incrementAndGet(); return new MethodOutcome() .setCreated(true) .setId(id); }
@Override public MethodOutcome invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException { IBaseResource response = myWrap.invokeClient(theResponseMimeType, theResponseInputStream, theResponseStatusCode, theHeaders); MethodOutcome retVal = new MethodOutcome(); retVal.setResource(response); retVal.setCreatedUsingStatusCode(theResponseStatusCode); retVal.setResponseHeaders(theHeaders); return retVal; } }
private Object toReturnType(IBaseResource resource) { Object retVal = null; switch (getMethodReturnType()) { case LIST_OF_RESOURCES: retVal = Collections.emptyList(); if (resource != null) { retVal = Collections.singletonList(resource); } break; case RESOURCE: retVal = resource; break; case BUNDLE_RESOURCE: retVal = resource; break; case METHOD_OUTCOME: MethodOutcome outcome = new MethodOutcome(); outcome.setOperationOutcome((IBaseOperationOutcome) resource); retVal = outcome; break; } return retVal; }
@Override public boolean enrichAuditDatasetFromResponse(GenericFhirAuditDataset auditDataset, Object response, AuditContext auditContext) { // Domain Resource in the request? Extract Patient ID and Sensitivity at this point if (response instanceof IDomainResource) { addResourceData(auditDataset, (T) response); } if (response instanceof MethodOutcome) { MethodOutcome methodOutcome = (MethodOutcome) response; if (methodOutcome.getCreated() != null && methodOutcome.getCreated()) { auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success); } if (methodOutcome.getOperationOutcome() != null) { super.enrichAuditDatasetFromResponse(auditDataset, methodOutcome.getOperationOutcome(), auditContext); } else { auditDataset.setEventOutcomeIndicator(EventOutcomeIndicator.Success); } if (methodOutcome.getResource() != null && methodOutcome.getResource() instanceof IDomainResource) { addResourceData(auditDataset, (T) methodOutcome.getResource()); } else if (methodOutcome.getId() != null) { auditDataset.setResourceId(methodOutcome.getId()); if (methodOutcome.getId().hasResourceType()) { auditDataset.setAffectedResourceType(methodOutcome.getId().getResourceType()); } } } return super.enrichAuditDatasetFromResponse(auditDataset, response, auditContext); }
private void addLocationHeader(RequestDetails theRequest, HttpServletResponse theResponse, MethodOutcome response, String headerLocation, String resourceName) { StringBuilder b = new StringBuilder(); b.append(theRequest.getFhirServerBase()); b.append('/'); b.append(resourceName); b.append('/'); b.append(response.getId().getIdPart()); if (response.getId().hasVersionIdPart()) { b.append("/" + Constants.PARAM_HISTORY + "/"); b.append(response.getId().getVersionIdPart()); } theResponse.addHeader(headerLocation, b.toString()); }
@Override public MethodOutcome invokeClient(String theResponseMimeType, InputStream theResponseInputStream, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException { MethodOutcome response = MethodUtil.process2xxResponse(myContext, theResponseStatusCode, theResponseMimeType, theResponseInputStream, theHeaders); response.setCreatedUsingStatusCode(theResponseStatusCode); if (myPrefer == PreferReturnEnum.REPRESENTATION) { if (response.getResource() == null) { if (response.getId() != null && isNotBlank(response.getId().getValue()) && response.getId().hasBaseUrl()) { ourLog.info("Server did not return resource for Prefer-representation, going to fetch: {}", response.getId().getValue()); IBaseResource resource = read().resource(response.getId().getResourceType()).withUrl(response.getId()).execute(); response.setResource(resource); } } } response.setResponseHeaders(theHeaders); return response; } }
MethodOutcome mo = new MethodOutcome(); parseContentLocation(getContext(), mo, locationHeader); if (mo.getId() == null || mo.getId().isEmpty()) { throw new InvalidRequestException("Invalid Content-Location header for resource " + getResourceName() + ": " + locationHeader);
IdDt id = (IdDt) outcome.getId(); System.out.println("Got ID: " + id.getValue()); Boolean created = outcome.getCreated(); IdDt id = (IdDt) outcome.getId(); OperationOutcome oo = (OperationOutcome) outcome.getOperationOutcome(); IdDt id = (IdDt) outcome.getId(); System.out.println("Got ID: " + id.getValue());
MethodOutcome retVal = new MethodOutcome(); retVal.setId(new IdType("Patient", "3746", "1")); retVal.setOperationOutcome(outcome);
if (response.getResource() != null) { restfulResponse.setOperationResourceLastUpdated(RestfulServerUtils.extractLastUpdatedFromResource(response.getResource())); IIdType responseId = response.getId(); if (responseId != null && responseId.getResourceType() == null && responseId.hasIdPart()) { responseId = responseId.withResourceType(getResourceName());
MethodOutcome retVal = new MethodOutcome(); if (locationHeaders.size() > 0) { String locationHeader = locationHeaders.get(0); IBaseResource outcome = parser.parseResource(reader); if (outcome instanceof IBaseOperationOutcome) { retVal.setOperationOutcome((IBaseOperationOutcome) outcome); } else { retVal.setResource(outcome);
MethodOutcome retVal = new MethodOutcome(); retVal.setCreated(true); retVal.setResource(theResource); return retVal;
@Update public MethodOutcome updatePatientPrefer( @ResourceParam Patient thePatient, @IdParam IdType theId) { // Save the patient to the database // Update the version and last updated time on the resource IdType updatedId = theId.withVersion("123"); thePatient.setId(updatedId); InstantType lastUpdated = InstantType.withCurrentTime(); thePatient.getMeta().setLastUpdatedElement(lastUpdated); // Add the resource to the outcome, so that it can be returned by the server // if the client requests it MethodOutcome outcome = new MethodOutcome(); outcome.setId(updatedId); outcome.setResource(thePatient); return outcome; } //END SNIPPET: updatePrefer
public MethodOutcome create(@ResourceParam Patient thePatient, RequestDetails theRequestDetails) { return new MethodOutcome(); // populate this }
throw new InternalErrorException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null, which is not allowed for create operation"); if (response.getCreated() == null || Boolean.TRUE.equals(response.getCreated())) { return Constants.STATUS_HTTP_201_CREATED; if (response == null || response.getCreated() == null || Boolean.FALSE.equals(response.getCreated())) { return Constants.STATUS_HTTP_200_OK; if (response.getOperationOutcome() == null) { return Constants.STATUS_HTTP_204_NO_CONTENT;
@Create public MethodOutcome create(@ResourceParam final Patient patient, @ConditionalUrlParam String theConditional) { // create the patient ... return new MethodOutcome(new IdDt(1L)).setCreated(true); }
@Delete public MethodOutcome delete(@IdParam IIdType theId) { TreeMap<Long, T> versions = myIdToVersionToResourceMap.get(theId.getIdPart()); if (versions == null || versions.isEmpty()) { throw new ResourceNotFoundException(theId); } long nextVersion = versions.lastEntry().getKey() + 1L; IIdType id = store(null, theId.getIdPart(), nextVersion); myDeleteCount.incrementAndGet(); return new MethodOutcome() .setId(id); }
public void setCreatedUsingStatusCode(int theResponseStatusCode) { if (theResponseStatusCode == Constants.STATUS_HTTP_201_CREATED) { setCreated(true); } } }