public HttpResponseMessage CreateValueSet( [FromBody] FhirValueSet fhirValueSet, [FromUri(Name = "_format")] string format = null) { var foundValueSets = (from vs in this.tdb.ValueSets join vsi in this.tdb.ValueSetIdentifiers on vs.Id equals vsi.ValueSetId join fvsi in fhirValueSet.Identifier on vsi.Identifier.ToLower().Trim() equals fvsi.Value.ToLower().Trim() select vs) .Distinct(); if (foundValueSets.Count() > 0) { throw new Exception("ValueSet already exists with this identifier. Use a PUT instead"); } ValueSetImporter importer = new ValueSetImporter(this.tdb); ValueSetExporter exporter = new ValueSetExporter(this.tdb); ValueSet valueSet = importer.Convert(fhirValueSet); this.tdb.ValueSets.Add(valueSet); this.tdb.SaveChanges(); string location = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, fhirValueSet.Id); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Location", location); FhirValueSet createdFhirValueSet = exporter.Convert(valueSet); return(Shared.GetResponseMessage(this.Request, format, createdFhirValueSet, statusCode: 201, headers: headers)); }
public HttpResponseMessage UpdateValueSet( [FromBody] FhirValueSet fhirValueSet, [FromUri] int valueSetId, [FromUri(Name = "_format")] string format = null) { ValueSetExporter exporter = new ValueSetExporter(this.tdb); ValueSetImporter importer = new ValueSetImporter(this.tdb); ValueSet originalValueSet = this.tdb.ValueSets.Single(y => y.Id == valueSetId); ValueSet newValueSet = importer.Convert(fhirValueSet, valueSet: originalValueSet); if (originalValueSet == null) { this.tdb.ValueSets.Add(newValueSet); } this.tdb.SaveChanges(); string location = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, fhirValueSet.Id); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Location", location); FhirValueSet updatedFhirValueSet = exporter.Convert(newValueSet); return(Shared.GetResponseMessage(this.Request, format, updatedFhirValueSet, originalValueSet != null ? 200 : 201, headers)); }
public HttpResponseMessage CreateValueSet( [FromBody] FhirValueSet fhirValueSet, [FromUri(Name = "_format")] string format = null) { var fhirIdentifier = fhirValueSet.Identifier.Count > 0 ? fhirValueSet.Identifier.First() : null; var fhirIdentifierValue = fhirIdentifier != null ? fhirIdentifier.Value : null; if (fhirValueSet.Identifier != null && this.tdb.ValueSets.Count(y => y.Oid == fhirIdentifierValue) > 0) { throw new Exception("ValueSet already exists with this identifier. Use a PUT instead"); } ValueSetImporter importer = new ValueSetImporter(this.tdb); ValueSetExporter exporter = new ValueSetExporter(this.tdb); ValueSet valueSet = importer.Convert(fhirValueSet); if (valueSet.Oid == null) { valueSet.Oid = string.Empty; } if (this.tdb.ValueSets.Count(y => y.Oid == valueSet.Oid) > 0) { throw new Exception("A ValueSet with that identifier already exists"); } this.tdb.ValueSets.AddObject(valueSet); this.tdb.SaveChanges(); string location = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, fhirValueSet.Id); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Location", location); FhirValueSet createdFhirValueSet = exporter.Convert(valueSet); return(Shared.GetResponseMessage(this.Request, format, createdFhirValueSet, statusCode: 201, headers: headers)); }