本文整理汇总了Java中ca.uhn.fhir.rest.api.MethodOutcome类的典型用法代码示例。如果您正苦于以下问题:Java MethodOutcome类的具体用法?Java MethodOutcome怎么用?Java MethodOutcome使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodOutcome类属于ca.uhn.fhir.rest.api包,在下文中一共展示了MethodOutcome类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updatePatient
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Update
public MethodOutcome updatePatient(HttpServletRequest theRequest, @ResourceParam Patient patient, @IdParam IdType theId,@ConditionalUrlParam String theConditional, RequestDetails theRequestDetails) {
log.debug("Update Patient Provider called");
MethodOutcome method = new MethodOutcome();
method.setCreated(true);
OperationOutcome opOutcome = new OperationOutcome();
method.setOperationOutcome(opOutcome);
Patient newPatient = null;
try {
newPatient = patientDao.update(ctx, patient, theId, theConditional);
} catch (Exception ex) {
log.error(ex.getMessage());
method.setId(newPatient.getIdElement());
method.setResource(newPatient);
}
log.debug("called update Patient method");
return method;
}
示例2: createPatient
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Create
public MethodOutcome createPatient(HttpServletRequest theRequest, @ResourceParam Patient patient) {
log.debug("Update Patient Provider called");
MethodOutcome method = new MethodOutcome();
method.setCreated(true);
OperationOutcome opOutcome = new OperationOutcome();
method.setOperationOutcome(opOutcome);
Patient newPatient = null;
try {
newPatient = patientDao.update(ctx, patient, null,null);
method.setId(newPatient.getIdElement());
method.setResource(newPatient);
} catch (Exception ex) {
log.error(ex.getMessage());
}
log.debug("called create Patient method");
return method;
}
示例3: updatePatient
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
/**
* The "@Update" annotation indicates that this method supports replacing an existing
* resource (by ID) with a new instance of that resource.
*
* @param theId
* This is the ID of the patient to update
* @param thePatient
* This is the actual resource to save
* @return This method returns a "MethodOutcome"
*/
@Update()
public MethodOutcome updatePatient(@IdParam IdType theId, @ResourceParam Patient thePatient) {
validateResource(thePatient);
Long id;
try {
id = theId.getIdPartAsLong();
} catch (DataFormatException e) {
throw new InvalidRequestException("Invalid ID " + theId.getValue() + " - Must be numeric");
}
/*
* Throw an exception (HTTP 404) if the ID is not known
*/
if (!myIdToPatientVersions.containsKey(id)) {
throw new ResourceNotFoundException(theId);
}
addNewVersion(thePatient, id);
return new MethodOutcome();
}
示例4: main
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
public static void main(String[] theArgs) {
Patient pat = new Patient();
pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J");
pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135");
pat.setGender(AdministrativeGender.MALE);
// Create a context
FhirContext ctx = FhirContext.forDstu3();
// Create a client
String serverBaseUrl = "http://fhirtest.uhn.ca/baseDstu3";
IGenericClient client = ctx.newRestfulGenericClient(serverBaseUrl);
// Use the client to store a new resource instance
MethodOutcome outcome = client
.create()
.resource(pat)
.execute();
// Print the ID of the newly created resource
System.out.println(outcome.getId());
}
示例5: main
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
public static void main(String[] theArgs) {
// Create a client
IGenericClient client = FhirContext.forDstu3().newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");
// Register some interceptors
client.registerInterceptor(new CookieInterceptor("mycookie=Chips Ahoy"));
client.registerInterceptor(new LoggingInterceptor());
// Read a Patient
Patient patient = client.read().resource(Patient.class).withId("example").execute();
// Change the gender
patient.setGender(patient.getGender() == AdministrativeGender.MALE ? AdministrativeGender.FEMALE : AdministrativeGender.MALE);
// Update the patient
MethodOutcome outcome = client.update().resource(patient).execute();
System.out.println("Now have ID: " + outcome.getId());
}
示例6: createPatientConditional
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@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();
}
}
示例7: updatePatientConditional
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Update
public MethodOutcome updatePatientConditional(
@ResourceParam Patient thePatient,
@IdParam IdDt 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
}
示例8: validatePatient
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Validate
public MethodOutcome validatePatient(@ResourceParam Patient thePatient) {
// 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(IssueSeverityEnum.WARNING).setDetails("One minor issue detected");
retVal.setOperationOutcome(outcome);
return retVal;
}
示例9: create
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Override
public MethodOutcome create(IResource theResource) {
BaseHttpClientInvocation invocation = MethodUtil.createCreateInvocation(theResource, myContext);
if (isKeepResponses()) {
myLastRequest = invocation.asHttpRequest(getServerBase(), createExtraParams(), getEncoding());
}
RuntimeResourceDefinition def = myContext.getResourceDefinition(theResource);
final String resourceName = def.getName();
OutcomeResponseHandler binding = new OutcomeResponseHandler(resourceName);
MethodOutcome resp = invokeClient(myContext, binding, invocation, myLogRequestAndResponse);
return resp;
}
示例10: addLocationHeader
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
private void addLocationHeader(Request theRequest, HttpServletResponse theResponse, MethodOutcome response, String headerLocation) {
StringBuilder b = new StringBuilder();
b.append(theRequest.getFhirServerBase());
b.append('/');
b.append(getResourceName());
b.append('/');
b.append(response.getId().getIdPart());
if (response.getId().hasVersionIdPart()) {
b.append("/" + Constants.PARAM_HISTORY + "/");
b.append(response.getId().getVersionIdPart());
} else if (response.getVersionId() != null && response.getVersionId().isEmpty() == false) {
b.append("/" + Constants.PARAM_HISTORY + "/");
b.append(response.getVersionId().getValue());
}
theResponse.addHeader(headerLocation, b.toString());
}
示例11: invokeClient
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Override
public MethodOutcome invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException, BaseServerResponseException {
switch (theResponseStatusCode) {
case Constants.STATUS_HTTP_200_OK:
case Constants.STATUS_HTTP_201_CREATED:
case Constants.STATUS_HTTP_204_NO_CONTENT:
if (myReturnVoid) {
return null;
}
MethodOutcome retVal = MethodUtil.process2xxResponse(getContext(), getResourceName(), theResponseStatusCode, theResponseMimeType, theResponseReader, theHeaders);
return retVal;
default:
throw processNon2xxResponseAndReturnExceptionToThrow(theResponseStatusCode, theResponseMimeType, theResponseReader);
}
}
示例12: parseContentLocation
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
protected static void parseContentLocation(MethodOutcome theOutcomeToPopulate, String theResourceName, String theLocationHeader) {
if (StringUtils.isBlank(theLocationHeader)) {
return;
}
theOutcomeToPopulate.setId(new IdDt(theLocationHeader));
String resourceNamePart = "/" + theResourceName + "/";
int resourceIndex = theLocationHeader.lastIndexOf(resourceNamePart);
if (resourceIndex > -1) {
int idIndexStart = resourceIndex + resourceNamePart.length();
int idIndexEnd = theLocationHeader.indexOf('/', idIndexStart);
if (idIndexEnd == -1) {
// nothing
} else {
String versionIdPart = "/_history/";
int historyIdStart = theLocationHeader.indexOf(versionIdPart, idIndexEnd);
if (historyIdStart != -1) {
theOutcomeToPopulate.setVersionId(new IdDt(theLocationHeader.substring(historyIdStart + versionIdPart.length())));
}
}
}
}
示例13: testCreateWithResourceResponse
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
/**
* Some servers (older ones?) return the resourcde you created instead of an OperationOutcome. We just need to ignore it.
*/
@Test
public void testCreateWithResourceResponse() throws Exception {
Patient patient = new Patient();
patient.addIdentifier("urn:foo", "123");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ctx.newXmlParser().encodeResourceToString(patient)), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.createPatient(patient);
assertEquals(HttpPost.class, capt.getValue().getClass());
HttpPost post = (HttpPost) capt.getValue();
assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient"));
assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue());
assertEquals("200", response.getId().getVersionIdPart());
}
示例14: testDelete
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Test
public void testDelete() throws Exception {
OperationOutcome oo = new OperationOutcome();
oo.addIssue().setDetails("Hello");
String resp = new FhirContext().newXmlParser().encodeResourceToString(oo);
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8")));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.deletePatient(new IdDt("1234"));
assertEquals(HttpDelete.class, capt.getValue().getClass());
assertEquals("http://foo/Patient/1234", capt.getValue().getURI().toString());
assertEquals("Hello", response.getOperationOutcome().getIssueFirstRep().getDetailsElement().getValue());
}
示例15: testUpdate
import ca.uhn.fhir.rest.api.MethodOutcome; //导入依赖的package包/类
@Test
public void testUpdate() throws Exception {
Patient patient = new Patient();
patient.addIdentifier("urn:foo", "123");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8"));
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200"));
ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo");
MethodOutcome response = client.updatePatient(new IdDt("100"), patient);
assertEquals(HttpPut.class, capt.getValue().getClass());
HttpPut post = (HttpPut) capt.getValue();
assertThat(post.getURI().toASCIIString(), StringEndsWith.endsWith("/Patient/100"));
assertThat(IOUtils.toString(post.getEntity().getContent()), StringContains.containsString("<Patient"));
assertEquals("http://example.com/fhir/Patient/100/_history/200", response.getId().getValue());
assertEquals("200", response.getId().getVersionIdPart());
assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, capt.getAllValues().get(0).getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue());
}