Skip to main content

No project description provided

Project description

Pyredox - A Pydantic-Based Library for Redox Data

PyPI Info GitHub Workflow Status Coverage Info Black Code Style

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


Download files

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

Source Distribution

pyredox-1.0.0.tar.gz (92.0 kB view hashes)

Uploaded Source

Built Distribution

pyredox-1.0.0-py3-none-any.whl (192.5 kB view hashes)

Uploaded Python 3

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