public async Task <IActionResult> Delete(string ResourceName, string id) { System.Diagnostics.Debug.WriteLine("DELETE: " + this.Request.GetDisplayUrl()); var buri = this.CalculateBaseURI("{ResourceName}"); var Inputs = GetInputs(buri); if (ResourceName == "AuditEvent") { // depends on the AuditEvent, if was created by the server, then it will get an unauthorized exception report // otherwise externally reported events can be updated! //throw new FhirServerException(HttpStatusCode.MethodNotAllowed, "Cannot DELETE a AuditEvent"); } IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri)); string deletedIdentity = await model.Delete(id, null); // Request.Properties.Add(Const.ResourceIdentityKey, deletedIdentity); if (!string.IsNullOrEmpty(deletedIdentity)) { ResourceIdentity ri = new ResourceIdentity(deletedIdentity); return(FhirObjectResult.FhirDeletedResult(ri.VersionId)); } return(FhirObjectResult.FhirDeletedResult()); // for an OperationOutcome return would need to return accepted }
public async Task <IActionResult> Delete(string ResourceName) { System.Diagnostics.Debug.WriteLine("DELETE: " + this.Request.GetDisplayUrl()); var buri = this.CalculateBaseURI("{ResourceName}"); var Inputs = GetInputs(buri); if (Request.TupledParameters(false).Count() == 0) { var oo = new OperationOutcome() { Text = Utility.CreateNarative("Precondition Error") }; oo.Issue = new List <OperationOutcome.IssueComponent> { new OperationOutcome.IssueComponent() { Details = new CodeableConcept(null, null, "Conditionally deleting a " + ResourceName + " requires parameters"), Severity = OperationOutcome.IssueSeverity.Fatal } }; return(new FhirObjectResult(HttpStatusCode.BadRequest, oo)); } if (ResourceName == "AuditEvent") { // depends on the AuditEvent, if was created by the server, then it will get an unauthorized exception report // otherwise externally reported events can be updated! //throw new FhirServerException(HttpStatusCode.MethodNotAllowed, "Cannot DELETE a AuditEvent"); } IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri)); string ifMatch = Request.RequestUri().Query; if (ifMatch.StartsWith("?")) { ifMatch = ifMatch.Substring(1); } string deletedIdentity = await model.Delete(null, ifMatch); // Request.Properties.Add(Const.ResourceIdentityKey, deletedIdentity); if (!string.IsNullOrEmpty(deletedIdentity)) { ResourceIdentity ri = new ResourceIdentity(deletedIdentity); return(FhirObjectResult.FhirDeletedResult(ri.VersionId)); } return(FhirObjectResult.FhirDeletedResult()); // for an OperationOutcome return would need to return accepted }
public async Task <IActionResult> Put(string ResourceName, [FromBody] Resource bodyResource) { System.Diagnostics.Debug.WriteLine("PUT: " + this.Request.GetDisplayUrl()); var buri = this.CalculateBaseURI("{ResourceName}"); if (String.IsNullOrEmpty(this.Request.RequestUri().Query)) { throw new FhirServerException(HttpStatusCode.BadRequest, "Conditional updates not supported without query parameters"); } if (!String.IsNullOrEmpty(bodyResource.Id)) { // This is a conditional update, so clear the Id on the record // so that it doesn't accidentally get processed bodyResource.Id = null; } var Inputs = GetInputs(buri); OperationOutcome so = new OperationOutcome(); if (ResourceName == "AuditEvent") { // depends on the AuditEvent, if was created by the server, then it will get an unauthorized exception report // otherwise externally reported events can be updated! //throw new FhirServerException(HttpStatusCode.MethodNotAllowed, "Cannot PUT a AuditEvent, you must POST them"); } // so.Success(); IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri)); string ifMatch = null; var conditionalSearchParams = this.Request.TupledParameters(false); if (conditionalSearchParams.Count() > 0) { ifMatch = this.Request.RequestUri().Query; } var result = await model.Create(bodyResource, ifMatch, null, null); // if (bodyResource is Binary) // this.Request.SaveEntry(bodyResource); result.ResourceBase = new Uri(buri); var actualResource = result; // Check the prefer header if (Request.Headers.ContainsKey("Prefer")) { string preferHeader = Request.Header("Prefer"); if (preferHeader != null && preferHeader.ToLower() == "return=operationoutcome") { if (!(result is OperationOutcome)) { so = new OperationOutcome() { Text = Utility.CreateNarative("Resource update") }; so.Text.Status = Narrative.NarrativeStatus.Generated; so.Issue = new List <OperationOutcome.IssueComponent> { new OperationOutcome.IssueComponent() { Severity = OperationOutcome.IssueSeverity.Information, Code = OperationOutcome.IssueType.Informational, Details = new CodeableConcept(null, null, "Update was completed") } }; result = so; } } } FhirObjectResult returnMessage; if (bodyResource.Annotation <CreateOrUpate>() == CreateOrUpate.Create) { returnMessage = new FhirObjectResult(HttpStatusCode.Created, result, actualResource); } else { returnMessage = new FhirObjectResult(HttpStatusCode.OK, result, actualResource); } // Check the prefer header if (Request.Headers.ContainsKey("Prefer")) { string preferHeader = Request.Header("Prefer"); if (preferHeader != null && preferHeader.ToLower() == "return=minimal") { returnMessage.Value = null; } } return(returnMessage); }
public async Task <IActionResult> Put(string ResourceName, string id, [FromBody] Resource bodyResource) { System.Diagnostics.Debug.WriteLine("PUT: " + this.Request.GetDisplayUrl()); var buri = this.CalculateBaseURI("{ResourceName}"); if (!Id.IsValidValue(id)) { throw new FhirServerException(HttpStatusCode.BadRequest, "ID [" + id + "] is not a valid FHIR Resource ID"); } var Inputs = GetInputs(buri); bodyResource.Id = id; if (ResourceName == "AuditEvent") { // depends on the AuditEvent, if was created by the server, then it will get an unauthorized exception report // otherwise externally reported events can be updated! //throw new FhirServerException(HttpStatusCode.MethodNotAllowed, "Cannot PUT a AuditEvent, you must POST them"); } IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri)); var result = await model.Create(bodyResource, null, null, null); // this.Request.SaveEntry(bodyResource); result.ResourceBase = new Uri(buri); var actualResource = result; ResourceIdentity ri = null; if (result is Bundle) { ri = result.ResourceIdentity(result.ResourceBase); } else if (!(result is OperationOutcome) && !string.IsNullOrEmpty(result.Id)) { ri = result.ResourceIdentity(result.ResourceBase); } // Check the prefer header if (Request.Headers.ContainsKey("Prefer")) { string preferHeader = Request.Header("Prefer"); if (preferHeader != null && preferHeader.ToLower() == "return=operationoutcome") { if (!(result is OperationOutcome)) { OperationOutcome so = new OperationOutcome() { Text = Utility.CreateNarative("Resource update") }; so.Text.Status = Narrative.NarrativeStatus.Generated; so.Issue = new List <OperationOutcome.IssueComponent> { new OperationOutcome.IssueComponent() { Severity = OperationOutcome.IssueSeverity.Information, Code = OperationOutcome.IssueType.Informational, Details = new CodeableConcept(null, null, "Update was completed") } }; result = so; } } } FhirObjectResult returnMessage; if (bodyResource.Annotation <CreateOrUpate>() == CreateOrUpate.Create) { returnMessage = new FhirObjectResult(HttpStatusCode.Created, result, actualResource); } else { returnMessage = new FhirObjectResult(HttpStatusCode.OK, result, actualResource); } // Check the prefer header if (Request.Headers.ContainsKey("Prefer")) { string preferHeader = Request.Header("Prefer"); if (preferHeader != null && preferHeader.ToLower() == "return=minimal") { returnMessage.Value = null; } } return(returnMessage); }
public async Task <IActionResult> Post(string ResourceName, [FromBody] Resource bodyResource) { System.Diagnostics.Debug.WriteLine("POST: " + this.Request.GetDisplayUrl()); var buri = this.CalculateBaseURI("{ResourceName}"); if (bodyResource == null) { var oo = new OperationOutcome() { Text = Utility.CreateNarative("Validation Error"), // Contained = new List<Resource> { bodyResource } // Can't attach a null resource! }; oo.Issue = new List <OperationOutcome.IssueComponent> { new OperationOutcome.IssueComponent() { Details = new CodeableConcept(null, null, "Missing " + ResourceName + " resource POST"), Severity = OperationOutcome.IssueSeverity.Fatal } }; return(new BadRequestObjectResult(oo) { StatusCode = (int)HttpStatusCode.BadRequest }); } if (!String.IsNullOrEmpty(bodyResource.Id)) { var oo = new OperationOutcome() { Text = Utility.CreateNarative("Validation Error"), Contained = new List <Resource> { bodyResource } }; oo.Issue = new List <OperationOutcome.IssueComponent> { new OperationOutcome.IssueComponent() { Details = new CodeableConcept(null, null, "ID must be empty for POST"), Severity = OperationOutcome.IssueSeverity.Fatal } }; return(new BadRequestObjectResult(oo) { StatusCode = (int)HttpStatusCode.BadRequest }); } var Inputs = GetInputs(buri); IFhirResourceServiceSTU3 model = GetResourceModel(ResourceName, GetInputs(buri)); var result = await model.Create(bodyResource, null, null, null); // this.Request.SaveEntry(bodyResource); result.ResourceBase = new Uri(buri); var actualResource = result; ResourceIdentity ri = null; if (result is Bundle) { ri = result.ResourceIdentity(result.ResourceBase); } else if (!(result is OperationOutcome) && !string.IsNullOrEmpty(result.Id)) { ri = result.ResourceIdentity(result.ResourceBase); } // Check the prefer header if (Request.Headers.ContainsKey("Prefer")) { string preferHeader = Request.Header("Prefer"); if (preferHeader != null && preferHeader.ToLower() == "return=operationoutcome") { if (!(result is OperationOutcome)) { OperationOutcome so = new OperationOutcome() { Text = Utility.CreateNarative("Resource update") }; so.Text.Status = Narrative.NarrativeStatus.Generated; so.Issue = new List <OperationOutcome.IssueComponent> { new OperationOutcome.IssueComponent() { Severity = OperationOutcome.IssueSeverity.Information, Code = OperationOutcome.IssueType.Informational, Details = new CodeableConcept(null, null, "Update was completed") } }; result = so; } } } FhirObjectResult returnMessage; if (bodyResource.Annotation <CreateOrUpate>() == CreateOrUpate.Create) { returnMessage = new FhirObjectResult(HttpStatusCode.Created, result, actualResource); } else { returnMessage = new FhirObjectResult(HttpStatusCode.OK, result, actualResource); } // Check the prefer header if (Request.Headers.ContainsKey("Prefer")) { string preferHeader = Request.Header("Prefer"); if (preferHeader != null && preferHeader.ToLower() == "return=minimal") { returnMessage.Value = null; } } return(returnMessage); }