Exemple #1
0
 /// <summary>
 /// Initializes a new instance of ImplementationGuideExporter
 /// </summary>
 /// <param name="tdb">Reference to the database</param>
 /// <param name="scheme">The server url's scheme</param>
 /// <param name="authority">The server url's authority</param>
 public ImplementationGuideExporter(IObjectRepository tdb, SimpleSchema schema, string scheme, string authority)
 {
     this.tdb       = tdb;
     this.scheme    = scheme;
     this.authority = authority;
     this.schema    = schema;
     this.implementationGuideType = STU3Helper.GetImplementationGuideType(this.tdb, true);
 }
Exemple #2
0
 public StructureDefinitionExporter(IObjectRepository tdb, string scheme, string authority)
 {
     this.tdb       = tdb;
     this.scheme    = scheme;
     this.authority = authority;
     this.implementationGuideType = STU3Helper.GetImplementationGuideType(this.tdb, true);
     this.profileBundle           = ProfileHelper.GetProfileBundle();
 }
Exemple #3
0
        public void Setup()
        {
            this.tdb = new MockObjectRepository();
            this.tdb.InitializeCDARepository();

            this.igType       = this.tdb.FindImplementationGuideType(Constants.IGTypeNames.CDA);
            this.igTypeSchema = this.igType.GetSimpleSchema();
        }
Exemple #4
0
        public void Setup()
        {
            this.mockRepo = new MockObjectRepository();

            cdaType      = this.mockRepo.FindOrCreateImplementationGuideType(Constants.IGTypeNames.CDA, string.Empty, string.Empty, string.Empty);
            documentType = this.mockRepo.FindOrCreateTemplateType(cdaType, "Document Templates", "ClinicalDocument", "ClinicalDocument", 1);
            ig           = this.mockRepo.FindOrCreateImplementationGuide(cdaType, "Test");
        }
 public StructureDefinitionExporter(IObjectRepository tdb, string scheme, string authority)
 {
     this.tdb       = tdb;
     this.scheme    = scheme;
     this.authority = authority;
     this.implementationGuideType = DSTU2Helper.GetImplementationGuideType(this.tdb, true);
     this.igTypePlugin            = this.implementationGuideType.GetPlugin();
 }
Exemple #6
0
        public static SimpleSchema GetSimplifiedSchema(HttpContext context, ImplementationGuideType igType)
        {
            if (context != null)
            {
                return(GetSimplifiedSchema(context.Application, igType));
            }

            return(GetSimplifiedSchema((HttpApplicationState)null, igType));
        }
Exemple #7
0
        public static void UpdateSimplifiedSchema(HttpApplicationState application, ImplementationGuideType igType, SimpleSchema schema)
        {
            if (application[igType.Name] != null)
            {
                application.Remove(igType.Name);
            }

            application.Add(igType.Name, schema);
        }
 public static List <SimplifiedSchemaObject> GetComplexTypesFromSchema(long implementationGuideTypeId)
 {
     using (TemplateDatabaseDataSource tdb = new TemplateDatabaseDataSource())
     {
         ImplementationGuideType igType = tdb.ImplementationGuideTypes.Single(y => y.Id == implementationGuideTypeId);
         SimplifiedSchema        schema = new SimplifiedSchema(
             Helper.GetIGSchema(igType));
         return(schema.ComplexTypes);
     }
 }
Exemple #9
0
        private void UpdateProperties(ImplementationGuide implementationGuide, ImplementationGuideType igType, ImportImplementationGuide importImplementationGuide)
        {
            var importIgStatus = GetImportStatus(importImplementationGuide);
            var organization   = !string.IsNullOrEmpty(importImplementationGuide.organizationName) ? this.tdb.Organizations.SingleOrDefault(y => y.Name.ToLower() == importImplementationGuide.organizationName.ToLower()) : null;

            if (implementationGuide.Identifier != importImplementationGuide.identifier)
            {
                implementationGuide.Identifier = importImplementationGuide.identifier;
            }

            if (implementationGuide.Organization != organization)
            {
                implementationGuide.Organization = organization;
            }

            if (implementationGuide.Name != importImplementationGuide.name)
            {
                implementationGuide.Name = importImplementationGuide.name;
            }

            if (implementationGuide.ImplementationGuideType != igType)
            {
                implementationGuide.ImplementationGuideType = igType;
            }

            if (implementationGuide.Version != importImplementationGuide.version)
            {
                implementationGuide.Version = importImplementationGuide.version;
            }

            if (implementationGuide.DisplayName != importImplementationGuide.displayName)
            {
                implementationGuide.DisplayName = importImplementationGuide.displayName;
            }

            if (implementationGuide.WebReadmeOverview != importImplementationGuide.WebReadmeOverview)
            {
                implementationGuide.WebReadmeOverview = importImplementationGuide.WebReadmeOverview;
            }

            if (implementationGuide.WebDisplayName != importImplementationGuide.webDisplayName)
            {
                implementationGuide.WebDisplayName = importImplementationGuide.webDisplayName;
            }

            if (implementationGuide.WebDescription != importImplementationGuide.WebDescription)
            {
                implementationGuide.WebDescription = importImplementationGuide.WebDescription;
            }

            if (implementationGuide.PublishStatus != importIgStatus)
            {
                implementationGuide.PublishStatus = importIgStatus;
            }
        }
Exemple #10
0
        /// <summary>
        /// Used to test green artifact generation.
        /// </summary>
        /// <returns></returns>
        public static MockObjectRepository GenerateGreenMockDataset1()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            mockRepo.FindOrCreateCodeSystem("SNOMED CT", "6.96");
            mockRepo.FindOrCreateCodeSystem("HL7ActStatus", "113883.5.14");
            mockRepo.FindOrCreateValueSet("GenderCode", "11.1");

            ImplementationGuideType igType      = mockRepo.FindOrCreateImplementationGuideType("CDA", "CDA.xsd", "cda", "urn:hl7-org:v3");
            TemplateType            docType     = mockRepo.FindOrCreateTemplateType(igType, "Document", "ClinicalDocument", "ClinicalDocument", 1);
            TemplateType            sectionType = mockRepo.FindOrCreateTemplateType(igType, "Section", "section", "Section", 2);

            mockRepo.GenerateDataType(igType, "II");
            mockRepo.GenerateDataType(igType, "INT");
            mockRepo.GenerateDataType(igType, "TS");
            mockRepo.GenerateDataType(igType, "CE");

            ImplementationGuide ig1 = mockRepo.FindOrAddImplementationGuide(igType, "Test IG 1");
            Template            t1  = mockRepo.GenerateTemplate("urn:oid:1.2.3.4", docType, "Test Template 1", ig1, null, null, null);

            TemplateConstraint tc1       = mockRepo.GenerateConstraint(t1, null, null, "code", "SHALL", "1..1", "CE");
            TemplateConstraint tc1_1     = mockRepo.GenerateConstraint(t1, tc1, null, "@code", "SHALL", "1..1", null, "SHALL", "1234-x", "Test Doc Code", null, null);
            TemplateConstraint tc1_2     = mockRepo.GenerateConstraint(t1, tc1, null, "@codeSystem", "SHALL", "1..1", null, "SHALL", "1.5.4.2.3", "Test Code System OID", null, null);
            TemplateConstraint tc2       = mockRepo.GenerateConstraint(t1, null, null, "setId", "SHALL", "1..1", "II");
            TemplateConstraint tc3       = mockRepo.GenerateConstraint(t1, null, null, "versionNumber", "SHALL", "1..1", "INT");
            TemplateConstraint tc4       = mockRepo.GenerateConstraint(t1, null, null, "recordTarget", "SHALL", "1..*", null);
            TemplateConstraint tc4_1     = mockRepo.GenerateConstraint(t1, tc4, null, "patientRole", "SHALL", "1..1", null);
            TemplateConstraint tc4_1_1   = mockRepo.GenerateConstraint(t1, tc4_1, null, "id", "SHALL", "1..1", "II");
            TemplateConstraint tc4_1_2   = mockRepo.GenerateConstraint(t1, tc4_1, null, "patient", "SHALL", "1..1", null);
            TemplateConstraint tc4_1_2_1 = mockRepo.GenerateConstraint(t1, tc4_1_2, null, "birthTime", "SHALL", "1..1", "TS");
            TemplateConstraint tc4_1_2_2 = mockRepo.GenerateConstraint(t1, tc4_1_2, null, "administrativeGenderCode", "SHALL", "1..1", "CE");

            // Green Info

            GreenTemplate gt1 = new GreenTemplate()
            {
                Id         = 1,
                Template   = t1,
                TemplateId = t1.Id,
                Name       = "Test Green Template 1"
            };

            mockRepo.GreenTemplates.AddObject(gt1);
            t1.GreenTemplates.Add(gt1);

            GreenConstraint gc1 = mockRepo.GenerateGreenConstraint(gt1, tc2, null, 1, "VersionSet", true);
            GreenConstraint gc2 = mockRepo.GenerateGreenConstraint(gt1, tc3, null, 2, "VersionNumber", true);
            GreenConstraint gc3 = mockRepo.GenerateGreenConstraint(gt1, tc4, null, 3, "Patient", false);
            GreenConstraint gc4 = mockRepo.GenerateGreenConstraint(gt1, tc4_1_1, gc3, 1, "Id", true);
            GreenConstraint gc5 = mockRepo.GenerateGreenConstraint(gt1, tc4_1_2_1, gc3, 2, "BirthDate", true);
            GreenConstraint gc6 = mockRepo.GenerateGreenConstraint(gt1, tc4_1_2_2, gc3, 3, "Gender", true);

            return(mockRepo);
        }
Exemple #11
0
        private ImplementationGuideType GetFHIRIGType()
        {
            ImplementationGuideType igType = this.tdb.ImplementationGuideTypes.SingleOrDefault(y => y.Name == FHIR_IG_TYPE_NAME);

            if (igType == null)
            {
                throw new Exception("The FHIR schema has not yet been loaded on this server");
            }

            return(igType);
        }
Exemple #12
0
        private void SaveSchemaFile(ImplementationGuideType igType, byte[] schema)
        {
            string directory     = Shared.Helper.GetSchemasDirectory(igType.Name);
            string tempDirectory = directory + "TEMP";
            string fullTempPath  = Path.Combine(tempDirectory, igType.SchemaLocation);

            // Write file to temporary location
            Directory.CreateDirectory(tempDirectory);
            File.WriteAllBytes(fullTempPath, schema);

            MoveSchemaFiles(tempDirectory, directory);
        }
        public FHIR2StructureDefinitionController(IObjectRepository tdb, HttpRequestMessage request = null)
        {
            this.tdb = tdb;

            // NOTE: This is for unit testing only
            if (request != null)
            {
                this.Request = request;
            }

            this.implementationGuideType = DSTU2Helper.GetImplementationGuideType(this.tdb, true);
        }
Exemple #14
0
        private void SaveSchemaZip(ImplementationGuideType igType, byte[] zip)
        {
            string directory     = Shared.Helper.GetSchemasDirectory(igType.Name);
            string tempDirectory = directory + "TEMP";

            using (MemoryStream zipFileStream = new MemoryStream(zip))
            {
                ZipFile zipFile = ZipFile.Read(zipFileStream);
                zipFile.ExtractAll(tempDirectory);
            }

            MoveSchemaFiles(tempDirectory, directory);
        }
Exemple #15
0
        public TemplateContextBuilder(IObjectRepository tdb, ImplementationGuideType igType, SimpleSchema igTypeSchema, string prefix = null)
        {
            this.tdb          = tdb;
            this.igType       = igType;
            this.plugin       = this.igType.GetPlugin();
            this.igTypeSchema = igTypeSchema;
            this.prefix       = !string.IsNullOrEmpty(prefix) ? prefix : igType.SchemaPrefix;

            if (!string.IsNullOrEmpty(this.prefix) && this.prefix.EndsWith(":"))
            {
                this.prefix = this.prefix.Substring(0, this.prefix.Length - 1);
            }
        }
Exemple #16
0
        public IEnumerable <string> GetAll(int id)
        {
            //id, name, schemalocation
            ImplementationGuideType igType = tdb.ImplementationGuideTypes.Single(y => y.Id == id);

            var schema = schemaFactory.Create(helper.GetIGSimplifiedSchemaLocation2(igType));

            var types = from t in schema.ComplexTypes
                        orderby t.Name
                        select t.Name;

            return(types);
        }
Exemple #17
0
        public static ImplementationGuideType GetImplementationGuideType(IObjectRepository tdb, bool throwError)
        {
            ImplementationGuideType found = tdb.ImplementationGuideTypes.SingleOrDefault(y => y.Name.ToLower() == Constants.IGTypeNames.FHIR_DSTU2.ToLower());

            if (found == null && throwError)
            {
                string errorMsg = "No DSTU2 FHIR IG Type is defined/configured";
                Log.For(typeof(DSTU2Helper)).Error(errorMsg);
                throw new Exception(errorMsg);
            }

            return(found);
        }
Exemple #18
0
        public HttpResponseMessage GetProfile(string templateOid, string _format = "")
        {
            string fhirTemplatesExportString = string.Empty;
            ImplementationGuideType igType   = GetFHIRIGType();
            User currentUser = CheckPoint.Instance.GetUser();
            int  templateId  = 0;

            Int32.TryParse(templateOid, out templateId);

            var             fhirTemplatesQuery = this.tdb.Templates.Where(y => (y.Id == templateId || y.Oid == templateOid) && y.ImplementationGuideTypeId == igType.Id);
            List <Template> fhirTemplates;

            if (!CheckPoint.Instance.IsDataAdmin)
            {
                fhirTemplates = (from vtp in this.tdb.ViewTemplatePermissions
                                 join t in fhirTemplatesQuery on vtp.TemplateId equals t.Id
                                 where vtp.UserId == currentUser.Id
                                 select t)
                                .ToList();
            }
            else
            {
                fhirTemplates = fhirTemplatesQuery.ToList();
            }

            if (fhirTemplates.Count == 0)
            {
                throw new Exception("Could not find specified FHIR profile/template.");
            }

            try
            {
                fhirTemplatesExportString = FHIRExporter.GenerateExport(this.tdb, fhirTemplates, new IGSettingsManager(this.tdb));
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to generate bundle export of FHIR templates: " + ex.Message, ex);
            }

            try
            {
                Bundle fhirTemplatesBundle = FhirParser.ParseBundleFromXml(fhirTemplatesExportString);
                return(GetResponseMessage(_format, fhirTemplatesBundle));
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to parse exported bundle for return: " + ex.Message, ex);
            }
        }
        private void UpdateProperties(ImplementationGuide implementationGuide, ImplementationGuideType igType, ImportImplementationGuide importImplementationGuide)
        {
            var importIgStatus = GetImportStatus(importImplementationGuide);

            if (implementationGuide.Organization == null)
            {
                implementationGuide.Organization = CheckPoint.Instance.GetUser(this.tdb).Organization;
            }

            if (implementationGuide.Name != importImplementationGuide.name)
            {
                implementationGuide.Name = importImplementationGuide.name;
            }

            if (implementationGuide.ImplementationGuideType != igType)
            {
                implementationGuide.ImplementationGuideType = igType;
            }

            if (implementationGuide.Version != importImplementationGuide.version)
            {
                implementationGuide.Version = importImplementationGuide.version;
            }

            if (implementationGuide.DisplayName != importImplementationGuide.displayName)
            {
                implementationGuide.DisplayName = importImplementationGuide.displayName;
            }

            if (implementationGuide.WebReadmeOverview != importImplementationGuide.WebReadmeOverview)
            {
                implementationGuide.WebReadmeOverview = importImplementationGuide.WebReadmeOverview;
            }

            if (implementationGuide.WebDisplayName != importImplementationGuide.webDisplayName)
            {
                implementationGuide.WebDisplayName = importImplementationGuide.webDisplayName;
            }

            if (implementationGuide.WebDescription != importImplementationGuide.WebDescription)
            {
                implementationGuide.WebDescription = importImplementationGuide.WebDescription;
            }

            if (implementationGuide.PublishStatus != importIgStatus)
            {
                implementationGuide.PublishStatus = importIgStatus;
            }
        }
        public IHttpActionResult GetClientConfig(bool isRef = false)
        {
            var clientConfig = new ClientConfigModel();

            foreach (IGTypeFhirElement fit in IGTypeSection.GetSection().FhirIgTypes)
            {
                ImplementationGuideType igType = this.tdb.ImplementationGuideTypes.SingleOrDefault(y => y.Name.ToLower() == fit.ImplementationGuideTypeName.ToLower());

                if (igType == null)
                {
                    Log.For(this).Warn("Configured FHIR IG Type could not be found in the database: " + fit.ImplementationGuideTypeName);
                    continue;
                }

                var fhirIgType = new ClientConfigModel.FhirIgType()
                {
                    Id      = igType.Id,
                    Name    = igType.Name,
                    Version = fit.Version,
                    BaseUrl = ""
                };

                switch (fhirIgType.Version)
                {
                case "DSTU1":
                    fhirIgType.BaseUrl = "/api/FHIR1/";
                    break;

                case "DSTU2":
                    fhirIgType.BaseUrl = "/api/FHIR2/";
                    break;

                case "STU3":
                    fhirIgType.BaseUrl = "/api/FHIR3/";
                    break;
                }

                clientConfig.FhirIgTypes.Add(fhirIgType);
            }

            if (isRef)
            {
                var clientConfigJson = Newtonsoft.Json.JsonConvert.SerializeObject(clientConfig);
                return(Content <string>(HttpStatusCode.OK, "var trifoliaConfig = " + clientConfigJson + ";", new Formatters.JavaScriptFormatter(), "text/javascript"));
            }

            return(Content <ClientConfigModel>(HttpStatusCode.OK, clientConfig));
        }
Exemple #21
0
        public FHIRLatestStructureDefinitionController(IObjectRepository tdb, HttpRequestMessage request = null)
        {
            Log.For(this).Trace("Instantiating controller");

            this.tdb = tdb;

            // NOTE: This is for unit testing only
            if (request != null)
            {
                this.Request = request;
            }

            this.implementationGuideType = LatestHelper.GetImplementationGuideType(this.tdb, true);

            Log.For(this).Trace("Done instantiating controller");
        }
Exemple #22
0
        /// <summary>
        /// Used to test different narrative constraint generation combinations.
        /// </summary>
        /// <returns></returns>
        public static MockObjectRepository GenerateMockDataset2()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            mockRepo.FindOrCreateCodeSystem("SNOMED CT", "6.96");
            mockRepo.FindOrCreateCodeSystem("HL7ActStatus", "113883.5.14");
            CodeSystem hl7CodeSystem = mockRepo.FindOrCreateCodeSystem("HL7", "1.2.3");

            ValueSet genderCodeValueSet = mockRepo.FindOrCreateValueSet("GenderCode", "11.1");

            mockRepo.FindOrCreateValueSetMember(genderCodeValueSet, hl7CodeSystem, "M", "Male", "active", "01/02/2012");
            mockRepo.FindOrCreateValueSetMember(genderCodeValueSet, hl7CodeSystem, "F", "Female", "active", "01/02/2012");
            mockRepo.FindOrCreateValueSetMember(genderCodeValueSet, hl7CodeSystem, "U", "Undetermined", "active", "01/02/2012");

            ImplementationGuideType igType = mockRepo.FindOrCreateImplementationGuideType("CDA", "CDA.xsd", "cda", "urn:hl7-org:v3");

            ImplementationGuide ig = mockRepo.FindOrAddImplementationGuide(igType, "The IG");

            TemplateType docType = mockRepo.FindOrCreateTemplateType(igType, "Document", "ClinicalDocument", "ClinicalDocument", 1);

            Template template1 = mockRepo.GenerateTemplate("1.2.3.4.5.6", docType, "Test Template 1", ig, null, null, "Test Description 1", "Test Notes 1");
            Template template2 = mockRepo.GenerateTemplate("1.2.3.4.5.6.5", docType, "Test Template 2", ig, null, null, "Test Description 2", "Test Notes 2");

            mockRepo.GenerateConstraint(template1, null, null, "value", "SHALL", "1..1", null, null, null, null, null, null);
            mockRepo.GenerateConstraint(template1, null, null, "@classCode", "SHALL", "1..1", null, null, "OBS", "Observation", null, mockRepo.CodeSystems.Single(y => y.Id == 2));
            mockRepo.GenerateConstraint(template1, null, null, "templateId/@root", "SHALL", "1..1", null, null, "22.4.47", null, null, null);
            mockRepo.GenerateConstraint(template1, null, null, "code", "SHALL", "1..1", "CD", null, null, null, null, null);
            mockRepo.GenerateConstraint(template1, null, template2, null, "MAY", "0..1", null, null, null, null, null, null);
            mockRepo.GenerateConstraint(template1, null, null, "administrativeGenderCode/@code", "SHALL", "1..1", null, "MAY", null, null, mockRepo.ValueSets.Single(y => y.Id == 1), null);
            mockRepo.GenerateConstraint(template1, null, null, "statusCode", "SHALL", "1..1", null, null, "completed", "Completed", null, mockRepo.CodeSystems.Single(y => y.Id == 2));
            mockRepo.GenerateConstraint(template1, null, null, "code/@code", "SHALL", "1..1", "CD", "SHALL", "1234-X", "Test Disp", null, mockRepo.CodeSystems.Single(y => y.Id == 1));
            mockRepo.GenerateConstraint(template1, null, null, "code", "SHALL", "1..1", "CD", "SHALL", "1234-X", "Test Disp", null, mockRepo.CodeSystems.Single(y => y.Id == 1));

            Template template3 = mockRepo.GenerateTemplate("1.2.3.4.5.6.7", docType, "Test Template 3", ig, null, null, "Test Description 3", "");

            TemplateConstraint template3_c1 = mockRepo.GenerateConstraint(template3, null, null, "code", "SHALL", "1..1");

            template3_c1.Category = "TestCategory";

            return(mockRepo);
        }
Exemple #23
0
        private DefaultSampleGenerator(IObjectRepository tdb, Template template)
        {
            this.tdb      = tdb;
            this.template = template;

            this.simpleSchema =
                SimpleSchema.CreateSimpleSchema(
                    Helper.GetIGSimplifiedSchemaLocation(template.ImplementationGuideType));

            if (string.IsNullOrEmpty(this.template.PrimaryContextType))
            {
                this.simpleSchema = this.simpleSchema.GetSchemaFromContext(template.TemplateType.RootContextType);
            }
            else
            {
                this.simpleSchema = this.simpleSchema.GetSchemaFromContext(template.PrimaryContextType);
            }

            this.igType       = template.ImplementationGuideType;
            this.igTypePlugin = this.igType.GetPlugin();
        }
        public void Setup()
        {
            this.tdb = new MockObjectRepository();

            ImplementationGuideType cdaType = this.tdb.FindOrCreateImplementationGuideType(Constants.IGTypeNames.CDA, Constants.IGTypeSchemaLocations.CDA, Constants.IGTypePrefixes.CDA, Constants.IGTypeNamespaces.CDA);
            TemplateType            docType = this.tdb.FindOrCreateTemplateType(cdaType, "Document Templates", "ClinicalDocument", "ClinicalDocument", 1);
            ImplementationGuide     ig      = this.tdb.FindOrCreateImplementationGuide(cdaType, "Test IG");

            this.template1          = this.tdb.CreateTemplate("1.2.3.4.5", docType, "Test Template 1", ig);
            this.template1.Bookmark = "TEST_TEMPLATE1";
            this.template2          = this.tdb.CreateTemplate("5.4.3.2.1", docType, "Test Template 2", ig);
            this.template2.Bookmark = "TEST_TEMPLATE2";

            MemoryStream ms = new MemoryStream();

            this.doc               = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document);
            this.mainPart          = this.doc.AddMainDocumentPart();
            this.mainPart.Document =
                new Document(
                    new Body());
        }
        public static IIGTypePlugin GetPlugin(ImplementationGuideType igType)
        {
            IGTypeSection       config        = IGTypeSection.GetSection();
            IGTypePluginElement configElement = config.Plugins[igType.Name];

            if (configElement == null)
            {
                throw new Exception("Plugin not configured for this type of schema!");
            }

            Type type = Type.GetType(configElement.PluginAssembly);

            if (type == null)
            {
                throw new Exception("Plugin not loaded for IG Type: " + configElement.PluginAssembly);
            }

            var pluginInterface = (IIGTypePlugin)Activator.CreateInstance(type);

            return(pluginInterface);
        }
Exemple #26
0
        public void Setup()
        {
            this.tdb = new MockObjectRepository();

            ImplementationGuideType cdaType = this.tdb.FindOrCreateImplementationGuideType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "cda.xsd", "cda", "urn:hl7-org:v3");
            TemplateType            docType = this.tdb.FindOrCreateTemplateType(cdaType, "Document Templates", "ClinicalDocument", "ClinicalDocument", 1);
            ImplementationGuide     ig      = this.tdb.FindOrAddImplementationGuide(cdaType, "Test IG");

            this.template1          = this.tdb.GenerateTemplate("1.2.3.4.5", docType, "Test Template 1", ig);
            this.template1.Bookmark = "TEST_TEMPLATE1";
            this.template2          = this.tdb.GenerateTemplate("5.4.3.2.1", docType, "Test Template 2", ig);
            this.template2.Bookmark = "TEST_TEMPLATE2";

            MemoryStream ms = new MemoryStream();

            this.doc               = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document);
            this.mainPart          = this.doc.AddMainDocumentPart();
            this.mainPart.Document =
                new Document(
                    new Body());
        }
Exemple #27
0
        public static ImplementationGuideType GetImplementationGuideType(IObjectRepository tdb, bool throwError)
        {
            ImplementationGuideType found = null;

            foreach (IGTypeFhirElement configFhirIgType in IGTypeSection.GetSection().FhirIgTypes)
            {
                if (configFhirIgType.Version == VERSION_NAME)
                {
                    found = tdb.ImplementationGuideTypes.SingleOrDefault(y => y.Name.ToLower() == configFhirIgType.ImplementationGuideTypeName.ToLower());
                    break;
                }
            }

            if (found == null && throwError)
            {
                string errorMsg = "No STU3 FHIR IG Type is defined/configured";
                Log.For(typeof(STU3Helper)).Error(errorMsg);
                throw new Exception(errorMsg);
            }

            return(found);
        }
Exemple #28
0
        public ConstraintParser(IObjectRepository tdb, IConstraint constraint, ImplementationGuideType igType, string valueSetFile = "voc.xml", VocabularyOutputType vocabularyOutputType = VocabularyOutputType.Default)
        {
            this.tdb          = tdb;
            this.constraint   = constraint;
            this.valueSetFile = valueSetFile;
            this.igTypePlugin = igType.GetPlugin();

            if (this.constraint.ValueSetId != null)
            {
                this.constraintValueSet = this.tdb.ValueSets.Single(y => y.Id == constraint.ValueSetId);
            }

            if (this.constraint.ValueCodeSystemId != null)
            {
                this.constraintCodeSystem = this.tdb.CodeSystems.Single(y => y.Id == constraint.ValueCodeSystemId);
            }

            if (!string.IsNullOrEmpty(this.constraint.Cardinality))
            {
                this.constraintCardinalityType = CardinalityParser.Parse(this.constraint.Cardinality);
            }

            if (!string.IsNullOrEmpty(this.constraint.Conformance))
            {
                this.constraintConformanceType = ConformanceParser.Parse(this.constraint.Conformance);
            }

            if (this.constraint.ContainedTemplateId != null)
            {
                this.containedTemplate = this.tdb.Templates.Single(y => y.Id == this.constraint.ContainedTemplateId.Value);
            }

            this.prefix = igType.SchemaPrefix;

            this.vocabularyOutputType = vocabularyOutputType;
        }
 public FHIR3ImplementationGuideController(IObjectRepository tdb)
 {
     this.tdb = tdb;
     this.implementationGuideType = STU3Helper.GetImplementationGuideType(this.tdb, true);
 }
Exemple #30
0
        public TypeModel SaveType(TypeModel model)
        {
            using (var transaction = this.tdb.BeginTransaction())
            {
                ImplementationGuideType igType = new ImplementationGuideType();

                if (model.Id != null)
                {
                    igType = this.tdb.ImplementationGuideTypes.Single(y => y.Id == model.Id);
                }
                else
                {
                    this.tdb.ImplementationGuideTypes.AddObject(igType);
                }

                if (igType.Name != model.Name)
                {
                    if (!string.IsNullOrEmpty(igType.Name))
                    {
                        string currentDirectory = Shared.Helper.GetSchemasDirectory(igType.Name);
                        string newDirectory     = Shared.Helper.GetSchemasDirectory(model.Name);
                        MoveSchemaFiles(currentDirectory, newDirectory);
                    }

                    igType.Name = model.Name;
                }

                if (igType.SchemaLocation != model.SchemaLocation)
                {
                    igType.SchemaLocation = model.SchemaLocation;
                }

                if (igType.SchemaPrefix != model.SchemaPrefix)
                {
                    igType.SchemaPrefix = model.SchemaPrefix;
                }

                if (igType.SchemaURI != model.SchemaUri)
                {
                    igType.SchemaURI = model.SchemaUri;
                }

                // Update template types
                foreach (var templateTypeModel in model.DeletedTemplateTypes)
                {
                    var templateType = igType.TemplateTypes.Single(y => y.Id == templateTypeModel.Id);
                    this.tdb.TemplateTypes.DeleteObject(templateType);
                }

                foreach (var templateTypeModel in model.TemplateTypes)
                {
                    SaveTemplateType(igType, templateTypeModel);
                }

                // Update data types
                var newDataTypes    = model.DataTypes.Where(y => igType.DataTypes.Count(x => x.DataTypeName == y) == 0).ToList();
                var deleteDataTypes = igType.DataTypes.Where(y => model.DataTypes.Count(x => x == y.DataTypeName) == 0).ToList();

                foreach (var current in newDataTypes)
                {
                    var newDataType = new ImplementationGuideTypeDataType()
                    {
                        ImplementationGuideType = igType,
                        DataTypeName            = current
                    };
                    this.tdb.ImplementationGuideTypeDataTypes.AddObject(newDataType);
                }

                foreach (var current in deleteDataTypes)
                {
                    current.green_constraint.ToList().ForEach(y => { y.ImplementationGuideTypeDataType = null; });
                    this.tdb.ImplementationGuideTypeDataTypes.DeleteObject(current);
                }

                this.tdb.SaveChanges();

                try
                {
                    // If a new schema file is attached, save it
                    if (!string.IsNullOrEmpty(model.SchemaFileContentType))
                    {
                        switch (model.SchemaFileContentType)
                        {
                        case "application/xml":
                            SaveSchemaFile(igType, model.SchemaFile);
                            break;

                        case "application/zip":
                        case "application/x-zip-compressed":
                            SaveSchemaZip(igType, model.SchemaFile);
                            break;

                        default:
                            throw new Exception("Unexpected file format " + model.SchemaFileContentType + " for new schema.");
                        }
                    }

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }

                return(GetImplementationGuideType(igType.Id));
            }
        }