Beispiel #1
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)
 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]
Beispiel #3
0
 def test_add_item_ref(self):
     self.igd.ItemRef.append(
         ODM.ItemRef(ItemOID="IT.STUDYID", Mandatory="Yes", OrderNumber=1))
     self.igd.ItemRef.append(
         ODM.ItemRef(ItemOID="IT.VS.VSTEST", Mandatory="No", OrderNumber=2))
     self.igd.ItemRef.append(
         ODM.ItemRef(ItemOID="IT.VS.VSORRES",
                     Mandatory="Yes",
                     OrderNumber=3,
                     MethodOID="MT.METHODFEX"))
     self.assertEqual(self.igd.ItemRef[0].ItemOID, "IT.STUDYID")
     self.assertEqual(self.igd.ItemRef[2].MethodOID, "MT.METHODFEX")
Beispiel #4
0
 def test_item_ref_exists(self):
     self.igd.ItemRef = [
         ODM.ItemRef(ItemOID="IT.VS.VSTESTCD",
                     Mandatory="Yes",
                     OrderNumber=4)
     ]
     self.assertEqual(self.igd.ItemRef[0].ItemOID, "IT.VS.VSTESTCD")
Beispiel #5
0
 def test_add_item_ref_invalid_kwarg(self):
     with self.assertRaises(TypeError):
         self.igd.ItemRef = [
             ODM.ItemRef(ItemOID="IT.STUDYID",
                         Mandatory="Yes",
                         InValid="Yes")
         ]
Beispiel #6
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")
Beispiel #7
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()])
Beispiel #8
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]
Beispiel #9
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)
Beispiel #10
0
 def test_add_item_ref_missing_kwarg(self):
     with self.assertRaises(ValueError):
         self.igd.ItemRef = [ODM.ItemRef(Mandatory="Yes", OrderNumber=1)]
Beispiel #11
0
 def set_itemrefs(self):
     """
     set some ItemRef element attributes using test data
     :return: return a list of ItemRef named tuples
     """
     itemrefs = []
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.STUDYID",
                     Mandatory="Yes",
                     OrderNumber=1,
                     KeySequence=1))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.DOMAIN", Mandatory="Yes",
                     OrderNumber=2))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.USUBJID",
                     Mandatory="Yes",
                     OrderNumber=3,
                     KeySequence=2,
                     MethodOID="MT.USUBJID"))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSSEQ",
                     Mandatory="Yes",
                     OrderNumber=4,
                     MethodOID="MT.SEQ"))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSTESTCD",
                     Mandatory="Yes",
                     OrderNumber=5,
                     KeySequence=3))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSTEST", Mandatory="Yes",
                     OrderNumber=6))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSPOS", Mandatory="No", OrderNumber=7))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSORRES", Mandatory="No",
                     OrderNumber=8))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSORRESU",
                     Mandatory="No",
                     OrderNumber=9))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSSTRESC",
                     Mandatory="No",
                     OrderNumber=10,
                     MethodOID="MT.VSSTRESC"))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSSTRESN",
                     Mandatory="No",
                     OrderNumber=11,
                     MethodOID="MT.VSSTRESN"))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSSTRESU",
                     Mandatory="No",
                     OrderNumber=12))
     itemrefs.append(
         ODM.ItemRef(ItemOID="IT.VS.VSBLFL",
                     Mandatory="No",
                     OrderNumber=13,
                     MethodOID="MT.VSBLFL"))
     return itemrefs
Beispiel #12
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")