Пример #1
0
        public static void Setup(TestContext context)
        {
            ExportTests.tdb = new MockObjectRepository();
            TrifoliaImporter importer = new TrifoliaImporter(ExportTests.tdb);

            ExportTests.tdb.InitializeFHIR3Repository();
            ExportTests.tdb.InitializeLCGAndLogin();

            string importContent = Helper.GetSampleContents(IMPORT_XML);
            var    importModel   = ImportModel.Deserialize(importContent);

            var importStatus = importer.Import(importModel);

            Assert.IsTrue(importStatus.Success, "Expected import to succeed");
            Assert.AreNotEqual(importStatus.ImplementationGuides.Count, 0, "Expected import to include implementation guides");

            ImplementationGuide ig = ExportTests.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == importStatus.ImplementationGuides.First().InternalId);
            var schema             = ig.ImplementationGuideType.GetSimpleSchema();
            ImplementationGuideExporter exporter = new ImplementationGuideExporter(ExportTests.tdb, schema, "localhost", "http");

            ExportTests.exportedBundle = exporter.GetImplementationGuides(implementationGuideId: ig.Id, include: "ImplementationGuide:resource");

            ExportTests.exportedXml = FhirSerializer.SerializeResourceToXml(ExportTests.exportedBundle);

            Assert.IsNotNull(ExportTests.exportedXml);
        }
Пример #2
0
        public ImportStatusModel Import(ImportModel model)
        {
            ImportStatusModel          importStatus = new ImportStatusModel(this.tdb);
            List <ImplementationGuide> importedImplementationGuides = new List <ImplementationGuide>();

            foreach (var importImplementationGuide in model.ImplementationGuide)
            {
                ImplementationGuideImporter importer = new ImplementationGuideImporter(this.tdb);
                var importedImplementationGuide      = importer.Import(importImplementationGuide);
                importStatus.AddImportedImplementationGuide(importedImplementationGuide);
                importStatus.Messages.AddRange(importer.Errors);
            }

            TemplateImporter templateImporter  = new TemplateImporter(this.tdb, shouldUpdate: true);
            List <Template>  importedTemplates = templateImporter.Import(model.Template);

            importStatus.AddImportedTemplates(importedTemplates);
            importStatus.Messages.AddRange(templateImporter.Errors);

            if (importStatus.Messages.Count == 0)
            {
                try
                {
                    this.tdb.SaveChanges();
                    importStatus.Success = true;
                }
                catch (Exception ex)
                {
                    importStatus.Messages.Add("Error saving changes from import: " + ex.Message);
                }
            }

            return(importStatus);
        }
Пример #3
0
        public List <TDBTemplate> Import(string importXml)
        {
            ImportModel import = null;

            try
            {
                using (StringReader sr = new StringReader(importXml))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(ImportModel));
                    import = (ImportModel)serializer.Deserialize(sr);
                }
            }
            catch
            {
                return(this.importedTemplates);
            }

            return(Import(import.Template));
        }
Пример #4
0
        public ExportModel GenerateExport()
        {
            List <ExportTemplate>            exportTemplates            = new List <ExportTemplate>();
            List <ExportImplementationGuide> exportImplementationGuides = new List <ExportImplementationGuide>();
            ExportModel export = new ExportModel()
            {
                Template            = exportTemplates,
                ImplementationGuide = exportImplementationGuides
            };

            this.templates.ForEach(y =>
            {
                SimpleSchema schema = null;

                if (this.verboseConstraints)
                {
                    if (this.schemas.ContainsKey(y.ImplementationGuideTypeId))
                    {
                        schema = this.schemas[y.ImplementationGuideTypeId];
                    }
                    else
                    {
                        schema = y.ImplementationGuideType.GetSimpleSchema();
                        this.schemas.Add(y.ImplementationGuideTypeId, schema);
                    }
                }

                exportTemplates.Add(y.Export(this.tdb, this.igSettings, schema, categories));

                bool foundImplementationGuide = FindImplementationGuide(exportImplementationGuides, y.OwningImplementationGuide);

                if (!foundImplementationGuide)
                {
                    var exportImplementationGuide = y.OwningImplementationGuide.Export(this.tdb, this.igSettings);
                    exportImplementationGuides.Add(exportImplementationGuide);
                }
            });

            return(export);
        }
Пример #5
0
        public static void Setup(TestContext context)
        {
            FHIRDSTU1ExportTest.tdb = new MockObjectRepository();
            TrifoliaImporter importer = new TrifoliaImporter(FHIRDSTU1ExportTest.tdb);

            FHIRDSTU1ExportTest.tdb.InitializeFHIRRepository();
            FHIRDSTU1ExportTest.tdb.InitializeLCGAndLogin();

            string importContent = Helper.GetSampleContents(IMPORT_XML);
            var    importModel   = ImportModel.Deserialize(importContent);

            var importStatus = importer.Import(importModel);

            Assert.IsTrue(importStatus.Success, "Expected import to succeed");
            Assert.AreNotEqual(importStatus.ImplementationGuides.Count, 0, "Expected import to include implementation guides");

            IGSettingsManager igManager = new IGSettingsManager(tdb, importStatus.ImplementationGuides.First().InternalId);

            TemplateImporter templateImporter = new TemplateImporter(tdb, shouldUpdate: true);

            FHIRDSTU1ExportTest.exportedXml = FHIRExporter.GenerateExport(tdb, templateImporter.Import(importModel.Template), igManager);

            Assert.IsNotNull(FHIRDSTU1ExportTest.exportedXml);
        }
Пример #6
0
        public ImportStatusModel ImportTrifoliaModel(NativeModel model)
        {
            TrifoliaImporter importer = new TrifoliaImporter(this.tdb);

            return(importer.Import(model));
        }
Пример #7
0
        public ExportModel GenerateExport()
        {
            List <ExportTemplate>            exportTemplates            = new List <ExportTemplate>();
            List <ExportImplementationGuide> exportImplementationGuides = new List <ExportImplementationGuide>();
            ExportModel export = new ExportModel()
            {
                Template            = exportTemplates,
                ImplementationGuide = exportImplementationGuides
            };

            this.templates.ForEach(y =>
            {
                SimpleSchema schema = null;

                if (this.verboseConstraints)
                {
                    if (this.schemas.ContainsKey(y.ImplementationGuideTypeId))
                    {
                        schema = this.schemas[y.ImplementationGuideTypeId];
                    }
                    else
                    {
                        schema = y.ImplementationGuideType.GetSimpleSchema();
                        this.schemas.Add(y.ImplementationGuideTypeId, schema);
                    }
                }

                exportTemplates.Add(y.Export(this.tdb, this.igSettings, schema, categories));

                bool foundImplementationGuide = FindImplementationGuide(exportImplementationGuides, y.OwningImplementationGuide);

                if (!foundImplementationGuide)
                {
                    var exportImplementationGuide = y.OwningImplementationGuide.Export(this.tdb, this.igSettings);
                    exportImplementationGuides.Add(exportImplementationGuide);
                }
            });

            var valueSets = (from t in this.templates
                             join tc in this.tdb.TemplateConstraints.AsNoTracking() on t.Id equals tc.TemplateId
                             join vs in this.tdb.ValueSets.AsNoTracking() on tc.ValueSetId equals vs.Id
                             select vs);
            var codeSystems = (from vs in valueSets
                               join vsm in this.tdb.ValueSetMembers.AsNoTracking() on vs.Id equals vsm.ValueSetId
                               join cs in this.tdb.CodeSystems.AsNoTracking() on vsm.CodeSystemId equals cs.Id
                               select cs).Distinct();

            foreach (var codeSystem in codeSystems)
            {
                var exportCodeSystem = new Shared.ImportExport.Model.TrifoliaCodeSystem()
                {
                    name        = codeSystem.Name,
                    Description = codeSystem.Description,
                    Identifier  = new Shared.ImportExport.Model.TrifoliaCodeSystemIdentifier()
                    {
                        value = codeSystem.Oid
                    }
                };

                export.CodeSystem.Add(exportCodeSystem);
            }

            foreach (var valueSet in valueSets)
            {
                var exportValueSet = new Shared.ImportExport.Model.TrifoliaValueSet()
                {
                    name                 = valueSet.Name,
                    Description          = valueSet.Description,
                    code                 = valueSet.Code,
                    intensional          = valueSet.Intensional.HasValue ? valueSet.Intensional.Value : false,
                    intensionalSpecified = valueSet.Intensional.HasValue,
                    isIncomplete         = valueSet.IsIncomplete,
                    source               = valueSet.Source
                };

                foreach (var valueSetIdentifier in valueSet.Identifiers)
                {
                    var exportValueSetId = new Shared.ImportExport.Model.TrifoliaValueSetIdentifier()
                    {
                        type  = valueSetIdentifier.Type.ToString(),
                        value = valueSetIdentifier.Identifier
                    };

                    if (valueSetIdentifier.IsDefault)
                    {
                        exportValueSet.defaultIdentifier = valueSetIdentifier.Identifier;
                    }

                    exportValueSet.Identifier.Add(exportValueSetId);
                }

                foreach (var valueSetMember in valueSet.Members)
                {
                    var exportValueSetMember = new Shared.ImportExport.Model.TrifoliaValueSetMember()
                    {
                        code                 = valueSetMember.Code,
                        displayName          = valueSetMember.DisplayName,
                        codeSystemIdentifier = valueSetMember.CodeSystem.Oid,
                        statusDate           = valueSetMember.StatusDate.HasValue ? valueSetMember.StatusDate.Value.ToString("s") : null
                    };

                    if (valueSetMember.Status != null)
                    {
                        if (valueSetMember.Status.ToLower().Trim() == "active")
                        {
                            exportValueSetMember.status = Shared.ImportExport.Model.TrifoliaValueSetMemberStatus.active;
                        }
                        else if (valueSetMember.Status.ToLower().Trim() == "inactive")
                        {
                            exportValueSetMember.status = Shared.ImportExport.Model.TrifoliaValueSetMemberStatus.inactive;
                        }
                    }

                    exportValueSet.Member.Add(exportValueSetMember);
                }

                export.ValueSet.Add(exportValueSet);
            }

            return(export);
        }