Example #1
0
        public void CloneTemplateTest()
        {
            MockObjectRepository repo = TestDataGenerator.GenerateMockDataset1();
            var      user             = repo.FindOrAddUser("test.user", repo.FindOrAddOrganization("LCG"));
            Template firstTemplate    = repo.Templates.First();

            Template secondTemplate = firstTemplate.CloneTemplate(repo, user.Id);

            repo.Templates.AddObject(secondTemplate);
            Assert.AreNotEqual(firstTemplate.Name, secondTemplate.Name, "Title for the first template should be different than the cloned template.");
            Assert.AreEqual(firstTemplate.Oid + ".1", secondTemplate.Oid, "Expected the second template's oid to have .1 added to it.");

            // Test that other properties were copied
            Assert.AreEqual(firstTemplate.ImplementationGuideTypeId, secondTemplate.ImplementationGuideTypeId);
            Assert.AreEqual(firstTemplate.TemplateTypeId, secondTemplate.TemplateTypeId);
            Assert.AreEqual(firstTemplate.OwningImplementationGuideId, secondTemplate.OwningImplementationGuideId);
            Assert.AreEqual(firstTemplate.ImpliedTemplateId, secondTemplate.ImpliedTemplateId);
            Assert.AreEqual(firstTemplate.PrimaryContext, secondTemplate.PrimaryContext);
            Assert.AreEqual(firstTemplate.PrimaryContextType, secondTemplate.PrimaryContextType);
            Assert.AreEqual(firstTemplate.IsOpen, secondTemplate.IsOpen);

            // Test that making more than 10 copies properly generates the title and oid
            Template lastCopiedTemplate = null;
            int      count = 1;

            while (count < 11)
            {
                lastCopiedTemplate = firstTemplate.CloneTemplate(repo, user.Id);
                repo.Templates.AddObject(lastCopiedTemplate);
                count++;
            }

            Assert.AreEqual(firstTemplate.Oid + ".12", lastCopiedTemplate.Oid, "Generated oid for copied templates is not working when there are more than 10 copies.");
            Assert.AreEqual(firstTemplate.Name + " (Copy 11)", lastCopiedTemplate.Name, "Genrated title for copied templates is not working when there are more than 10 copies.");
        }
        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);
        }
        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));
        }
Example #4
0
        public void CheckPoint_CheckHL7Roles()
        {
            MockObjectRepository mockRepo = TestDataGenerator.GenerateMockDataset1();

            mockRepo.FindOrAddUser("testuser", mockRepo.FindOrAddOrganization(Helper.AUTH_EXTERNAL));
            mockRepo.AddRole("Users");
            mockRepo.AddRole("HL7 Members");
            mockRepo.AssociateUserWithRole("testuser", mockRepo.FindOrAddOrganization(Helper.AUTH_EXTERNAL).Id, "Users");

            //With Role Restriction added, try to add role, Assert role did not get added
            Role role = mockRepo.Roles.Single(y => y.Name == "HL7 Members");

            role.Restrictions.Add(new RoleRestriction()
            {
                Role           = role,
                RoleId         = role.Id,
                OrganizationId = mockRepo.FindOrAddOrganization(Helper.AUTH_EXTERNAL).Id,
                Organization   = mockRepo.FindOrAddOrganization(Helper.AUTH_EXTERNAL)
            });

            DBContext.Instance = mockRepo;
            CheckPoint.Instance.CheckHL7Roles("testuser", "ismember");

            User user = mockRepo.Users.SingleOrDefault(y => y.UserName == "testuser" && y.Organization.Name == Helper.AUTH_EXTERNAL);

            Assert.IsTrue(user.UserName == "testuser");
            Assert.IsTrue(user.Roles.Count(y => y.Role.Name == "Users") > 0);
            Assert.IsFalse(user.Roles.Count(y => y.Role.Name == "HL7 Members") > 0);


            //Test for: Remove Role Restriction, try to modify role, Assert the role gets added

            role.Restrictions.Remove(role.Restrictions.SingleOrDefault(y => y.Organization.Name == Helper.AUTH_EXTERNAL));

            DBContext.Instance = mockRepo;
            CheckPoint.Instance.CheckHL7Roles("testuser", "ismember");

            Assert.IsTrue(user.UserName == "testuser");
            Assert.IsTrue(user.Roles.Count(y => y.Role.Name == "HL7 Members") > 0);

            //Should the old role be removed?
            //Assert.IsFalse(user.Roles.Count(y => y.Role.Name == "Users") > 0);
        }
Example #5
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);
        }