/// <summary> /// Validate a resource (really an update with debugging / non comit) /// </summary> public OperationOutcome ValidateResource(string resourceType, string id, DomainResourceBase target) { this.ThrowIfNotReady(); FhirOperationResult result = null; try { // Setup outgoing content // Create or update? var handler = FhirResourceHandlerUtil.GetResourceHandler(resourceType); if (handler == null) { throw new FileNotFoundException(); // endpoint not found! } result = handler.Update(id, target, TransactionMode.Rollback); if (result == null || result.Results.Count == 0) // Create { result = handler.Create(target, TransactionMode.Rollback); WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Created; } if (result == null || result.Outcome == ResultCode.Rejected) { throw new InvalidDataException("Resource structure is not valid"); } else if (result.Outcome == ResultCode.AcceptedNonConformant) { throw new ConstraintException("Resource not conformant"); } else if (result.Outcome == ResultCode.TypeNotAvailable) { throw new FileNotFoundException(String.Format("Resource {0} not found", WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri)); } else if (result.Outcome != ResultCode.Accepted) { throw new DataException("Validate failed"); } // Return constraint return(MessageUtil.CreateOutcomeResource(result)); } catch (Exception e) { return(this.ErrorHelper(e, result, false) as OperationOutcome); } }