Exemplo n.º 1
0
 def add_IGD_refdef(self):
     itr1 = ODM.ItemRef(ItemOID="ODM.IT.VS.VSDAT", Mandatory="Yes")
     itr2 = ODM.ItemRef(ItemOID="ODM.IT.VS.BP.DIABP.VSORRES_BAD",
                        Mandatory="Yes")
     itr3 = ODM.ItemRef(ItemOID="ODM.IT.VS.BP.SYSBP.VSORRES",
                        Mandatory="Yes")
     igd1 = ODM.ItemGroupDef(OID="ODM.IG.VS",
                             Name="Vital Sign Measurement",
                             Repeating="Yes")
     igd1.ItemRef = [itr1, itr2, itr3]
     igr4 = ODM.ItemRef(ItemOID="ODM.IT.DM.BRTHYR", Mandatory="Yes")
     igr5 = ODM.ItemRef(ItemOID="ODM.IT.DM.SEX", Mandatory="Yes")
     igd2 = ODM.ItemGroupDef(OID="ODM.IG.DM",
                             Name="Demographics",
                             Repeating="No")
     igd2.ItemRef = [igr4, igr5]
     igr6 = ODM.ItemRef(ItemOID="ODM.IT.Common.SubjectID", Mandatory="Yes")
     igr7 = ODM.ItemRef(ItemOID="ODM.IT.Common.Visit", Mandatory="Yes")
     igd3 = ODM.ItemGroupDef(OID="ODM.IG.Common",
                             Name="Common",
                             Repeating="No")
     igd3.ItemRef = [igr6, igr7]
     igr8 = ODM.ItemRef(ItemOID="ODM.IT.AE.AETERM", Mandatory="Yes")
     igr9 = ODM.ItemRef(ItemOID="ODM.IT.AE.AESEV", Mandatory="Yes")
     igd4 = ODM.ItemGroupDef(OID="ODM.IG.AE",
                             Name="Adverse Events",
                             Repeating="Yes")
     igd4.ItemRef = [igr8, igr9]
     return [igd1, igd2, igd3, igd4]
Exemplo n.º 2
0
 def test_ItemGroupDef(self):
     attrs = {
         "OID": "IG.VS",
         "Name": "VS",
         "Repeating": "Yes",
         "Domain": "VS",
         "Name": "VS",
         "SASDatasetName": "VS",
         "IsReferenceData": "No",
         "Purpose": "Tabulation"
     }
     igd = ODM.ItemGroupDef(**attrs)
     tt = ODM.TranslatedText(_content="this is the first test description",
                             lang="en")
     igd.Description = ODM.Description()
     igd.Description.TranslatedText = [tt]
     ir1 = ODM.ItemRef(ItemOID="IT.STUDYID",
                       Mandatory="Yes",
                       OrderNumber="1")
     ir2 = ODM.ItemRef(ItemOID="IT.VS.VSTEST",
                       Mandatory="No",
                       OrderNumber="2")
     igd.ItemRef = [ir1, ir2]
     igd_dict = igd.to_dict()
     print(igd_dict)
     is_valid = self.validator.verify_conformance(igd_dict, "ItemGroupDef")
     self.assertTrue(is_valid)
Exemplo n.º 3
0
 def add_IGD(self):
     itr1 = ODM.ItemRef(ItemOID="ODM.IT.VS.VSDAT", Mandatory="Yes")
     itr2 = ODM.ItemRef(ItemOID="ODM.IT.VS.BP.DIABP.VSORRES",
                        Mandatory="Yes")
     itr3 = ODM.ItemRef(ItemOID="ODM.IT.VS.BP.SYSBP.VSORRES",
                        Mandatory="Yes")
     igd1 = ODM.ItemGroupDef(OID="ODM.IG.VS",
                             Name="Vital Sign Measurement",
                             Repeating="Yes")
     igd1.ItemRef = [itr1, itr2, itr3]
     igr4 = ODM.ItemRef(ItemOID="ODM.IT.DM.BRTHYR", Mandatory="Yes")
     igr5 = ODM.ItemRef(ItemOID="ODM.IT.DM.SEX", Mandatory="Yes")
     igd2 = ODM.ItemGroupDef(OID="ODM.IG.DM",
                             Name="Demographics",
                             Repeating="No")
     igd2.ItemRef = [igr4, igr5]
     return [igd1, igd2]
Exemplo n.º 4
0
    def setUp(self) -> None:
        current_datetime = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
        root = ODM.ODM(FileOID="ODM.DEMO.001", Granularity="Metadata", AsOfDateTime=current_datetime,
                       CreationDateTime=current_datetime, ODMVersion="1.3.2", FileType="Snapshot",
                       Originator="swhume", SourceSystem="odmlib", SourceSystemVersion="0.1")

        # create Study and add to ODM
        root.Study.append(ODM.Study(OID="ODM.GET.STARTED"))

        # create the global variables
        root.Study[0].GlobalVariables = ODM.GlobalVariables()
        root.Study[0].GlobalVariables.StudyName = ODM.StudyName(_content="Get Started with ODM XML")
        root.Study[0].GlobalVariables.StudyDescription = ODM.StudyDescription(
            _content="Demo to get started with odmlib")
        root.Study[0].GlobalVariables.ProtocolName = ODM.ProtocolName(_content="ODM XML Get Started")

        # create the MetaDataVersion
        root.Study[0].MetaDataVersion.append(ODM.MetaDataVersion(OID="MDV.DEMO-ODM-01", Name="Get Started MDV",
                                                                 Description="Get Started Demo"))
        # create Protocol
        p = ODM.Protocol()
        p.Description = ODM.Description()
        p.Description.TranslatedText.append(ODM.TranslatedText(_content="Get Started Protocol", lang="en"))
        p.StudyEventRef.append(ODM.StudyEventRef(StudyEventOID="BASELINE", OrderNumber=1, Mandatory="Yes"))
        root.Study[0].MetaDataVersion[0].Protocol = p

        # create a StudyEventDef
        sed = ODM.StudyEventDef(OID="BASELINE", Name="Baseline Visit", Repeating="No", Type="Scheduled")
        sed.FormRef.append(ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=1))
        root.Study[0].MetaDataVersion[0].StudyEventDef.append(sed)

        # create a FormDef
        fd = ODM.FormDef(OID="ODM.F.DM", Name="Demographics", Repeating="No")
        fd.ItemGroupRef.append(ODM.ItemGroupRef(ItemGroupOID="ODM.IG.DM", Mandatory="Yes", OrderNumber=2))
        root.Study[0].MetaDataVersion[0].FormDef.append(fd)

        # create an ItemGroupDef
        igd = ODM.ItemGroupDef(OID="ODM.IG.DM", Name="Demographics", Repeating="No")
        igd.ItemRef.append(ODM.ItemRef(ItemOID="ODM.IT.DM.BRTHYR", Mandatory="Yes"))
        root.Study[0].MetaDataVersion[0].ItemGroupDef.append(igd)

        # create an ItemDef
        itd = ODM.ItemDef(OID="ODM.IT.DM.BRTHYR", Name="Birth Year", DataType="integer")
        itd.Description = ODM.Description()
        itd.Description.TranslatedText.append(ODM.TranslatedText(_content="Year of the subject's birth", lang="en"))
        itd.Question = ODM.Question()
        itd.Question.TranslatedText.append(ODM.TranslatedText(_content="Birth Year", lang="en"))
        itd.Alias.append(ODM.Alias(Context="CDASH", Name="BRTHYR"))
        itd.Alias.append(ODM.Alias(Context="SDTM", Name="BRTHDTC"))
        root.Study[0].MetaDataVersion[0].ItemDef.append(itd)

        # save the new ODM document to an ODM XML file
        root.write_xml(ODM_XML_FILE)

        # save the same ODM document to a JSON file
        root.write_json(ODM_JSON_FILE)
Exemplo n.º 5
0
 def test_itemgroupdef_iterator(self):
     """ test the ability to reference a specific or slice of ItemRefs """
     attrs = self.set_itemgroupdef_attributes()
     igd = ODM.ItemGroupDef(**attrs)
     tt = ODM.TranslatedText(_content="Vital Signs", lang="en")
     igd.Description = ODM.Description()
     igd.Description.TranslatedText = [tt]
     item_refs = self.set_itemrefs()
     igd.ItemRef = item_refs
     parser = ODM_PARSER.ODMParser(self.odm_test_file)
     parser.parse()
     parser.MetaDataVersion()
     irs = [ir.ItemOID for ir in igd]
     self.assertEqual(len(irs), 13)
     self.assertEqual(len(igd), 13)
Exemplo n.º 6
0
 def test_itemgroupdef_slice(self):
     """ test the ability to reference a specific or slice of ItemRefs """
     attrs = self.set_itemgroupdef_attributes()
     igd = ODM.ItemGroupDef(**attrs)
     tt = ODM.TranslatedText(_content="Vital Signs", lang="en")
     igd.Description = ODM.Description()
     igd.Description.TranslatedText = [tt]
     item_refs = self.set_itemrefs()
     igd.ItemRef = item_refs
     parser = ODM_PARSER.ODMParser(self.odm_test_file)
     parser.parse()
     parser.MetaDataVersion()
     self.assertEqual(len(igd), 13)
     self.assertEqual(igd.ItemRef[0].ItemOID, "IT.STUDYID")
     slice_itr = igd.ItemRef[1:5]
     self.assertEqual(slice_itr[1].ItemOID, "IT.VS.USUBJID")
Exemplo n.º 7
0
 def test_to_json(self):
     attrs = self.set_itemgroupdef_attributes()
     igd = ODM.ItemGroupDef(**attrs)
     tt = ODM.TranslatedText(_content="this is the first test description",
                             lang="en")
     igd.Description = ODM.Description()
     igd.Description.TranslatedText = [tt]
     ir1 = ODM.ItemRef(ItemOID="IT.STUDYID", Mandatory="Yes", OrderNumber=1)
     ir2 = ODM.ItemRef(ItemOID="IT.VS.VSTEST",
                       Mandatory="No",
                       OrderNumber=2)
     igd.ItemRef = [ir1, ir2]
     igd_json = igd.to_json()
     igd_dict = json.loads(igd_json)
     print(igd_dict)
     self.assertEqual(igd_dict["OID"], "IG.VS")
     self.assertEqual(igd_dict["ItemRef"][1]["ItemOID"], "IT.VS.VSTEST")
Exemplo n.º 8
0
 def test_to_xml(self):
     attrs = self.set_itemgroupdef_attributes()
     igd = ODM.ItemGroupDef(**attrs)
     tt = ODM.TranslatedText(_content="this is the first test description",
                             lang="en")
     desc = ODM.Description()
     desc.TranslatedText = [tt]
     igd.Description = desc
     ir1 = ODM.ItemRef(ItemOID="IT.STUDYID", Mandatory="Yes", OrderNumber=1)
     ir2 = ODM.ItemRef(ItemOID="IT.VS.VSTEST",
                       Mandatory="No",
                       OrderNumber=2)
     igd.ItemRef = [ir1, ir2]
     igd_xml = igd.to_xml()
     self.assertEqual(igd_xml.attrib["OID"], "IG.VS")
     self.assertListEqual(["Description", "ItemRef", "ItemRef"],
                          [e.tag for e in igd_xml.getchildren()])
Exemplo n.º 9
0
 def test_itemgroupdef_round_trip(self):
     """ system test to create and serialize an ItemGroupDef object """
     attrs = self.set_itemgroupdef_attributes()
     igd = ODM.ItemGroupDef(**attrs)
     tt = ODM.TranslatedText(_content="Vital Signs", lang="en")
     igd.Description = ODM.Description()
     igd.Description.TranslatedText = [tt]
     item_refs = self.set_itemrefs()
     igd.ItemRef = item_refs
     parser = ODM_PARSER.ODMParser(self.odm_test_file)
     parser.parse()
     mdv = parser.MetaDataVersion()
     igd_list = parser.ItemGroupDef(parent=mdv[0])
     igd_dict = igd_list[0]
     self.assertEqual(igd_dict["OID"], "IG.VS")
     ir_list = parser.ItemRef(parent=igd_dict["elem"])
     # tests the __len__ in ItemGroupDef as well as the add_item_ref
     self.assertEqual(len(ir_list), len(igd))
Exemplo n.º 10
0
 def test_item_group_valid_kwargs_only(self):
     igd = ODM.ItemGroupDef(OID="IG.VS", Name="VS", Repeating="Yes")
     self.assertEqual(igd.OID, "IG.VS")
Exemplo n.º 11
0
 def setUp(self) -> None:
     attrs = self.set_itemgroupdef_attributes()
     self.igd = ODM.ItemGroupDef(**attrs)
     self.odm_test_file = os.path.join(
         os.path.dirname(os.path.realpath(__file__)), 'data',
         'test_igd_001.xml')
Exemplo n.º 12
0
 def test_get_missing_attribute(self):
     igd = ODM.ItemGroupDef(OID="IG.VS",
                            Name="Vital Signs",
                            Repeating="Yes")
     self.assertEqual(igd.OID, "IG.VS")
     self.assertIsNone(igd.Comment)
Exemplo n.º 13
0
    def test_xml_to_string(self):
        current_datetime = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
        root = ODM.ODM(FileOID="ODM.DEMO.001", Granularity="Metadata", AsOfDateTime=current_datetime,
                       CreationDateTime=current_datetime, ODMVersion="1.3.2", FileType="Snapshot",
                       Originator="swhume", SourceSystem="odmlib", SourceSystemVersion="0.1")

        # create Study and add to ODM
        root.Study.append(ODM.Study(OID="ODM.GET.STARTED"))

        # create the global variables
        root.Study[0].GlobalVariables = ODM.GlobalVariables()
        root.Study[0].GlobalVariables.StudyName = ODM.StudyName(_content="Get Started with ODM XML")
        root.Study[0].GlobalVariables.StudyDescription = ODM.StudyDescription(
            _content="Demo to get started with odmlib")
        root.Study[0].GlobalVariables.ProtocolName = ODM.ProtocolName(_content="ODM XML Get Started")

        # create the MetaDataVersion
        root.Study[0].MetaDataVersion.append(ODM.MetaDataVersion(OID="MDV.DEMO-ODM-01", Name="Get Started MDV",
                                                                 Description="Get Started Demo"))
        # create Protocol
        p = ODM.Protocol()
        p.Description = ODM.Description()
        p.Description.TranslatedText.append(ODM.TranslatedText(_content="Get Started Protocol", lang="en"))
        p.StudyEventRef.append(ODM.StudyEventRef(StudyEventOID="BASELINE", OrderNumber=1, Mandatory="Yes"))
        root.Study[0].MetaDataVersion[0].Protocol = p

        # create a StudyEventDef
        sed = ODM.StudyEventDef(OID="BASELINE", Name="Baseline Visit", Repeating="No", Type="Scheduled")
        sed.FormRef.append(ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=1))
        root.Study[0].MetaDataVersion[0].StudyEventDef.append(sed)

        # create a FormDef
        fd = ODM.FormDef(OID="ODM.F.DM", Name="Demographics", Repeating="No")
        fd.ItemGroupRef.append(ODM.ItemGroupRef(ItemGroupOID="ODM.IG.DM", Mandatory="Yes", OrderNumber=2))
        root.Study[0].MetaDataVersion[0].FormDef.append(fd)

        # create an ItemGroupDef
        igd = ODM.ItemGroupDef(OID="ODM.IG.DM", Name="Demographics", Repeating="No")
        igd.ItemRef.append(ODM.ItemRef(ItemOID="ODM.IT.DM.BRTHYR", Mandatory="Yes"))
        root.Study[0].MetaDataVersion[0].ItemGroupDef.append(igd)

        # create an ItemDef
        itd = ODM.ItemDef(OID="ODM.IT.DM.BRTHYR", Name="Birth Year", DataType="integer")
        itd.Description = ODM.Description()
        itd.Description.TranslatedText.append(ODM.TranslatedText(_content="Year of the subject's birth", lang="en"))
        itd.Question = ODM.Question()
        itd.Question.TranslatedText.append(ODM.TranslatedText(_content="Birth Year", lang="en"))
        itd.Alias.append(ODM.Alias(Context="CDASH", Name="BRTHYR"))
        itd.Alias.append(ODM.Alias(Context="SDTM", Name="BRTHDTC"))
        root.Study[0].MetaDataVersion[0].ItemDef.append(itd)

        odm_xml_string = root.to_xml_string()
        # add namespaces
        nsr = NS.NamespaceRegistry()
        odm_str = nsr.set_odm_namespace_attributes_string(odm_xml_string)
        with open("./data/simple_create_from_string.xml", "w") as xml_file:
            xml_file.write(odm_str)

        loader = LD.ODMLoader(OL.XMLODMLoader(model_package="odm_1_3_2", ns_uri="http://www.cdisc.org/ns/odm/v1.3"))
        loader.open_odm_document("./data/simple_create_from_string.xml")
        mdv = loader.MetaDataVersion()
        item_list = mdv.ItemDef
        item = item_list[0]
        self.assertEqual(item.OID, "ODM.IT.DM.BRTHYR")