示例#1
0
        private void AddProfiles()
        {
            List <TemplateType> templateTypes = this.templates.Select(y => y.TemplateType).Distinct().ToList();

            /*      no need to create a default for each type since they are the same for all
             * foreach (var templateType in templateTypes)
             * {
             *  control.defaults.Add(templateType.RootContextType, new Models.Control.TemplateReference("instance-template-format-example.html", "instance-template-example.html"));
             * }
             */

            foreach (var template in this.templates)
            {
                var templateSchema = this.schema.GetSchemaFromContext(template.PrimaryContextType);

                StructureDefinitionExporter sdExporter = new StructureDefinitionExporter(this.tdb, "http", "test.com");
                var    strucDef         = sdExporter.Convert(template, templateSchema);
                string location         = string.Format("StructureDefinition/{0}", strucDef.Id);
                var    strucDefContent  = this.Serialize(strucDef);
                string fileExtension    = this.JsonFormat ? "json" : "xml";
                string strucDefFileName = string.Format("resources/structuredefinition/{0}.{1}", strucDef.Id, fileExtension);
                this.zip.AddEntry(strucDefFileName, strucDefContent);

                this.control.Resources.Add(location, new Models.Control.ResourceReference("StructureDefinition-" + strucDef.Id + ".html"));
            }
        }
        public Bundle GetImplementationGuides(SummaryType?summary = null, string include = null, int?implementationGuideId = null, string name = null)
        {
            // TODO: Should not be using constant string for IG type name to find templates... Not sure how else to identify FHIR DSTU1 templates though
            var implementationGuides = this.tdb.ImplementationGuides.Where(y => y.ImplementationGuideTypeId == this.implementationGuideType.Id);

            if (!CheckPoint.Instance.IsDataAdmin)
            {
                User currentUser = CheckPoint.Instance.GetUser(this.tdb);
                implementationGuides = (from ig in implementationGuides
                                        join igp in this.tdb.ImplementationGuidePermissions on ig.Id equals igp.UserId
                                        where igp.UserId == currentUser.Id
                                        select ig);
            }

            if (implementationGuideId != null)
            {
                implementationGuides = implementationGuides.Where(y => y.Id == implementationGuideId);
            }

            if (!string.IsNullOrEmpty(name))
            {
                implementationGuides = implementationGuides.Where(y => y.Name.ToLower().Contains(name.ToLower()));
            }

            Bundle bundle = new Bundle()
            {
                Type = Bundle.BundleType.BatchResponse
            };

            foreach (var ig in implementationGuides)
            {
                FhirImplementationGuide fhirImplementationGuide = Convert(ig, summary);

                // Add the IG before the templates
                bundle.AddResourceEntry(fhirImplementationGuide, this.GetFullUrl(ig));

                // TODO: Need to implement a more sophisticated approach to parsing "_include"
                if (!string.IsNullOrEmpty(include) && include == "ImplementationGuide:resource")
                {
                    List <Template> templates = ig.GetRecursiveTemplates(this.tdb, inferred: true);

                    /*
                     * // TODO: Add additional query parameters for indicating parent template ids and categories?
                     * IGSettingsManager igSettings = new IGSettingsManager(this.tdb, ig.Id);
                     * string templateBundleXml = FHIRExporter.GenerateExport(this.tdb, templates, igSettings);
                     * Bundle templateBundle = (Bundle)FhirParser.ParseResourceFromXml(templateBundleXml);
                     *
                     * var templateEntries = templateBundle.Entry.Where(y =>
                     *  y.Resource.ResourceType != ResourceType.ImplementationGuide &&
                     *  y.Resource.Id != fhirImplementationGuide.Id);
                     *
                     * // TODO: Make sure that if multiple IGs are returned, that there are distinct bundle entries
                     * // (no duplicate template/profile entries that are referenced by two separate IGs)
                     * bundle.Entry.AddRange(templateEntries);
                     */

                    StructureDefinitionExporter strucDefExporter = new StructureDefinitionExporter(this.tdb, this.scheme, this.authority);
                    foreach (var template in templates)
                    {
                        var templateSchema = this.schema.GetSchemaFromContext(template.PrimaryContextType);
                        var strucDef       = strucDefExporter.Convert(template, schema);
                        bundle.AddResourceEntry(strucDef, this.GetFullUrl(template));
                    }
                }
            }

            return(bundle);
        }