public void BuildGreenSchemaTest_SeparatedDataTypes() { Template docTemplate = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4"); Template baseSectionTemplate = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1"); Template sectionTemplateReq = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1.1"); Template sectionTemplateOpt = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1.2"); Template entryTemplate = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1.3"); GreenTemplate greenDocTemplate = CreateGreenTemplate(docTemplate, "myGreenDoc"); string sectionXpath = "component/structuredBody/component/section"; var greenDoc = CreateGreenConstraint(greenDocTemplate, this.mockRepo.TemplateConstraints.Single(y => y.Number == 39704), null, "My Section", "mySection", sectionXpath); GreenTemplate greenSectionTemplateReq = CreateGreenTemplate(sectionTemplateReq, "myGreenSection"); string entryXpath = "entry/observation"; var greenSection = CreateGreenConstraint(greenSectionTemplateReq, this.mockRepo.TemplateConstraints.Single(y => y.Number == 39712), null, "My Entry", "myEntry", entryXpath); GreenTemplate greenEntryTemplate = CreateGreenTemplate(entryTemplate, "myEntry"); string hemoglobinXpath = "value"; var cdDataType = this.mockRepo.FindOrAddDataType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "CD"); var greenEntry = CreateGreenConstraint(greenEntryTemplate, this.mockRepo.TemplateConstraints.Single(y => y.Number == 39714), null, "Hemoglobin", "hemoglobin", hemoglobinXpath, cdDataType); GreenSchemaPackage package = GreenSchemaGenerator.Generate(mockRepo, docTemplate, true); Assert.IsNotNull(package); Assert.IsNotNull(package.GreenSchemaContent); Assert.AreNotEqual(0, package.GreenSchemaContent.Length); Assert.IsNotNull(package.GreenSchemaFileName); Assert.AreNotEqual(0, package.GreenSchemaFileName.Length); bool foundImport = package.GreenSchemaContent.IndexOf("<xs:import") > 0; Assert.IsTrue(foundImport, "Could not find <xs:import> in green schema content"); Assert.IsNotNull(package.DataTypesContent); Assert.AreNotEqual(0, package.DataTypesContent.Length); Assert.IsNotNull(package.DataTypesFileName); Assert.AreNotEqual(0, package.DataTypesFileName.Length); }
public HttpResponseMessage ExportGreen(GreenSettingsModel model) { if (!CheckPoint.Instance.GrantViewImplementationGuide(model.ImplementationGuideId)) { throw new AuthorizationException("You do not have permissions to this implementation guide."); } ImplementationGuide ig = this.tdb.ImplementationGuides.Single(y => y.Id == model.ImplementationGuideId); Template rootTemplate = this.tdb.Templates.Single(y => y.Id == model.RootTemplateId); // Generate the schema GreenSchemaPackage package = GreenSchemaGenerator.Generate(this.tdb, rootTemplate, model.SeparateDataTypes); using (ZipFile zip = new ZipFile()) { byte[] schemaContentBytes = ASCIIEncoding.UTF8.GetBytes(package.GreenSchemaContent); zip.AddEntry(package.GreenSchemaFileName, schemaContentBytes); // If the datatypes were separated into another schema if (!string.IsNullOrEmpty(package.DataTypesFileName)) { byte[] dataTypesContentBytes = ASCIIEncoding.UTF8.GetBytes(package.DataTypesContent); zip.AddEntry(package.DataTypesFileName, dataTypesContentBytes); } using (MemoryStream ms = new MemoryStream()) { zip.Save(ms); string packageFileName = string.Format("{0}_green.zip", ig.GetDisplayName(true)); byte[] data = ms.ToArray(); return(GetExportResponse(packageFileName, ZIP_MIME_TYPE, data)); } } }
public void BuildGreenSchemaTest_Basic() { var ivlts_dt = this.mockRepo.FindOrAddDataType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "IVL_TS"); Template docTemplate = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4"); Template baseSectionTemplate = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1"); Template sectionTemplateReq = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1.1"); Template sectionTemplateOpt = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1.2"); Template entryTemplate = this.mockRepo.Templates.Single(y => y.Oid == "urn:oid:1.2.3.4.1.3"); GreenTemplate greenDocTemplate = CreateGreenTemplate(docTemplate, "myGreenDoc"); string sectionXpath = "component/structuredBody/component/section"; var greenDoc = CreateGreenConstraint(greenDocTemplate, this.mockRepo.TemplateConstraints.Single(y => y.Number == 39704), null, "My Section", "mySection", sectionXpath); CreateGreenConstraint(greenDocTemplate, this.mockRepo.TemplateConstraints.Single(y => y.Number == 98023), null, "MyCode", "myCode", "code", ivlts_dt); GreenTemplate greenSectionTemplateReq = CreateGreenTemplate(sectionTemplateReq, "myGreenSection"); string entryXpath = "entry/observation"; var greenSection = CreateGreenConstraint(greenSectionTemplateReq, this.mockRepo.TemplateConstraints.Single(y => y.Number == 39712), null, "My Entry", "myEntry", entryXpath); GreenTemplate greenEntryTemplate = CreateGreenTemplate(entryTemplate, "myEntry"); string hemoglobinXpath = "value"; var cdDataType = this.mockRepo.FindOrAddDataType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "CD"); var greenEntry = CreateGreenConstraint(greenEntryTemplate, this.mockRepo.TemplateConstraints.Single(y => y.Number == 39714), null, "Hemoglobin", "hemoglobin", hemoglobinXpath, cdDataType); GreenSchemaPackage package = GreenSchemaGenerator.Generate(mockRepo, docTemplate); // Is the schema content a valid schema? AssertSchemaValid(package.GreenSchemaContent); // Load the schema into an XmlDocument so we can assert XPATH against it XmlDocument schemaDoc = new XmlDocument(); schemaDoc.LoadXml(package.GreenSchemaContent); XmlNamespaceManager nsManager = new XmlNamespaceManager(schemaDoc.NameTable); nsManager.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); /////////// // Test the schema generation results /////////// // XPATH = /xs:schema/xs:element[@name='myGreenDoc'] var rootElementDocTemplate = schemaDoc.SelectSingleNode( "/xs:schema/xs:element[@name='" + greenDocTemplate.Name + "']", nsManager); Assert.IsNotNull(rootElementDocTemplate, "Could not find correct root element for document template"); // XPATH = //xs:complexType[@name='myGreenDoc'] var docTemplateComplexType = schemaDoc.SelectSingleNode( "//xs:complexType[@name='" + greenDocTemplate.Name + "']", nsManager); Assert.IsNotNull(docTemplateComplexType, "Could not find complex type for document template"); // XPATH = xs:sequence/xs:choice/xs:element[@name='myGreenSection' and @type='myGreenSection'] var docTemplateElement = docTemplateComplexType.SelectSingleNode( "xs:sequence/xs:choice/xs:element[@name='" + greenSectionTemplateReq.Name + "' and @type='" + greenSectionTemplateReq.Name + "']", nsManager); Assert.IsNotNull(docTemplateElement, "Could not find section element within doc template"); // XPATH = //xs:complexType[@name='myGreenSection'] var sectionComplexType = schemaDoc.SelectSingleNode( "//xs:complexType[@name='" + greenSectionTemplateReq.Name + "']", nsManager); Assert.IsNotNull(sectionComplexType, "Could not find complex type for green section template"); // XPATH = xs:sequence/xs:element[@name='myEntry' and @type='myEntry'] var sectionTemplateElement = sectionComplexType.SelectSingleNode( "xs:sequence/xs:element[@name='" + greenEntryTemplate.Name + "' and @type='" + greenEntryTemplate.Name + "']", nsManager); Assert.IsNotNull(sectionTemplateElement, "Could not find entry element within section template"); // XPATH = //xs:complexType[@name='myEntry'] var entryComplexType = schemaDoc.SelectSingleNode( "//xs:complexType[@name='" + greenEntryTemplate.Name + "']", nsManager); Assert.IsNotNull(entryComplexType, "Could not find complex type for green entry template"); // XPATH = xs:sequence/xs:element[@name='hemoglobin'] var hemoglobinElement = entryComplexType.SelectSingleNode( "xs:sequence/xs:element[@name='hemoglobin']", nsManager); Assert.IsNotNull(hemoglobinElement, "Could not find element in entry for hemoglobin constraint."); Assert.IsNotNull(hemoglobinElement.Attributes["type"], "Hemoglobin element does not have a data-type specified."); Assert.AreEqual("CD", hemoglobinElement.Attributes["type"].Value, "Hemoglobin element's data type is not 'CD'."); // XPATH = //xs:complexType[@name='CD'] var dataTypeCDComplexType = schemaDoc.SelectSingleNode( "//xs:complexType[@name='CD']", nsManager); Assert.IsNotNull(dataTypeCDComplexType, "Could not find complex type 'CD' copied from base schema."); // XPATH = //xs:complexType[@name='ANY'] var dataTypeANYComplexType = schemaDoc.SelectSingleNode( "//xs:complexType[@name='ANY']", nsManager); Assert.IsNotNull(dataTypeANYComplexType, "Could not find complex type 'ANY' (referenced from 'CD') copied from base schema."); }
public void BuildGreenSchemaTest_CollapsedConstraint2() { ImplementationGuide ig = this.mockRepo.FindOrAddImplementationGuide(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "Testing"); Template docTemplate = this.mockRepo.GenerateTemplate("5.4.3.2.1", "Document", "Testing Collapsed", ig, "ClinicalDocument", "ClinicalDocument"); var recordTarget = this.mockRepo.GenerateConstraint(docTemplate, null, null, "recordTarget", "SHALL", "1..*"); var patientRole = this.mockRepo.GenerateConstraint(docTemplate, recordTarget, null, "patientRole", "SHALL", "1..1"); var patient = this.mockRepo.GenerateConstraint(docTemplate, patientRole, null, "patient", "SHALL", "1..1"); var patientGender = this.mockRepo.GenerateConstraint(docTemplate, patient, null, "administrativeGenderCode", "SHALL", "1..1"); var patientName = this.mockRepo.GenerateConstraint(docTemplate, patient, null, "name", "SHALL", "1..1"); var patientFirstName = this.mockRepo.GenerateConstraint(docTemplate, patientName, null, "given", "SHALL", "1..1"); var patientLastName = this.mockRepo.GenerateConstraint(docTemplate, patientName, null, "family", "SHALL", "1..1"); GreenTemplate greenDocTemplate = CreateGreenTemplate(docTemplate, "myGreenDoc"); string recordTargetXpath = "recordTarget"; var greenRecordTarget = CreateGreenConstraint(greenDocTemplate, recordTarget, null, "Patient", "patient", recordTargetXpath); string genderXpath = "recordTarget/patientRole/patient/administrativeGenderCode"; var ceDataType = this.mockRepo.FindOrAddDataType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "CE"); var greenPatientGender = CreateGreenConstraint(greenDocTemplate, patientGender, greenRecordTarget, "Gender", "gender", genderXpath, ceDataType); string nameXpath = "recordTarget/patientRole/patient/name"; var greenPatientName = CreateGreenConstraint(greenDocTemplate, patientName, greenRecordTarget, "Name", "name", nameXpath); string firstNameXpath = "recordTarget/patientRole/patient/name/given"; var stDataType = this.mockRepo.FindOrAddDataType(MockObjectRepository.DEFAULT_CDA_IG_TYPE_NAME, "ST"); var greenPatientFirstName = CreateGreenConstraint(greenDocTemplate, patientFirstName, greenPatientName, "First", "first", firstNameXpath, stDataType); string lastNameXpath = "recordTarget/patientRole/patient/name/family"; var greenPatientLastName = CreateGreenConstraint(greenDocTemplate, patientLastName, greenPatientName, "Last", "last", lastNameXpath, stDataType); GreenSchemaPackage package = GreenSchemaGenerator.Generate(mockRepo, docTemplate); // Is the schema content a valid schema? AssertSchemaValid(package.GreenSchemaContent); // Load the schema into an XmlDocument so we can assert XPATH against it XmlDocument schemaDoc = new XmlDocument(); schemaDoc.LoadXml(package.GreenSchemaContent); XmlNamespaceManager nsManager = new XmlNamespaceManager(schemaDoc.NameTable); nsManager.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema"); /////////// // Test the schema generation results /////////// // XPATH = /xs:schema/xs:element[@name='myGreenDoc'] var rootElementDocTemplate = schemaDoc.SelectSingleNode( "/xs:schema/xs:element[@name='" + greenDocTemplate.Name + "' and @type='" + greenDocTemplate.Name + "']", nsManager); Assert.IsNotNull(rootElementDocTemplate, "Could not find correct root element for document template"); // XPATH = /xs:schema/xs:complexType[@name='myGreenDoc'] var rootComplexTypeDocTemplate = schemaDoc.SelectSingleNode( "/xs:schema/xs:complexType[@name='" + greenDocTemplate.Name + "']", nsManager); Assert.IsNotNull(rootComplexTypeDocTemplate, "Could not find complex type for document template"); // XPATH = xs:sequence/xs:element[@name='patient' and @minOccurs='1' and @maxOccurs='unbounded'] var patientNode = rootComplexTypeDocTemplate.SelectSingleNode( "xs:sequence/xs:element[@name='patient' and @minOccurs='1' and @maxOccurs='unbounded']", nsManager); Assert.IsNotNull(patientNode, "Could not find patient element within myGreenDoc that has min and max occurs set correctly."); // XPATH = xs:complexType/xs:sequence/xs:element[@name='gender' and @minOccurs='1' and @maxOccurs='1'] var patientGenderNode = patientNode.SelectSingleNode( "xs:complexType/xs:sequence/xs:element[@name='gender' and @minOccurs='1' and @maxOccurs='1']", nsManager); Assert.IsNotNull(patientGenderNode, "Could not find gender element with correct min and max occurs within patient element."); // XPATH = xs:complexType/xs:sequence/xs:element[@name='name' and @minOccurs='1' and @maxOccurs='1'] var patientNameNode = patientNode.SelectSingleNode( "xs:complexType/xs:sequence/xs:element[@name='name' and @minOccurs='1' and @maxOccurs='1']", nsManager); Assert.IsNotNull(patientGenderNode, "Could not find name element with correct min and max occurs within patient element."); // XPATH = xs:complexType/xs:sequence/xs:element[@name='first' and @minOccurs='1' and @maxOccurs='1' and @type='ST'] var patientFirstNameNode = patientNameNode.SelectSingleNode( "xs:complexType/xs:sequence/xs:element[@name='first' and @minOccurs='1' and @maxOccurs='1' and @type='ST']", nsManager); Assert.IsNotNull(patientFirstNameNode, "Could not find name element with correct min and max occurs within patient element."); // XPATH = xs:complexType/xs:sequence/xs:element[@name='last' and @minOccurs='1' and @maxOccurs='1' and @type='ST'] var patientLastNameNode = patientNameNode.SelectSingleNode( "xs:complexType/xs:sequence/xs:element[@name='last' and @minOccurs='1' and @maxOccurs='1' and @type='ST']", nsManager); Assert.IsNotNull(patientLastNameNode, "Could not find name element with correct min and max occurs within patient element."); }