public async Task <IActionResult> Create([FromBody] Resource resource) { //TODO: Remove temp code if (resource.ResourceType.Equals(ResourceType.OperationOutcome)) { throw new HttpFhirException("Invalid Fhir Request", (OperationOutcome)resource, HttpStatusCode.BadRequest); } Resource result = null; var request = FhirRequest.Create(null, ResourceType.DocumentReference, resource, Request, RequestingAsid()); var createIssue = await _nrlsMaintain.ValidateCreate <DocumentReference>(request); if (createIssue != null) { return(BadRequest(createIssue)); } //If we have a valid document that needs to be Superseded, try update on that var validUpdateDocument = await _nrlsMaintain.ValidateConditionalUpdate(request); if (validUpdateDocument != null) { if (validUpdateDocument.ResourceType == ResourceType.OperationOutcome) { return(BadRequest(validUpdateDocument)); } result = await _nrlsMaintain.SupersedeWithoutValidation <DocumentReference>(request, validUpdateDocument.Id, validUpdateDocument.VersionId); } else { //just try and create new document result = await _nrlsMaintain.CreateWithoutValidation <DocumentReference>(request); } if (result.ResourceType == ResourceType.OperationOutcome) { return(BadRequest(result)); } var response = OperationOutcomeFactory.CreateSuccess(); var newResource = $"{_nrlsApiSettings.ResourceLocation}/{ResourceType.DocumentReference}?_id={result.Id}"; //Temp required header for NRLS API tests Request.HttpContext.Response.Headers.Add("Content-Location", newResource); return(Created(newResource, response)); }
public async Task <IActionResult> Create([FromBody] Resource resource) { var request = FhirRequest.Create(null, ResourceType.DocumentReference, resource, Request, RequestingAsid()); var createIssue = await _nrlsMaintain.ValidateCreate(request); if (createIssue != null) { return(BadRequest(createIssue)); } Resource result = null; //If we have a valid document that needs to be Superseded, try update on that var validUpdateDocument = await _nrlsMaintain.ValidateConditionalUpdate(request); if (validUpdateDocument != null) { if (validUpdateDocument.ResourceType == ResourceType.OperationOutcome) { return(BadRequest(validUpdateDocument)); } result = await _nrlsMaintain.SupersedeWithoutValidation(request, validUpdateDocument.Id, validUpdateDocument.VersionId); } else { //just try and create new document result = await _nrlsMaintain.CreateWithoutValidation(request); } if (result.ResourceType == ResourceType.OperationOutcome) { return(BadRequest(result)); } var response = OperationOutcomeFactory.CreateSuccess(); var newResource = $"{_nrlsApiSettings.ResourceLocation}/{ResourceType.DocumentReference}/{result.Id}"; return(Created(newResource, response)); }