def test_sasformat_type(self): attrs = { "OID": "ODM.CL.LBTESTCD", "Name": "Laboratory Test Code", "DataType": "text", "SASFormatName": "$AETERM" } cl = ODM.CodeList(**attrs) self.assertEqual(cl.SASFormatName, "$AETERM") # start with an underscore attrs["SASFormatName"] = "_AETERM" cl = ODM.CodeList(**attrs) self.assertEqual(cl.SASFormatName, "_AETERM") # start with a number attrs["SASFormatName"] = "9AETERM" with self.assertRaises(ValueError): cl = ODM.CodeList(**attrs) # end with a symbol attrs["SASFormatName"] = "AETERM%" with self.assertRaises(ValueError): cl = ODM.CodeList(**attrs) # test with none - does not throw an error when value is None attrs["SASFormatName"] = None cl = ODM.CodeList(**attrs) self.assertIsNone(cl.SASFormatName)
def test_to_dict(self): attrs = self._set_attributes() cl = ODM.CodeList(**attrs) eni = ODM.EnumeratedItem(CodedValue="HGB", OrderNumber=1) eni.Alias = [ODM.Alias(Context="nci:ExtCodeID", Name="C64848")] cl.EnumeratedItem.append(eni) eni.Alias.append(ODM.Alias(Context="nci:ExtCodeID", Name="C65047")) cl_dict = cl.to_dict() self.assertDictEqual(cl_dict, self.expected_json_dict())
def test_to_xml(self): attrs = self._set_attributes() cl = ODM.CodeList(**attrs) eni = ODM.EnumeratedItem(CodedValue="HGB", OrderNumber=1) eni.Alias = [ODM.Alias(Context="nci:ExtCodeID", Name="C64848")] cl.EnumeratedItem.append(eni) eni.Alias.append(ODM.Alias(Context="nci:ExtCodeID", Name="C65047")) cl_xml = cl.to_xml() self.assertEqual(cl_xml.attrib["OID"], "ODM.CL.LBTESTCD") ei = cl_xml.find("EnumeratedItem") self.assertEqual(ei.attrib["CodedValue"], "HGB")
def test_to_xml_external_code_list(self): attrs = self._set_attributes() cl = ODM.CodeList(**attrs) excl = ODM.ExternalCodeList(Dictionary="MedDRA", Version="23.0", href="https://www.meddra.org/") cl.ExternalCodeList = excl cl_xml = cl.to_xml() self.assertEqual(cl_xml.attrib["OID"], "ODM.CL.LBTESTCD") ecl = cl_xml.find("ExternalCodeList") self.assertEqual(ecl.attrib["Dictionary"], "MedDRA")
def test_ExternalCodeList(self): attrs = { "OID": "ODM.CL.LBTESTCD", "Name": "Laboratory Test Code", "DataType": "text" } cl = ODM.CodeList(**attrs) excl = ODM.ExternalCodeList(Dictionary="MedDRA", Version="23.0", href="https://www.meddra.org/") cl.ExternalCodeList = excl cl_dict = cl.to_dict() is_valid = self.validator.verify_conformance(cl_dict, "CodeList") self.assertTrue(is_valid)
def test_CodeList(self): attrs = { "OID": "ODM.CL.LBTESTCD", "Name": "Laboratory Test Code", "DataType": "text" } cl = ODM.CodeList(**attrs) eni = ODM.EnumeratedItem(CodedValue="HGB", OrderNumber=1) eni.Alias = [ODM.Alias(Context="nci:ExtCodeID", Name="C64848")] cl.EnumeratedItem.append(eni) eni.Alias.append(ODM.Alias(Context="nci:ExtCodeID", Name="C65047")) cl_dict = cl.to_dict() print(cl_dict) is_valid = self.validator.verify_conformance(cl_dict, "CodeList") self.assertTrue(is_valid)
def add_CL(self): tt1 = ODM.TranslatedText(_content="No", lang="en") dc1 = ODM.Decode() dc1.TranslatedText = [tt1] cli1 = ODM.CodeListItem(CodedValue="N") cli1.Decode = dc1 tt2 = ODM.TranslatedText(_content="Yes", lang="en") dc2 = ODM.Decode() dc2.TranslatedText = [tt2] cli2 = ODM.CodeListItem(CodedValue="Y") cli2.Decode = dc2 cl = ODM.CodeList(OID="ODM.CL.NY_SUB_Y_N", Name="No Yes Response", DataType="text") cl.CodeListItem = [cli1, cli2] return [cl]
def test_to_xml_code_list_item(self): attrs = self._set_attributes() cl = ODM.CodeList(**attrs) cli1 = ODM.CodeListItem(CodedValue="HGB", OrderNumber=1) cli1.Alias = [ODM.Alias(Context="nci:ExtCodeID", Name="C64848")] cl.CodeListItem.append(cli1) cli2 = ODM.CodeListItem(CodedValue="VITB12", OrderNumber=2) cli2.Alias.append(ODM.Alias(Context="nci:ExtCodeID", Name="C64817")) cl.CodeListItem.append(cli2) cli3 = ODM.CodeListItem(CodedValue="GLUC", OrderNumber=3) cli3.Alias.append(ODM.Alias(Context="nci:ExtCodeID", Name="C41376")) cl.CodeListItem.append(cli3) cl_xml = cl.to_xml() self.assertEqual(cl_xml.attrib["OID"], "ODM.CL.LBTESTCD") ei = cl_xml.findall("CodeListItem") self.assertEqual(ei[0].attrib["CodedValue"], "HGB")
def setUp(self) -> None: attrs = self._set_attributes() self.cl = ODM.CodeList(**attrs)