Beispiel #1
0
 def test_ItemDef(self):
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": "1",
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field"
     }
     item = ODM.ItemDef(**attrs)
     item.Description.TranslatedText = [
         ODM.TranslatedText(_content="this is the first test description",
                            lang="en")
     ]
     item.Question.TranslatedText = [
         ODM.TranslatedText(_content="Any AEs?", lang="en")
     ]
     item.CodeListRef = ODM.CodeListRef(
         CodeListOID="CL.NY_SUB_Y_N_2011-10-24")
     item_dict = item.to_dict()
     print(item_dict)
     is_valid = self.validator.verify_conformance(item_dict, "ItemDef")
     self.assertTrue(is_valid)
Beispiel #2
0
 def test_to_xml(self):
     attrs = self.set_item_attributes()
     item = ODM.ItemDef(**attrs)
     item.Description.TranslatedText = [
         ODM.TranslatedText(_content="this is the first test description",
                            lang="en")
     ]
     item.Question.TranslatedText = [
         ODM.TranslatedText(_content="Any AEs?", lang="en")
     ]
     item.ExternalQuestion = ODM.ExternalQuestion(Dictionary="SF36",
                                                  Version="12",
                                                  Code="Walks 1-mile")
     item.CodeListRef = ODM.CodeListRef(
         CodeListOID="CL.NY_SUB_Y_N_2011-10-24")
     item.RangeCheck = [ODM.RangeCheck(Comparator="EQ", SoftHard="Soft")]
     item.RangeCheck[0].CheckValue = [ODM.CheckValue(_content="DIABP")]
     item.RangeCheck[0].FormalExpression = [
         ODM.FormalExpression(Context="Python 3.7",
                              _content="print('hello world')")
     ]
     item.RangeCheck[0].MeasurementUnitRef = ODM.MeasurementUnitRef(
         MeasurementUnitOID="ODM.MU.UNITS")
     item.RangeCheck[0].ErrorMessage.TranslatedText = [
         ODM.TranslatedText(_content="invalid test code", lang="en")
     ]
     item_xml = item.to_xml()
     self.assertEqual(item_xml.attrib["OID"], "ODM.IT.AE.AEYN")
     cv = item_xml.find("*/CheckValue")
     self.assertEqual(cv.text, "DIABP")
     dt = item_xml.findall("Description/TranslatedText")
     self.assertEqual(len(dt), 1)
Beispiel #3
0
 def test_to_json(self):
     attrs = self.set_item_attributes()
     item = ODM.ItemDef(**attrs)
     item.Description.TranslatedText.append(
         ODM.TranslatedText(_content="this is the first test description",
                            lang="en"))
     item.Question.TranslatedText = [
         ODM.TranslatedText(_content="Any AEs?", lang="en")
     ]
     item.CodeListRef = ODM.CodeListRef(
         CodeListOID="CL.NY_SUB_Y_N_2011-10-24")
     item_json = item.to_json()
     item_dict = json.loads(item_json)
     self.assertEqual(item_dict["OID"], "ODM.IT.AE.AEYN")
Beispiel #4
0
 def test_to_dict(self):
     attrs = self.set_item_attributes()
     item = ODM.ItemDef(**attrs)
     item.Description.TranslatedText = [
         ODM.TranslatedText(_content="this is the first test description",
                            lang="en")
     ]
     item.Question.TranslatedText = [
         ODM.TranslatedText(_content="Any AEs?", lang="en")
     ]
     item.CodeListRef = ODM.CodeListRef(
         CodeListOID="CL.NY_SUB_Y_N_2011-10-24")
     item_dict = item.to_dict()
     expected_dict = {
         'OID': 'ODM.IT.AE.AEYN',
         'Name': 'Any AEs?',
         'DataType': 'text',
         'Length': 1,
         'SASFieldName': 'AEYN',
         'SDSVarName': 'AEYN',
         'Origin': 'CRF',
         'Comment': 'Data management field',
         'Description': {
             'TranslatedText': [{
                 '_content': 'this is the first test description',
                 'lang': 'en'
             }]
         },
         'Question': {
             'TranslatedText': [{
                 '_content': 'Any AEs?',
                 'lang': 'en'
             }]
         },
         'CodeListRef': {
             'CodeListOID': 'CL.NY_SUB_Y_N_2011-10-24'
         }
     }
     self.assertDictEqual(item_dict, expected_dict)
Beispiel #5
0
 def test_float_type(self):
     # rank is a float - test as a float
     attrs = {"CodedValue": "HGB", "Rank": 1.1}
     cli = ODM.CodeListItem(**attrs)
     self.assertEqual(cli.Rank, 1.1)
     # test float as string
     attrs = {"CodedValue": "HGB", "Rank": "1.1"}
     cli = ODM.CodeListItem(**attrs)
     self.assertEqual(cli.Rank, 1.1)
     # test integer as float
     attrs = {"CodedValue": "HGB", "Rank": 1}
     cli = ODM.CodeListItem(**attrs)
     self.assertEqual(cli.Rank, 1.0)
     # test non-float as string
     attrs = {"CodedValue": "HGB", "Rank": "a"}
     with self.assertRaises(TypeError):
         cli = ODM.CodeListItem(**attrs)
     # test object as float
     clr = ODM.CodeListRef(CodeListOID="CL.TEST")
     attrs = {"CodedValue": "HGB", "Rank": clr}
     with self.assertRaises(TypeError):
         cli = ODM.CodeListItem(**attrs)
Beispiel #6
0
 def test_codelist_ref(self):
     self.item.CodeListRef = ODM.CodeListRef(
         CodeListOID="CL.NY_SUB_Y_N_2011-10-24")
     self.assertEqual(self.item.CodeListRef.CodeListOID,
                      "CL.NY_SUB_Y_N_2011-10-24")
Beispiel #7
0
 def test_add_undefined_content(self):
     # use conformance rules to check for unknown objects being added after creation
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": 1,
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field",
         "SignificantDigits": 1
     }
     item = ODM.ItemDef(**attrs)
     clr = ODM.CodeListRef(CodeListOID="CL.TEST")
     with self.assertRaises(TypeError):
         item.NewCodeList = clr
     # cannot add unknown attributes or elements during creation, but can afterwards; catch with conformance checks
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": 1,
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field",
         "SignificantDigits": 1
     }
     item = ODM.ItemDef(**attrs)
     with self.assertRaises(TypeError):
         item.InSignificantDigits = 1
     # can add all objects during creation and they are validated
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": 1,
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field",
         "CodeListRef": clr
     }
     item = ODM.ItemDef(**attrs)
     self.assertEqual(item.CodeListRef, clr)
     attrs["CodeListReference"] = clr
     with self.assertRaises(TypeError):
         # test shows that ItemDef fails the schema check because it has an unknown CodeListReference object
         item = ODM.ItemDef(**attrs)
     self.assertEqual(item.CodeListRef, clr)
     # test adding the wrong type of object to a list
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": 1,
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field",
         "Alias": [clr]
     }
     with self.assertRaises(TypeError):
         item = ODM.ItemDef(**attrs)
     # test adding the wrong type of object to a list
     alias = ODM.Alias(Context="CDASH", Name="AEYN")
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": 1,
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field",
         "Alias": alias
     }
     with self.assertRaises(TypeError):
         item = ODM.ItemDef(**attrs)
     # assign wrong type of object to an element
     attrs = {
         "OID": "ODM.IT.AE.AEYN",
         "Name": "Any AEs?",
         "DataType": "text",
         "Length": 1,
         "SASFieldName": "AEYN",
         "SDSVarName": "AEYN",
         "Origin": "CRF",
         "Comment": "Data management field",
         "CodeListRef": alias
     }
     with self.assertRaises(TypeError):
         item = ODM.ItemDef(**attrs)