Package: ukrdc-xsdata
UKRDC-XSDataXSData models for the UKRDC.Installationpip install ukrdc-xsdataBasic usageCreating UKRDC XMLimportdatetimefromxsdata.models.datatypeimportXmlDatefromukrdc_xsdata.ukrdcimportPatientRecord,Patient,typesrecord=PatientRecord(sending_facility="RFBAK",sending_extract="PV",patient=Patient(birth_time=XmlDate.from_datetime(datetime.datetime(year=1950,month=10,day=1)),gender=types.gender.Gender.VALUE_9,names=Patient.Names(name=[types.Name(use="L",family="A TEST PATIENT",given="TESTING")]),addresses=Patient.Addresses(address=[types.Address(street="1 TEST STREET",town="TEST TOWN",county="TEST COUNTY",postcode="DK1 3GG",country=types.Address.Country(coding_standard="ISO3166-1",code="GB",description="United Kingdom"))]),patient_numbers=types.PatientNumbers(patient_number=[types.PatientNumber(number="1111111111",organization=types.PatientNumberOrganization.CHI,number_type=types.PatientNumberNumberType.NI,),types.PatientNumber(number="U0000000",organization=types.PatientNumberOrganization.LOCALHOSP,number_type=types.PatientNumberNumberType.MRN,)])))fromxsdata.formats.dataclass.serializers.xmlimportXmlSerializerprint(XmlSerializer().render(record))will render<?xml version="1.0" encoding="UTF-8"?><ns0:PatientRecordxmlns:ns0="http://www.rixg.org.uk/"><SendingFacility>RFBAK</SendingFacility><SendingExtract>PV</SendingExtract><Patient><PatientNumbers><PatientNumber><Number>1111111111</Number><Organization>CHI</Organization><NumberType>NI</NumberType></PatientNumber><PatientNumber><Number>U0000000</Number><Organization>LOCALHOSP</Organization><NumberType>MRN</NumberType></PatientNumber></PatientNumbers><Names><Nameuse="L"><Family>ATESTPATIENT</Family><Given>TESTING</Given></Name></Names><BirthTime>1950-10-01T00:00:00</BirthTime><Gender>9</Gender><Addresses><Address><Street>1TESTSTREET</Street><Town>TESTTOWN</Town><County>TESTCOUNTY</County><Postcode>DK13GG</Postcode><Country><CodingStandard>ISO3166-1</CodingStandard><Code>GB</Code><Description>UnitedKingdom</Description></Country></Address></Addresses></Patient></ns0:PatientRecord>Reading UKRDC XMLin_xml="""<?xml version="1.0" encoding="UTF-8"?><ns0:PatientRecord xmlns:ns0="http://www.rixg.org.uk/"><SendingFacility>RFBAK</SendingFacility><SendingExtract>PV</SendingExtract><Patient><PatientNumbers><PatientNumber><Number>1111111111</Number><Organization>CHI</Organization><NumberType>NI</NumberType></PatientNumber><PatientNumber><Number>U0000000</Number><Organization>LOCALHOSP</Organization><NumberType>MRN</NumberType></PatientNumber></PatientNumbers><Names><Name use="L"><Family>A TEST PATIENT</Family><Given>TESTING</Given></Name></Names><BirthTime>1950-10-01T00:00:00</BirthTime><Gender>9</Gender><Addresses><Address><Street>1 TEST STREET</Street><Town>TEST TOWN</Town><County>TEST COUNTY</County><Postcode>DK1 3GG</Postcode><Country><CodingStandard>ISO3166-1</CodingStandard><Code>GB</Code><Description>United Kingdom</Description></Country></Address></Addresses></Patient></ns0:PatientRecord>"""fromukrdc_xsdata.ukrdcimportPatientRecordfromxsdata.formats.dataclass.parsersimportXmlParserobj=XmlParser().from_string(in_xml,PatientRecord)The objectobjcan then be used to access the data as a standard Python dataclass instance.
E.g.obj.sending_facilityorobj.patient.names.name.