public MethodOutcome create(@ResourceParam Patient thePatient, RequestDetails theRequestDetails) { return new MethodOutcome(); // populate this }
@Create public MethodOutcome createPatientConditional( @ResourceParam Patient thePatient, @ConditionalUrlParam String theConditionalUrl) { if (theConditionalUrl != null) { // We are doing a conditional create // populate this with the ID of the existing resource which // matches the conditional URL return new MethodOutcome(); } else { // We are doing a normal create // populate this with the ID of the newly created resource return new MethodOutcome(); } } //END SNIPPET: createConditional
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; }
@Create public MethodOutcome createPatient(@ResourceParam Patient patient) { patient.setId(createId(counter, 1L)); patients.put(String.valueOf(counter), patient); return new MethodOutcome(patient.getIdElement()); }
@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); }
@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); }
@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; } }
@Override public MethodOutcome execute() { BaseHttpClientInvocation invocation = ValidateMethodBindingDstu2Plus.createValidateInvocation(myContext, myResource); ResourceResponseHandler<BaseOperationOutcome> handler = new ResourceResponseHandler<BaseOperationOutcome>(null, null); IBaseOperationOutcome outcome = invoke(null, handler, invocation); MethodOutcome retVal = new MethodOutcome(); retVal.setOperationOutcome(outcome); return retVal; }
@Update public MethodOutcome update(@IdParam IdType theId, @ResourceParam Patient thePatient) { String resourceId = theId.getIdPart(); String versionId = theId.getVersionIdPart(); // this will contain the ETag String currentVersion = "1"; // populate this with the current version if (!versionId.equals(currentVersion)) { throw new ResourceVersionConflictException("Expected version " + currentVersion); } // ... perform the update ... return new MethodOutcome(); } //END SNIPPET: updateEtag
@Update public MethodOutcome updatePatientConditional( @ResourceParam Patient thePatient, @IdParam IdType theId, @ConditionalUrlParam String theConditional) { // Only one of theId or theConditional will have a value and the other will be null, // depending on the URL passed into the server. if (theConditional != null) { // Do a conditional update. theConditional will have a value like "Patient?identifier=system%7C00001" } else { // Do a normal update. theId will have the identity of the resource to update } return new MethodOutcome(); // populate this } //END SNIPPET: updateConditional
@Create public MethodOutcome createPatientResource(@ResourceParam Patient thePatient) { // ..save the resouce.. IdType id = new IdType("123"); // the new databse primary key for this resource // Get the tag list List<Coding> tags = thePatient.getMeta().getTag(); for (Coding tag : tags) { // process/save each tag somehow } return new MethodOutcome(id); } //END SNIPPET: createTags
@Update public MethodOutcome updatePatientWithRawValue ( @ResourceParam Patient thePatient, @IdParam IdType theId, @ResourceParam String theRawBody, @ResourceParam EncodingEnum theEncodingEnum) { // Here, thePatient will have the parsed patient body, but // theRawBody will also have the raw text of the resource // being created, and theEncodingEnum will tell you which // encoding was used return new MethodOutcome(); // populate this } //END SNIPPET: updateRaw
/** * @param theConditional This is provided only so that subclasses can implement if they want */ @Update public MethodOutcome update( @ResourceParam T theResource, @ConditionalUrlParam String theConditional) { ValidateUtil.isTrueOrThrowInvalidRequest(isBlank(theConditional), "This server doesn't support conditional update"); String idPartAsString = theResource.getIdElement().getIdPart(); TreeMap<Long, T> versionToResource = getVersionToResource(idPartAsString); Long versionIdPart; boolean created; if (versionToResource.isEmpty()) { versionIdPart = 1L; created = true; } else { versionIdPart = versionToResource.lastKey() + 1L; created = false; } IIdType id = store(theResource, idPartAsString, versionIdPart); myUpdateCount.incrementAndGet(); return new MethodOutcome() .setCreated(created) .setId(id); }
@Create public MethodOutcome create(@ResourceParam final Patient patient, @ConditionalUrlParam String theConditional) { // create the patient ... return new MethodOutcome(new IdDt(1L)).setCreated(true); }
MethodOutcome retVal = new MethodOutcome(); retVal.setCreated(true); retVal.setResource(theResource);
@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
MethodOutcome mo = new MethodOutcome(); parseContentLocation(getContext(), mo, locationHeader); if (mo.getId() == null || mo.getId().isEmpty()) {
@Validate public MethodOutcome validatePatient(@ResourceParam Patient thePatient, @Validate.Mode ValidationModeEnum theMode, @Validate.Profile String theProfile) { // Actually do our validation: The UnprocessableEntityException // results in an HTTP 422, which is appropriate for business rule failure if (thePatient.getIdentifierFirstRep().isEmpty()) { /* It is also possible to pass an OperationOutcome resource * to the UnprocessableEntityException if you want to return * a custom populated OperationOutcome. Otherwise, a simple one * is created using the string supplied below. */ throw new UnprocessableEntityException("No identifier supplied"); } // This method returns a MethodOutcome object MethodOutcome retVal = new MethodOutcome(); // You may also add an OperationOutcome resource to return // This part is optional though: OperationOutcome outcome = new OperationOutcome(); outcome.addIssue().setSeverity(IssueSeverity.WARNING).setDiagnostics("One minor issue detected"); retVal.setOperationOutcome(outcome); return retVal; } //END SNIPPET: validate
MethodOutcome retVal = new MethodOutcome(); retVal.setId(new IdType("Patient", "3746", "1"));
@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); }