Esempio n. 1
0
 def test_add_form_ref(self):
     fr1 = ODM.FormRef(FormOID="ODM.F.VS", Mandatory="Yes", OrderNumber=1)
     fr2 = ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=2)
     fr3 = ODM.FormRef(FormOID="ODM.F.MH", Mandatory="Yes", OrderNumber=3)
     self.sed.FormRef = [fr1, fr2, fr3]
     self.assertEqual(self.sed.FormRef[0].FormOID, "ODM.F.VS")
     self.assertEqual(self.sed.FormRef[2].OrderNumber, 3)
Esempio n. 2
0
 def add_SED(self):
     fr1 = ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=1)
     fr2 = ODM.FormRef(FormOID="ODM.F.VS", Mandatory="Yes", OrderNumber=2)
     fr3 = ODM.FormRef(FormOID="ODM.F.AE", Mandatory="Yes", OrderNumber=3)
     ser1 = ODM.StudyEventDef(OID="BASELINE",
                              Name="Baseline Visit",
                              Repeating="No",
                              Type="Scheduled")
     ser1.FormRef = [fr1, fr2, fr3]
     ser2 = ODM.StudyEventDef(OID="FOLLOW-UP",
                              Name="Follow-up Visit",
                              Repeating="Yes",
                              Type="Scheduled")
     ser2.FormRef = [fr1, fr2, fr3]
     return [ser1, ser2]
Esempio n. 3
0
 def test_to_dict(self):
     attrs = self.set_attributes()
     sed = ODM.StudyEventDef(**attrs)
     tt1 = ODM.TranslatedText(_content="this is the first test description",
                              lang="en")
     desc = ODM.Description()
     desc.TranslatedText = [tt1]
     sed.Description = desc
     fr1 = ODM.FormRef(FormOID="ODM.F.VS", Mandatory="Yes", OrderNumber=1)
     fr2 = ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=2)
     fr3 = ODM.FormRef(FormOID="ODM.F.MH", Mandatory="Yes", OrderNumber=3)
     sed.FormRef = [fr1, fr2, fr3]
     a1 = ODM.Alias(Context="SDTMIG", Name="VS")
     sed.Alias = [a1]
     sed_dict = sed.to_dict()
     self.assertEqual(sed_dict["OID"], "ODM.SE.BASELINE")
     self.assertDictEqual(sed_dict, self.expected_dict())
Esempio n. 4
0
 def test_studyeventdef_slice(self):
     """ test the ability to reference a specific or slice of FormRefs """
     attrs = self.set_attributes()
     sed = ODM.StudyEventDef(**attrs)
     tt1 = ODM.TranslatedText(_content="this is the first test description",
                              lang="en")
     desc = ODM.Description()
     desc.TranslatedText = [tt1]
     sed.Description = desc
     fr1 = ODM.FormRef(FormOID="ODM.F.VS", Mandatory="Yes", OrderNumber=1)
     fr2 = ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=2)
     fr3 = ODM.FormRef(FormOID="ODM.F.MH", Mandatory="Yes", OrderNumber=3)
     sed.FormRef = [fr1, fr2, fr3]
     self.assertEqual(len(sed.FormRef), 3)
     first_fr = sed[0]
     self.assertEqual(first_fr.FormOID, "ODM.F.VS")
     slice_fr = sed[1:3]
     self.assertEqual(slice_fr[1].FormOID, "ODM.F.MH")
Esempio n. 5
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)
Esempio n. 6
0
 def test_to_xml(self):
     attrs = self.set_attributes()
     sed = ODM.StudyEventDef(**attrs)
     tt1 = ODM.TranslatedText(_content="this is the first test description",
                              lang="en")
     desc = ODM.Description()
     desc.TranslatedText = [tt1]
     sed.Description = desc
     fr1 = ODM.FormRef(FormOID="ODM.F.VS", Mandatory="Yes", OrderNumber=1)
     fr2 = ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber=2)
     fr3 = ODM.FormRef(FormOID="ODM.F.MH", Mandatory="Yes", OrderNumber=3)
     sed.FormRef = [fr1, fr2, fr3]
     a1 = ODM.Alias(Context="SDTMIG", Name="VS")
     sed.Alias = [a1]
     sed_xml = sed.to_xml()
     self.assertEqual(sed_xml.attrib["OID"], "ODM.SE.BASELINE")
     fr = sed_xml.findall("FormRef")
     self.assertEqual(len(fr), 3)
     self.assertEqual(fr[0].attrib, {
         "FormOID": "ODM.F.VS",
         "Mandatory": "Yes",
         "OrderNumber": "1"
     })
Esempio n. 7
0
 def test_StudEventDef(self):
     attrs = {
         "OID": "ODM.SE.BASELINE",
         "Name": "Baseline Visit",
         "Repeating": "No",
         "Type": "Scheduled",
         "Category": "Pre-treatment"
     }
     sed = ODM.StudyEventDef(**attrs)
     tt1 = ODM.TranslatedText(_content="this is the first test description",
                              lang="en")
     sed.Description = ODM.Description()
     sed.Description.TranslatedText = [tt1]
     fr1 = ODM.FormRef(FormOID="ODM.F.VS", Mandatory="Yes", OrderNumber="1")
     fr2 = ODM.FormRef(FormOID="ODM.F.DM", Mandatory="Yes", OrderNumber="2")
     fr3 = ODM.FormRef(FormOID="ODM.F.MH", Mandatory="Yes", OrderNumber="3")
     sed.FormRef = [fr1, fr2, fr3]
     a1 = ODM.Alias(Context="SDTMIG", Name="VS")
     a2 = ODM.Alias(Context="CDASHIG", Name="VS")
     sed.Alias = [a1, a2]
     sed_dict = sed.to_dict()
     print(sed_dict)
     is_valid = self.validator.verify_conformance(sed_dict, "StudyEventDef")
     self.assertTrue(is_valid)
Esempio n. 8
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")