Source code for examples.sintrom.schemas
from typing import Final
import numpy as np
import pandas as pd
import pandera.pandas as pa
from pandera.typing.pandas import Index, Series
from sara.oar import OARSchema
class SintromETLSchema(pa.DataFrameModel):
"""Describe Schema for Sintrom ETL dataframe."""
inr: Series[pd.Float64Dtype] = pa.Field(
metadata={
"description": "The inr of the patient at date before"
"sintrom prescription",
},
)
sintrom: Series[pd.Float64Dtype] = pa.Field(
metadata={"description": "The sintrom administered in mg"},
)
row: Index[pd.Int64Dtype] = pa.Field(
metadata={"description": "Row index in the original excel dataset"},
)
date: Index[np.datetime64] = pa.Field(
metadata={"description": "date of the day"},
)
class Config:
"""Add process description to SintromETLSchema."""
metadata: Final[dict] = {
"process": (
"0. For patient 'row' at day 'date'.\n"
"1. The inr 'inr' is measured.\n"
"2. Dr acknowledge this inr and prescribes 'sintrom' dose "
"of sintrom."
),
}
[docs]
class SintromEnvSchema(OARSchema):
"""Pandera OAR Schema for sintrom prescription environment."""
inr: Series[pd.Float64Dtype] = pa.Field(
alias=("obs0", "inr"),
metadata={
"description": "The inr of the patient at date before "
"sintrom prescription",
},
)
sintrom: Series[pd.Float64Dtype] = pa.Field(
alias=("act0", "sintrom"),
metadata={"description": "The sintrom administered in mg"},
)
inr_quality: Series[pd.Float64Dtype] = pa.Field(
alias=("rew1", "inr_quality"),
metadata={
"description": (
"Quality of the inr the day after sintrom administration. "
"Specifically quality = -|inr - 2.5|."
),
},
)
row: Index[pd.Int64Dtype] = pa.Field(
metadata={"description": "Row index in the original excel dataset"},
)
date: Index[np.datetime64] = pa.Field(
metadata={"description": "date of the day"},
)
class Config:
"""Add process and description to SintromEnvSchema."""
metadata: Final[dict] = {
"description": (
"Sintrom (acenocoumarol) is "
"an oral anticoagulant of the vitamin K antagonist class, prescribed "
"to reduce the risk of thromboembolic events in conditions such as "
"atrial fibrillation, venous thrombosis, pulmonary embolism, or in "
"patients with prosthetic heart valves. Its action is monitored using "
"the International Normalized Ratio (INR), a standardized measure of "
"blood clotting time. The therapeutic INR target depends on the "
"clinical situation: most indications require an INR between 2.0 and "
"3.0, while mechanical heart valves generally require a higher range, "
"around 2.5 to 3.5. Prescribing Sintrom means adjusting the daily "
"dose to keep the patient within this target range. If the INR is "
"below target, the dose should be increased; if the INR is above, the "
"dose should be reduced or temporarily stopped, and in cases of very "
"high INR, vitamin K may be considered to reverse the effect. Regular "
"monitoring is essential, especially when starting treatment or after "
"dose adjustments, typically every few days initially and then every "
"few weeks once the INR is stable. Prescribers must also take into "
"account interactions with diet, alcohol, and other medications."
),
"process": (
"0. For patient 'row' at day 'date'.\n"
"1. Dr observes inr ('obs0', 'inr').\n"
"2. Dr prescribes ('act0', 'sintrom') dose of sintrom.\n"
"3, Dr receives ('rew1', 'inr_quality') as reward."
),
}