No project description provided
Project description
Pyredox - A Pydantic-Based Library for Redox Data
Pyredox is library for producing, ingesting, and validating data from Redox, a "data platform designed to connect providers, payers and products."
Pyredox is a set of Pydantic models that conforms to the Redox data model specification for the purpose of making it easy to convert Redox-formatted JSON to Python objects and vice versa. Because pyredox inherits the functionality of Pydantic, it validates that the JSON data conforms to the spec automatically upon object creation.
For example, if you tried to create a NewPatient
model with
insufficient data, you would get an error like this:
>>> from pyredox.patientadmin.newpatient import NewPatient
>>> NewPatient(Meta={})
ValidationError: 3 validation errors for NewPatient
Meta -> DataModel
field required (type=value_error.missing)
Meta -> EventType
field required (type=value_error.missing)
Patient
field required (type=value_error.missing)
Usage
The simplest way to create a pyredox
model from a JSON payload is to pass an
unpacked dict
as the parameter when initializing the object, like this:
payload_str = """
{
"Meta": {
"DataModel": "PatientAdmin",
"EventType": "NewPatient"
},
"Patient": {
"Identifiers": [
{
"ID": "e167267c-16c9-4fe3-96ae-9cff5703e90a",
"IDType": "EHRID"
}
]
}
}
"""
data = json.loads(payload_str)
new_patient = NewPatient(**data)
If you have a payload and don't know which object type it is, you can use the factory helper, which can take a JSON string or the loaded JSON dict/list:
from pyredox.factory import redox_object_factory
redox_object1 = redox_object_factory(payload_str) # str input
redox_object2 = redox_object_factory(data) # dict input
To create a JSON payload to send to Redox from an existing pyredox
object, just
call the json()
method of the object:
new_patient.json()
When working with the individual fields of a model object, you can traverse the element properties like so:
new_patient.patient.identifiers[0].id # "e167267c-16c9-4fe3-96ae-9cff5703e90a"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyredox-0.1.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06099674c72eaa250dca9b97cb1b8286ccf74edd1274dc08aabda0c40441660e |
|
MD5 | 9745e0b3d39b7250d8400b64574db0c8 |
|
BLAKE2b-256 | fe7ad2563a3e7639f1baefb6b2081d05d9542725c879cab279fd5baf0a26f5b0 |