public Template CreateTemplate(StructureDefinition strucDef) { var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl); StructureDefinitionImporter importer = new StructureDefinitionImporter(this.tdb, uri.Scheme, uri.Authority); Template template = importer.Convert(strucDef); this.tdb.Templates.AddObject(template); return(template); }
public IHttpActionResult UpdateStructureDefinition( [FromBody] StructureDefinition strucDef, [FromUri] string bookmark) { Template existingTemplate = this.tdb.Templates.SingleOrDefault(y => y.Bookmark.ToLower().Trim() == bookmark.ToLower().Trim()); // Make sure the profile exists if (existingTemplate == null) { return(CreateErrorResponse(App_GlobalResources.TrifoliaLang.TemplateNotFoundMessageFormat)); } if (!CheckPoint.Instance.GrantEditTemplate(existingTemplate.Id)) { throw new UnauthorizedAccessException(); } var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl); StructureDefinitionImporter importer = new StructureDefinitionImporter(this.tdb, uri.Scheme, uri.Authority); StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority); Template updatedTemplate; try { User author = CheckPoint.Instance.GetUser(this.tdb); updatedTemplate = importer.Convert(strucDef, existingTemplate, author); } catch (Exception ex) { return(CreateErrorResponse(ex.Message, OperationOutcome.IssueType.Exception)); } if (existingTemplate == null) { this.tdb.Templates.Add(updatedTemplate); } this.tdb.SaveChanges(); string location = string.Format("{0}://{1}/api/FHIR3/StructureDefinition/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, updatedTemplate.Id); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Location", location); SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, updatedTemplate.ImplementationGuideType); schema = schema.GetSchemaFromContext(updatedTemplate.PrimaryContextType); StructureDefinition updatedStrucDef = exporter.Convert(updatedTemplate, schema); return(Content <Resource>((existingTemplate == null ? HttpStatusCode.Created : HttpStatusCode.OK), updatedStrucDef, headers)); }
public IHttpActionResult UpdateStructureDefinition( [FromBody] StructureDefinition strucDef, [FromUri] int templateId) { Template existingTemplate = this.tdb.Templates.SingleOrDefault(y => y.Id == templateId); if (!CheckPoint.Instance.GrantEditTemplate(templateId)) { throw new UnauthorizedAccessException(); } var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl); StructureDefinitionImporter importer = new StructureDefinitionImporter(this.tdb, uri.Scheme, uri.Authority); StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority); Template updatedTemplate = importer.Convert(strucDef, existingTemplate); if (existingTemplate == null) { this.tdb.Templates.AddObject(updatedTemplate); } this.tdb.SaveChanges(); string location = string.Format("{0}://{1}/api/FHIR2/StructureDefinition/{2}", this.Request.RequestUri.Scheme, this.Request.RequestUri.Authority, updatedTemplate.Id); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Location", location); SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, updatedTemplate.ImplementationGuideType); schema = schema.GetSchemaFromContext(updatedTemplate.PrimaryContextType); StructureDefinition updatedStrucDef = exporter.Convert(updatedTemplate, schema); return(Content <Resource>((existingTemplate == null ? HttpStatusCode.Created : HttpStatusCode.OK), updatedStrucDef, headers)); }