public void GetRecursiveTemplates_ThreeVersions_V3Changed()
        {
            MockObjectRepository tdb = new MockObjectRepository();

            tdb.InitializeCDARepository();

            // Version 1
            var implementationGuide1 = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "IG V1");
            var template1            = tdb.GenerateTemplate("1.2.3.4", "Document", "Doc Template V1", implementationGuide1, "ClinicalDocument", "ClinicalDocument");

            // Version 2
            var implementationGuide2 = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "IG V2", previousVersion: implementationGuide1);

            // Version 3
            var implementationGuide3 = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "IG V3", previousVersion: implementationGuide2);
            var template2            = tdb.GenerateTemplate("1.2.3.4", "Document", "Doc Template V3", implementationGuide3, "ClinicalDocument", "ClinicalDocument", previousVersion: template1);

            // Check list of templates for version 1
            var templates = implementationGuide1.GetRecursiveTemplates(tdb);

            Assert.IsNotNull(templates, "Version 1 returned null value");
            Assert.AreEqual(1, templates.Count, "Version 1 returned incorrect number of templates");

            // Check list of templates for version 2
            templates = implementationGuide2.GetRecursiveTemplates(tdb);
            Assert.IsNotNull(templates, "Version 2 returned null value");
            Assert.AreEqual(1, templates.Count, "Version 2 returned incorrect number of templates");

            // Check list of templates for version 3
            templates = implementationGuide3.GetRecursiveTemplates(tdb);
            Assert.IsNotNull(templates, "Version 3 returned null value");
            Assert.AreEqual(1, templates.Count, "Version 3 returned incorrect number of templates");
        }
        public void GetRecursiveTemplates_ContainedNotInferred_MultiVersions()
        {
            MockObjectRepository tdb = new MockObjectRepository();

            tdb.InitializeCDARepository();

            var externalIG  = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "External IG");
            var exTemplate1 = tdb.GenerateTemplate("4.3.2.1", "Entry", "Ext Entry Template", externalIG, "observation", "Observation");

            // Version 1, create the template
            var implementationGuide1 = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "IG V1");
            var template1            = tdb.GenerateTemplate("1.2.3.4", "Document", "Doc Template V1", implementationGuide1, "ClinicalDocument", "ClinicalDocument");
            var tc1 = tdb.GenerateConstraint(template1, null, null, "entryRelationship", "SHALL", "1..1");

            tdb.GenerateConstraint(template1, tc1, exTemplate1, "observation", "SHALL", "1..1");

            // Version 2, deprecate the template, remove contained external template
            var implementationGuide2 = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "IG V2", previousVersion: implementationGuide1);
            var template2            = tdb.GenerateTemplate("1.2.3.4", "Document", "Doc Template V2", implementationGuide2, "ClinicalDocument", "ClinicalDocument", previousVersion: template1);

            // Check list of templates for version 1
            var templates = implementationGuide1.GetRecursiveTemplates(tdb, inferred: false);

            Assert.IsNotNull(templates, "Version 1 returned null value");
            Assert.AreEqual(1, templates.Count, "Version 1 returned incorrect number of templates");

            // Check list of templates for version 2
            templates = implementationGuide2.GetRecursiveTemplates(tdb, inferred: false);
            Assert.IsNotNull(templates, "Version 2 returned null value");
            Assert.AreEqual(1, templates.Count, "Version 2 returned incorrect number of templates");
        }
Example #3
0
        public void TestGetTemplates()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            mockRepo.InitializeFHIR3Repository();
            mockRepo.InitializeLCGAndLogin();

            var ig       = mockRepo.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_FHIR_STU3_IG_TYPE_NAME, "Test IG");
            var template = mockRepo.GenerateTemplate("http://test.com/profile1", "Composition", "Test Composition", ig);

            HttpRequestMessage request = new HttpRequestMessage()
            {
                RequestUri = new Uri("http://localhost:8080/api/FHIR3/StructureDefinition")
            };
            HttpRequest  contextRequest  = new HttpRequest(null, "http://localhost:8080/api/FHIR3/StructureDefinition", null);
            HttpResponse contextResponse = new HttpResponse(new StringWriter());

            HttpContext.Current = new HttpContext(contextRequest, contextResponse);

            FHIR3StructureDefinitionController controller = new FHIR3StructureDefinitionController(mockRepo, request);
            var response = controller.GetTemplates();
            var result   = AssertHelper.IsType <NegotiatedContentResult <Bundle> >(response);

            Assert.IsNotNull(result.Content);
            Assert.AreEqual(1, result.Content.Entry.Count);

            var firstEntry = result.Content.Entry.First();

            Assert.AreEqual("http://localhost:8080/api/FHIR3/StructureDefinition/1", firstEntry.FullUrl);
            Assert.IsNotNull(firstEntry.Resource);

            var firstStrucDef = AssertHelper.IsType <StructureDefinition>(firstEntry.Resource);

            Assert.AreEqual("Test-Composition", firstStrucDef.Id);
        }
Example #4
0
        public void GenerateXMLTest()
        {
            MockObjectRepository mockTdb = new MockObjectRepository();

            mockTdb.InitializeCDARepository();

            ImplementationGuide ig       = mockTdb.FindOrAddImplementationGuide("CDA", "Test IG", null, DateTime.Now);
            Template            template = mockTdb.GenerateTemplate("urn:oid:2.16.22.22.11", "Document", "Test Doc Type", ig, "ClinicalDocument", "ClinicalDocument", "Test Description");
            var tca1 = mockTdb.GenerateConstraint(template, null, null, "@classCode", "SHALL", "1..1", value: "test1");
            var tca2 = mockTdb.GenerateConstraint(template, null, null, "@moodCode", "SHALL", "1..1", value: "test2");
            var tc1  = mockTdb.GenerateConstraint(template, null, null, "entryRelationship", "SHALL", "1..1");
            var tc2  = mockTdb.GenerateConstraint(template, tc1, null, "observation", "SHOULD", "0..1");
            var tc3  = mockTdb.GenerateConstraint(template, tc2, null, "value", "SHALL", "1..1", "CD", value: "4321", displayName: "Test");

            template.TemplateSamples = new System.Data.Entity.Core.Objects.DataClasses.EntityCollection <TemplateSample>();
            template.TemplateSamples.Add(new TemplateSample()
            {
                XmlSample = "<test><example>VALUE</example></test>"
            });

            List <Template> templates = new List <Template>();

            templates.Add(template);

            IGSettingsManager igSettings = new IGSettingsManager(mockTdb, ig.Id);
            TemplateExporter  exporter   = new TemplateExporter(templates, mockTdb, ig.Id);
            string            export     = exporter.GenerateXML();

            Assert.IsFalse(string.IsNullOrEmpty(export));
        }
        public void ExportTemplatesModelTest1()
        {
            MockObjectRepository tdb = new MockObjectRepository();

            tdb.InitializeCDARepository();

            Organization        org        = tdb.FindOrAddOrganization("LCG Test");
            ImplementationGuide ig         = tdb.FindOrAddImplementationGuide(tdb.FindImplementationGuideType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME), "Test Implementation Guide");
            IGSettingsManager   igSettings = new IGSettingsManager(tdb, ig.Id);

            Template template = tdb.GenerateTemplate("1.2.3.4", "Document", "Test Template", ig, "observation", "Observation", "Test Description", "Test Notes", org);
            var      tc1      = tdb.GenerateConstraint(template, null, null, "entryRelationship", "SHALL", "1..1");
            var      tc2      = tdb.GenerateConstraint(template, tc1, null, "observation", "SHOULD", "0..1");
            var      tc3      = tdb.GenerateConstraint(template, tc2, null, "value", "SHALL", "1..1", "CD", value: "4321", displayName: "Test");

            tc3.Description = "Test description";
            tc3.Label       = "Test Label";
            var tc4 = tdb.GeneratePrimitive(template, null, "SHALL", "This is a test");

            ExportTemplate export = template.Export(tdb, igSettings);

            Assert.IsNotNull(export);
            Assert.AreEqual(template.Oid, export.identifier);
            Assert.AreEqual(template.Name, export.title);
            Assert.AreEqual(template.TemplateType.Name, export.templateType);
            Assert.AreEqual(template.PrimaryContext, export.context);
            Assert.AreEqual(template.PrimaryContextType, export.contextType);
            Assert.AreEqual(template.Description, export.Description);
            Assert.AreEqual(template.Notes, export.Notes);
            Assert.AreEqual(template.OrganizationName, export.organizationName);

            // Assert constraints
            Assert.IsNotNull(export.Constraint);
            Assert.AreEqual(2, export.Constraint.Count);

            // tc1
            Assert.AreEqual(tc1.Context, export.Constraint[0].context);
            Assert.AreEqual(ExportConformanceTypes.SHALL, export.Constraint[0].conformance);
            Assert.AreEqual(tc1.Cardinality, export.Constraint[0].cardinality);

            // tc4
            Assert.IsNull(export.Constraint[1].context);
            Assert.AreEqual(true, export.Constraint[1].isPrimitive);
            Assert.AreEqual(tc4.PrimitiveText, export.Constraint[1].NarrativeText);

            // tc2
            Assert.AreEqual(1, export.Constraint[0].Constraint.Count);
            Assert.AreEqual(tc2.Context, export.Constraint[0].Constraint[0].context);
            Assert.AreEqual(ExportConformanceTypes.SHOULD, export.Constraint[0].Constraint[0].conformance);
            Assert.AreEqual(tc2.Cardinality, export.Constraint[0].Constraint[0].cardinality);

            // tc3
            Assert.AreEqual(1, export.Constraint[0].Constraint[0].Constraint.Count);
            Assert.AreEqual(tc3.Context, export.Constraint[0].Constraint[0].Constraint[0].context);
            Assert.AreEqual(ExportConformanceTypes.SHALL, export.Constraint[0].Constraint[0].Constraint[0].conformance);
            Assert.AreEqual(tc3.Cardinality, export.Constraint[0].Constraint[0].Constraint[0].cardinality);
            Assert.AreEqual(tc3.Description, export.Constraint[0].Constraint[0].Constraint[0].Description);
            Assert.AreEqual(tc3.Label, export.Constraint[0].Constraint[0].Constraint[0].Label);
            Assert.IsFalse(string.IsNullOrEmpty(export.Constraint[0].Constraint[0].Constraint[0].Description));
        }
        public void ExportTemplatesModelTest2()
        {
            MockObjectRepository tdb = new MockObjectRepository();

            tdb.InitializeCDARepository();

            Organization        org        = tdb.FindOrAddOrganization("LCG Test");
            ImplementationGuide ig         = tdb.FindOrAddImplementationGuide(tdb.FindImplementationGuideType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME), "Test Implementation Guide");
            IGSettingsManager   igSettings = new IGSettingsManager(tdb, ig.Id);

            Template template = tdb.GenerateTemplate("1.2.3.4", "Document", "Test Template", ig, "observation", "Observation", "Test Description", "Test Notes");

            ExportTemplate export = template.Export(tdb, igSettings);

            Assert.IsNotNull(export);
            Assert.AreEqual(template.Oid, export.identifier);
            Assert.AreEqual(template.Name, export.title);
            Assert.AreEqual(template.TemplateType.Name, export.templateType);
            Assert.AreEqual(template.PrimaryContext, export.context);
            Assert.AreEqual(template.PrimaryContextType, export.contextType);
            Assert.AreEqual(template.Description, export.Description);
            Assert.AreEqual(template.Notes, export.Notes);
            Assert.IsNull(export.organizationName);
            Assert.AreEqual(template.OwningImplementationGuide.Name, export.ImplementationGuide.name);
        }
Example #7
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);
        }
Example #8
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);
        }
        public void TestCloneTemplate()
        {
            MockObjectRepository mockDb = new MockObjectRepository();

            mockDb.InitializeCDARepository();
            var ig = mockDb.FindOrAddImplementationGuide("CDA", "My Test IG");

            var template1 = mockDb.GenerateTemplate("1.2.3.4.1", "Document", "My Test Template", ig);

            template1.AuthorId = 2;

            mockDb.GenerateConstraint(template1, null, null, "recordTarget", "SHALL", "1..1");

            template1.TemplateSamples.Add(new TemplateSample()
            {
                Name      = "My Test Sample",
                XmlSample = "<test></test>"
            });

            // Test 1
            var clone1 = template1.CloneTemplate(mockDb, null);

            Assert.IsNotNull(clone1);
            Assert.AreEqual("D_My_Test_Template (Copy)", clone1.Bookmark);
            Assert.AreEqual("My Test Template (Copy)", clone1.Name);
            Assert.AreEqual("1.2.3.4.1.1", clone1.Oid);
            Assert.AreEqual(2, clone1.AuthorId);
            Assert.AreEqual(1, clone1.Constraints.Count);

            // Test the sample for clone1
            Assert.AreEqual(1, clone1.TemplateSamples.Count);
            Assert.AreEqual("My Test Sample", clone1.TemplateSamples.First().Name);
            Assert.AreEqual("<test></test>", clone1.TemplateSamples.First().XmlSample);

            mockDb.Templates.AddObject(clone1);

            // Test 2
            var clone2 = template1.CloneTemplate(mockDb, 1);

            Assert.IsNotNull(clone2);
            Assert.AreEqual("D_My_Test_Template (Copy 2)", clone2.Bookmark);
            Assert.AreEqual("My Test Template (Copy 2)", clone2.Name);
            Assert.AreEqual("1.2.3.4.1.2", clone2.Oid);
            Assert.AreEqual(1, clone2.AuthorId);
            Assert.AreEqual(1, clone2.Constraints.Count);
        }
        public void ExportFHIRComposition()
        {
            MockObjectRepository tdb = new MockObjectRepository();

            tdb.InitializeFHIRRepository();

            ImplementationGuide ig = tdb.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_FHIR_DSTU1_IG_TYPE_NAME, "Test FHIR IG");
            Template            t  = tdb.GenerateTemplate("FHIR_1.2.3.4", "Composition", "Test FHIR Composition", ig, "Composition", "Composition");

            var tc1 = tdb.GenerateConstraint(t, null, null, "subject", "SHALL", "1..1");
            var tc2 = tdb.GenerateConstraint(t, null, null, "author", "SHALL", "1..1");

            List <Template> templates = new List <Template>();

            templates.Add(t);

            string export = FHIRExporter.GenerateExport(tdb, templates, new Trifolia.Shared.IGSettingsManager(tdb));

            Assert.IsNotNull(export, "Expected generated export not to be null");
            Assert.AreNotEqual(0, export.Length, "Expected generated export not to be empty");
        }
Example #11
0
        public void FindTemplate_Local_RelativeUrl_Test()
        {
            HttpRequestMessage request = new HttpRequestMessage();

            request.RequestUri = new Uri("http://test:100/");
            MockObjectRepository repo = new MockObjectRepository();

            repo.InitializeFHIR2Repository();

            var ig       = repo.FindOrAddImplementationGuide(repo.FindImplementationGuideType(MockObjectRepository.DEFAULT_FHIR_DSTU2_IG_TYPE_NAME), "Test IG");
            var template = repo.GenerateTemplate("urn:oid:1.2.3.4", repo.FindTemplateType(MockObjectRepository.DEFAULT_FHIR_DSTU2_IG_TYPE_NAME, "Composition"), "Test Template", ig);

            ResourceReference reference = new ResourceReference();

            reference.Reference = "StructureDefinition/" + template.Id;

            MockWebClient webClient     = new MockWebClient();
            var           foundTemplate = Shared.FindTemplate(request, webClient, repo, reference);

            Assert.IsNotNull(foundTemplate);
            Assert.AreEqual(template.Id, foundTemplate.Id);
            Assert.AreEqual(template.Name, foundTemplate.Name);
            Assert.AreEqual(0, webClient.RequestCount);
        }
Example #12
0
        public void TestConvertExtension()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            mockRepo.InitializeFHIR3Repository();
            mockRepo.InitializeLCG();

            var ig       = mockRepo.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_FHIR_STU3_IG_TYPE_NAME, "Test IG");
            var template = mockRepo.GenerateTemplate("http://test.com/fhir/test", "Composition", "Test Composition", ig, "Composition", "Composition");

            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test.com/extension",
                Type       = "String",
                Value      = "Test string extension value"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test2.com/extension",
                Type       = "Date",
                Value      = "2016234234234" // Invalid date format, but should still be parsed by FHIR library
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test3.com/extension",
                Type       = "Coding",
                Value      = "xyz-123|display|urn:oid:2.16.113"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()
            {
                Identifier = "http://test4.com/extension",
                Type       = "CodeableConcept",
                Value      = "xyz-123|display|urn:oid:2.16.113"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()         // Extension has invalid value... It is skipped
            {
                Identifier = "http://test5.com/extension",
                Type       = "CodeableConcept",
                Value      = "test"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()         // Extension has invalid value... It is skipped
            {
                Identifier = "http://test6.com/extension",
                Type       = "Boolean",
                Value      = "test"
            });
            template.Extensions.Add(new Trifolia.DB.TemplateExtension()         // Extension has invalid value... It is skipped
            {
                Identifier = "http://test7.com/extension",
                Type       = "Integer",
                Value      = "test"
            });

            StructureDefinitionExporter exporter = new StructureDefinitionExporter(mockRepo, "http", "test.com");
            SimpleSchema schema = SimpleSchema.CreateSimpleSchema(
                Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                    new ImplementationGuideType()
            {
                Name           = MockObjectRepository.DEFAULT_FHIR_STU3_IG_TYPE_NAME,
                SchemaLocation = "fhir-all.xsd"
            }));

            StructureDefinition strucDef = exporter.Convert(template, schema);

            Assert.IsNotNull(strucDef);
            Assert.IsNotNull(strucDef.Extension);
            Assert.AreEqual(strucDef.Extension.Count, 4);

            // Extension 1
            Assert.AreEqual(strucDef.Extension[0].Url, "http://test.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[0].Value, typeof(FhirString));
            Assert.AreEqual(((FhirString)strucDef.Extension[0].Value).Value, "Test string extension value");

            // Extension 2
            Assert.AreEqual(strucDef.Extension[1].Url, "http://test2.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[1].Value, typeof(Date));
            Assert.AreEqual(((Date)strucDef.Extension[1].Value).Value, "2016234234234");

            // Extension 3
            Assert.AreEqual(strucDef.Extension[2].Url, "http://test3.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[2].Value, typeof(Coding));
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).Code, "xyz-123");
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).Display, "display");
            Assert.AreEqual(((Coding)strucDef.Extension[2].Value).System, "urn:oid:2.16.113");

            // Extension 4
            Assert.AreEqual(strucDef.Extension[3].Url, "http://test4.com/extension");
            Assert.IsInstanceOfType(strucDef.Extension[3].Value, typeof(CodeableConcept));
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding.Count, 1);
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].Code, "xyz-123");
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].Display, "display");
            Assert.AreEqual(((CodeableConcept)strucDef.Extension[3].Value).Coding[0].System, "urn:oid:2.16.113");
        }
Example #13
0
        public void TemplateValidationSuccess()
        {
            Template newTemplate = tdb.GenerateTemplate("1.2.3.4", tdb.FindTemplateType("CDA", "Document"), "Test 1", this.ig, "section", "Section");
            var      tc1         = tdb.GenerateConstraint(newTemplate, null, null, "code", "SHALL", "1..1");

            tdb.GenerateConstraint(newTemplate, tc1, null, "@code", "SHALL", "1..1", value: "TEST", displayName: "TESTDISPLAY");
            tdb.GenerateConstraint(newTemplate, null, null, "title", "SHALL", "1..1");
            tdb.GenerateConstraint(newTemplate, null, null, "text", "SHALL", "1..1");
            var tc2 = tdb.GenerateConstraint(newTemplate, null, null, "entry", "SHALL", "1..1");

            tdb.GenerateConstraint(newTemplate, tc2, null, "observation", "SHALL", "1..1");

            List <TemplateValidationResult> errors = newTemplate.ValidateTemplate();

            Assert.IsNotNull(errors, "Errors list should not be null.");
            Assert.AreEqual(0, errors.Count, "Shouldn't have found any errors.");
        }
Example #14
0
        public void MyTestInitialize()
        {
            tdb = new MockObjectRepository();

            // IG Type
            ImplementationGuideType cdaType = tdb.FindOrCreateImplementationGuideType("CDA", "cda.xsd", "cda", "urn:hl7-org:v3");

            // Template Type
            TemplateType docType = tdb.FindOrCreateTemplateType(cdaType, "document", "ClinicalDocument", "ClinicalDocument", 1);
            TemplateType secType = tdb.FindOrCreateTemplateType(cdaType, "section", "section", "Section", 2);
            TemplateType entType = tdb.FindOrCreateTemplateType(cdaType, "entry", "entry", "Entry", 3);

            // Code System
            CodeSystem cs1 = tdb.FindOrCreateCodeSystem("SNOMED CT", "6.36");

            // Value Set
            ValueSet vs1 = tdb.FindOrCreateValueSet("Test Value Set 1", "1.2.3.4");

            tdb.FindOrCreateValueSetMember(vs1, cs1, "1234", "Test Member 1");
            tdb.FindOrCreateValueSetMember(vs1, cs1, "4321", "Test Member 2");

            // Implementation Guide
            ImplementationGuide ig1 = tdb.FindOrAddImplementationGuide(cdaType, "Test Implementation Guide 1", publishDate: new DateTime(2012, 1, 1));

            // IG Files
            byte[] testSchBytes = Helper.GetSampleContentBytes("Trifolia.Test.DocSamples.test.sch");

            ImplementationGuideFile testSchFile = tdb.GenerateImplementationGuideFile(ig1, "test.sch", ImplementationGuideFile.ContentTypeSchematron, "text/xml", content: testSchBytes);

            this.testSchFileId = testSchFile.Id;

            tdb.GenerateImplementationGuideFile(ig1, "voc.xml", ImplementationGuideFile.ContentTypeVocabulary, "text/xml", content: testSchBytes);
            tdb.GenerateImplementationGuideFile(ig1, "test1_template1.ent", ImplementationGuideFile.ContentTypeSchematronHelper, "text/xml", content: testSchBytes);

            ImplementationGuide ig2 = tdb.FindOrAddImplementationGuide(cdaType, "Test Implementation Guide 2");

            // Template 1
            Template t1 = tdb.GenerateTemplate("urn:oid:1.2.3.4", docType, "Test Template", ig1, null, null, null);

            tdb.GenerateConstraint(t1, null, null, "title", "SHALL", "1..1");

            // Template 2
            Template           t2     = tdb.GenerateTemplate("urn:oid:1.2.3.4.1", docType, "Test Template", ig1, null, null, null);
            TemplateConstraint t2_tc1 = tdb.GenerateConstraint(t2, null, null, "title", "SHALL", "1..1");

            t2_tc1.Schematron = "count(cda:title)";

            TemplateConstraint t2_tc2 = tdb.GeneratePrimitive(t2, null, "SHALL", "This is a test primitive");

            tdb.GeneratePrimitive(t2, null, "SHALL", "This is test primitive #2", "count(cda:title) &gt; 0");

            // Template 3
            Template t3 = tdb.GenerateTemplate("urn:oid:1.2.3.4.2", docType, "Test Template", ig2, null, null, null);

            tdb.GenerateConstraint(t1, null, null, "title", "SHOULD", "1..1");

            // Template 4
            Template           t4    = tdb.GenerateTemplate("urn:oid:1.2.3.4.3", docType, "Test Template", ig2, null, null, null);
            TemplateConstraint t4_p1 = tdb.GenerateConstraint(t4, null, null, "entryRelationship", "SHALL", "1..1", null, null, null, null, null, null, null, true);
            TemplateConstraint t4_p2 = tdb.GenerateConstraint(t4, t4_p1, null, "@typeCode", "SHALL", "1..1", null, null, "DRIV");
            TemplateConstraint t4_p3 = tdb.GenerateConstraint(t4, t4_p1, null, "observation", "SHALL", "1..1", null, null, "DRIV", null, null, null, null, true);
        }
Example #15
0
        /// <summary>
        /// Data set is used to test implementation guide generation (the MS Word document export) and to test importing/exporting
        /// implementation guides in the legacy trifolia format.
        /// </summary>
        public static MockObjectRepository GenerateMockDataset1()
        {
            MockObjectRepository mockRepo = new MockObjectRepository();

            Organization internalOrg = mockRepo.FindOrAddOrganization("Lantana");
            Organization testOrg     = mockRepo.FindOrAddOrganization("Test Organization");

            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);
            TemplateType entryType    = mockRepo.FindOrCreateTemplateType(igType, "Entry", "entry", "Entry", 3);
            TemplateType subEntryType = mockRepo.FindOrCreateTemplateType(igType, "Sub-Entry", "entry", "Entry", 4);
            TemplateType otherType    = mockRepo.FindOrCreateTemplateType(igType, "Other", string.Empty, string.Empty, 5);

            mockRepo.FindOrCreateValueSet("Test Value Set", "9.8.7.6.5.4.3.2.1");

            ImplementationGuide ig = mockRepo.FindOrAddImplementationGuide(igType, "Test Implementation Guide", internalOrg);

            mockRepo.FindOrAddImplementationGuide(igType, "Test IG 2", testOrg);
            mockRepo.FindOrAddImplementationGuide(igType, "Test IG 3", internalOrg);

            Template template1 = mockRepo.GenerateTemplate("1.2.3.4.5", docType, "Test Template 1", ig, null, null, "Test Description 2", "Test Note 1");

            template1.Notes = "This is a test note";

            // Basic constraint, nothing special
            TemplateConstraint t1tc1 = mockRepo.GenerateConstraint(template1, null, null, "templateId", "SHALL", "1..1");

            t1tc1.Notes = "This is a test constraint comment";

            // Constraint with a child
            TemplateConstraint t1tc2   = mockRepo.GenerateConstraint(template1, null, null, "code", "SHALL", "1..1");
            TemplateConstraint t1tc2_2 = mockRepo.GenerateConstraint(template1, t1tc2, null, "@code", "SHALL", "1..1", null, null, "12345X", "Test Static Value");

            // Constraint with a child (child has valueset)
            ValueSet           t1tc3_vs = mockRepo.FindOrCreateValueSet("Test Valueset", "9.8.7.6.5.4.3.2.1");
            TemplateConstraint t1tc3    = mockRepo.GenerateConstraint(template1, null, null, "code", "SHALL", "1..1");
            TemplateConstraint t1tc3_1  = mockRepo.GenerateConstraint(template1, t1tc3, null, "@code", "SHALL", "1..1", "CE", "SHALL", null, null, t1tc3_vs);

            t1tc3_1.IsStatic = true;

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

            template2.ImpliedTemplate = template1;

            // Constraint with a child
            TemplateConstraint t2tc1 = mockRepo.GenerateConstraint(template2, null, null, "code", "SHALL", "1..1");

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

            TemplateConstraint t3tc1   = mockRepo.GenerateConstraint(template3, null, template2, null, "SHALL", "1..1");
            TemplateConstraint t3tc2   = mockRepo.GenerateConstraint(template3, null, null, "entry", "SHALL", "1..1");
            TemplateConstraint t3tc2_1 = mockRepo.GenerateConstraint(template3, t3tc2, template2, "observation", "SHALL", "1..1");

            Template template4 = mockRepo.GenerateTemplate("8.2234.19.234.11", docType, "Test Constraint Description Template", ig, null, null, null, null);

            mockRepo.GenerateConstraint(template4, null, null, "code", "SHALL", "1..1", "CD", null, null, null, null, null, "Test constraint description");

            return(mockRepo);
        }