public HttpResponseMessage UpdateValueSet( [FromBody] FhirValueSet fhirValueSet, [FromUri] int valueSetId, [FromUri(Name = "_format")] string format = null) { ValueSetExporter exporter = new ValueSetExporter(this.tdb); ValueSet originalValueSet = this.tdb.ValueSets.Single(y => y.Id == valueSetId); ValueSet newValueSet = exporter.Convert(fhirValueSet, valueSet: originalValueSet); if (originalValueSet == null) { this.tdb.ValueSets.AddObject(newValueSet); } this.tdb.SaveChanges(); string location = string.Format("{0}://{1}/api/FHIR2/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 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 GetValueSetExpansion( [FromUri] int valueSetId, [FromUri(Name = "_format")] string format = null, [FromUri(Name = "_summary")] SummaryType?summary = null) { ValueSet valueSet = this.tdb.ValueSets.Single(y => y.Id == valueSetId); ValueSetExporter exporter = new ValueSetExporter(this.tdb); FhirValueSet fhirValueSet = exporter.Convert(valueSet, summary); return(Shared.GetResponseMessage(this.Request, format, fhirValueSet)); }
public HttpResponseMessage CreateValueSet( [FromBody] FhirValueSet fhirValueSet, [FromUri(Name = "_format")] string format = null) { if (fhirValueSet.Identifier != null && this.tdb.ValueSets.Count(y => y.Oid == fhirValueSet.Identifier.Value) > 0) { throw new Exception("ValueSet already exists with this identifier. Use a PUT instead"); } ValueSetExporter exporter = new ValueSetExporter(this.tdb); ValueSet valueSet = exporter.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/FHIR2/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 GetValueSets( [FromUri(Name = "_id")] int?valueSetId = null, [FromUri(Name = "name")] string name = null, [FromUri(Name = "_format")] string format = null, [FromUri(Name = "_summary")] SummaryType?summary = null) { var valueSets = this.tdb.ValueSets.Where(y => y.Id >= 0); ValueSetExporter exporter = new ValueSetExporter(this.tdb); if (valueSetId != null) { valueSets = valueSets.Where(y => y.Id == valueSetId); } if (!string.IsNullOrEmpty(name)) { valueSets = valueSets.Where(y => y.Name.ToLower().Contains(name.ToLower())); } Bundle bundle = new Bundle() { Type = Bundle.BundleType.BatchResponse }; var publishedValueSets = (from ig in this.tdb.ImplementationGuides join t in this.tdb.Templates on ig.Id equals t.OwningImplementationGuideId join tc in this.tdb.TemplateConstraints on t.Id equals tc.TemplateId where ig.PublishStatus != null && ig.PublishStatus.Status == PublishStatus.PUBLISHED_STATUS && tc.ValueSet != null select tc.ValueSet) .ToList(); // Query the database immediately foreach (var valueSet in valueSets) { var fhirValueSet = exporter.Convert(valueSet, summary, publishedValueSets); var fullUrl = string.Format("{0}://{1}/api/FHIR3/ValueSet/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, valueSet.Id); bundle.AddResourceEntry(fhirValueSet, fullUrl); } return(Shared.GetResponseMessage(this.Request, format, bundle)); }
public HttpResponseMessage GetValueSets( [FromUri(Name = "_id")] int?valueSetId = null, [FromUri(Name = "name")] string name = null, [FromUri(Name = "_format")] string format = null, [FromUri(Name = "_summary")] SummaryType?summary = null) { var valueSets = this.tdb.ValueSets.Where(y => y.Id >= 0); ValueSetExporter exporter = new ValueSetExporter(this.tdb); if (valueSetId != null) { valueSets = valueSets.Where(y => y.Id == valueSetId); } if (!string.IsNullOrEmpty(name)) { valueSets = valueSets.Where(y => y.Name.ToLower().Contains(name.ToLower())); } Bundle bundle = new Bundle() { Type = Bundle.BundleType.BatchResponse }; foreach (var valueSet in valueSets) { var fhirValueSet = exporter.Convert(valueSet, summary); var fullUrl = string.Format("{0}://{1}/api/FHIR2/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, fhirValueSet.Url); bundle.AddResourceEntry(fhirValueSet, fullUrl); } return(Shared.GetResponseMessage(this.Request, format, bundle)); }