public FhirResponse Put(IKey key, Resource resource) { Validate.Key(key); Validate.ResourceType(key, resource); Validate.HasTypeName(key); Validate.HasResourceId(key); Validate.HasResourceId(resource); Validate.IsResourceIdEqual(key, resource); Entry current = fhirStore.Get(key); Entry entry = Entry.PUT(key, resource); transfer.Internalize(entry); Store(entry); // API: The api demands a body. This is wrong //CCR: The documentations specifies that servers should honor the Http return preference header Entry result = fhirStore.Get(entry.Key); transfer.Externalize(result); return(Respond.WithResource(current != null ? HttpStatusCode.OK : HttpStatusCode.Created, result)); }
//public FhirResponse Search(string type, IEnumerable<Tuple<string, string>> parameters, int pageSize, string sortby) //{ // Validate.TypeName(type); // Uri link = localhost.Uri(type); // IEnumerable<string> keys = store.List(type); // var snapshot = pager.CreateSnapshot(Bundle.BundleType.Searchset, link, keys, ); // Bundle bundle = pager.GetFirstPage(snapshot); // return Respond.WithBundle(bundle, localhost.Base); // DSTU2: search /* * Query query = FhirParser.ParseQueryFromUriParameters(collection, parameters); * ICollection<string> includes = query.Includes; * * SearchResults results = index.Search(query); * * if (results.HasErrors) * { * throw new SparkException(HttpStatusCode.BadRequest, results.Outcome); * } * * Uri link = localhost.Uri(type).AddPath(results.UsedParameters); * * Bundle bundle = pager.GetFirstPage(link, keys, sortby); * * /* * if (results.HasIssues) * { * var outcomeEntry = BundleEntryFactory.CreateFromResource(results.Outcome, new Uri("outcome/1", UriKind.Relative), DateTimeOffset.Now); * outcomeEntry.SelfLink = outcomeEntry.Id; * bundle.Entries.Add(outcomeEntry); * } * return Respond.WithBundle(bundle); */ //} //public FhirResponse Update(IKey key, Resource resource) //{ // Validate.HasTypeName(key); // Validate.HasNoVersion(key); // Validate.ResourceType(key, resource); // Interaction original = store.Get(key); // if (original == null) // { // return Respond.WithError(HttpStatusCode.MethodNotAllowed, // "Cannot update resource {0}/{1}, because it doesn't exist on this server", // key.TypeName, key.ResourceId); // } // Interaction interaction = Interaction.PUT(key, resource); // interaction.Resource.AffixTags(original.Resource); // transfer.Internalize(interaction); // Store(interaction); // // todo: does this require a response? // transfer.Externalize(interaction); // return Respond.WithEntry(HttpStatusCode.OK, interaction); //} public FhirResponse VersionSpecificUpdate(IKey versionedkey, Resource resource) { Validate.HasTypeName(versionedkey); Validate.HasVersion(versionedkey); Key key = versionedkey.WithoutVersion(); Entry current = fhirStore.Get(key); Validate.IsSameVersion(current.Key, versionedkey); return(this.Put(key, resource)); }
private static void ValidateKey(Key key, bool includeVersion = false) { Validate.HasTypeName(key); Validate.HasResourceId(key); if (includeVersion) { Validate.HasVersion(key); } else { Validate.HasNoVersion(key); } Validate.Key(key); }
public FhirResponse ReadMeta(Key key) { Validate.HasTypeName(key); Validate.HasResourceId(key); Validate.HasNoVersion(key); Validate.Key(key); Interaction interaction = store.Get(key); if (interaction == null) { return(Respond.NotFound(key)); } else if (interaction.IsDeleted()) { return(Respond.Gone(interaction)); } return(Respond.WithMeta(interaction)); }
/// <summary> /// Create a new resource with a server assigned id. /// </summary> /// <param name="collection">The resource type, in lowercase</param> /// <param name="resource">The data for the Resource to be created</param> /// <returns> /// Returns /// 201 Created - on successful creation /// </returns> public FhirResponse Create(IKey key, Resource resource) { Validate.Key(key); Validate.ResourceType(key, resource); Validate.HasTypeName(key); Validate.HasNoResourceId(key); Validate.HasNoVersion(key); Interaction interaction = Interaction.POST(key, resource); transfer.Internalize(interaction); Store(interaction); // API: The api demands a body. This is wrong Interaction result = store.Get(interaction.Key); transfer.Externalize(result); return(Respond.WithResource(HttpStatusCode.Created, interaction)); }
/// <summary> /// Create a new resource with a server assigned id. /// </summary> /// <param name="collection">The resource type, in lowercase</param> /// <param name="resource">The data for the Resource to be created</param> /// <returns> /// Returns /// 201 Created - on successful creation /// </returns> public FhirResponse Create(IKey key, Resource resource) { Validate.Key(key); Validate.ResourceType(key, resource); Validate.HasTypeName(key); Validate.HasNoResourceId(key); Validate.HasNoVersion(key); Interaction interaction = Interaction.POST(key, resource); transfer.Internalize(interaction); Store(interaction); // API: The api demands a body. This is wrong //CCR: The documentations specifies that servers should honor the Http return preference header Interaction result = fhirStore.Get(interaction.Key); transfer.Externalize(result); return(Respond.WithResource(HttpStatusCode.Created, result)); }
/// <summary> /// Read the state of a specific version of the resource. /// </summary> /// <param name="collectionName">The resource type, in lowercase</param> /// <param name="id">The id part of a version-specific reference</param> /// <param name="vid">The version part of a version-specific reference</param> /// <returns>A Result containing the resource, or an Issue</returns> /// <remarks> /// If the version referred to is actually one where the resource was deleted, the server should return a /// 410 status code. /// </remarks> public FhirResponse VersionRead(Key key) { Validate.HasTypeName(key); Validate.HasResourceId(key); Validate.HasVersion(key); Validate.Key(key); Interaction interaction = store.Get(key); if (interaction == null) { return(Respond.NotFound(key)); } else if (interaction.IsDeleted()) { return(Respond.Gone(interaction)); } transfer.Externalize(interaction); return(Respond.WithResource(interaction)); }