Skip to main content

No project description provided

Project description

UKRDC-XSData

XSData models for the UKRDC.

Installation

pip install ukrdc-xsdata

Basic usage

Creating UKRDC XML

import datetime
from xsdata.models.datatype import XmlDateTime
from ukrdc_xsdata.ukrdc import PatientRecord, Patient, types

record = PatientRecord(
    sending_facility = "RFBAK",
    sending_extract = "PV",
    patient = Patient(
        birth_time = XmlDateTime.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,
                )
            ]
        )
    )
)


from xsdata.formats.dataclass.serializers.xml import XmlSerializer

print(XmlSerializer().render(record))

will render

<?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>

Reading UKRDC XML

in_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>
"""

from ukrdc_xsdata.ukrdc import PatientRecord
from xsdata.formats.dataclass.parsers import XmlParser

obj = XmlParser().from_string(in_xml, PatientRecord)

The object obj can then be used to access the data as a standard Python dataclass instance. E.g. obj.sending_facility or obj.patient.names.name.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ukrdc-xsdata-3.3.0.post1.tar.gz (70.7 kB view details)

Uploaded Source

Built Distribution

ukrdc_xsdata-3.3.0.post1-py3-none-any.whl (99.0 kB view details)

Uploaded Python 3

File details

Details for the file ukrdc-xsdata-3.3.0.post1.tar.gz.

File metadata

  • Download URL: ukrdc-xsdata-3.3.0.post1.tar.gz
  • Upload date:
  • Size: 70.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for ukrdc-xsdata-3.3.0.post1.tar.gz
Algorithm Hash digest
SHA256 fc4ef1dfe94b00e0edeb97101dc4b02e3eb3a7ac4ff10e02a54528075e22261b
MD5 99021d1053461c79b808fa1a01130dd1
BLAKE2b-256 85065f8ada101ef353f763d140d32657fc4d0bed95badbd263725b4c1455b742

See more details on using hashes here.

File details

Details for the file ukrdc_xsdata-3.3.0.post1-py3-none-any.whl.

File metadata

  • Download URL: ukrdc_xsdata-3.3.0.post1-py3-none-any.whl
  • Upload date:
  • Size: 99.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for ukrdc_xsdata-3.3.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 a3988040b209b66c794f0f30ba02532b475038b547c99fe58cbe8ab9854b6cf7
MD5 39b2d0d2fd9aae998290c5247df9d986
BLAKE2b-256 ce3d78d092bb33bbe552e64369cf0088157860274e22e609da5749148d5e9e5d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page