meta-edc 1.0.6__py3-none-any.whl → 1.0.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- meta_analytics/dataframes/__init__.py +3 -0
- meta_analytics/dataframes/constants.py +1 -1
- meta_analytics/dataframes/enrolled/__init__.py +0 -1
- meta_analytics/dataframes/get_eos_df.py +15 -2
- meta_analytics/dataframes/get_glucose_df.py +149 -0
- meta_analytics/dataframes/get_glucose_fbg_df.py +27 -0
- meta_analytics/dataframes/get_glucose_fbg_ogtt_df.py +22 -0
- meta_analytics/dataframes/glucose_endpoints/endpoint_by_date.py +106 -120
- meta_analytics/dataframes/glucose_endpoints/glucose_endpoints_by_date.py +36 -227
- meta_analytics/dataframes/utils.py +18 -4
- meta_analytics/notebooks/hiv_regimens.ipynb +425 -0
- meta_analytics/notebooks/monitoring_report.ipynb +1561 -0
- meta_analytics/notebooks/pharmacy.ipynb +971 -0
- meta_analytics/utils.py +81 -0
- {meta_edc-1.0.6.dist-info → meta_edc-1.0.7.dist-info}/METADATA +4 -3
- {meta_edc-1.0.6.dist-info → meta_edc-1.0.7.dist-info}/RECORD +32 -18
- {meta_edc-1.0.6.dist-info → meta_edc-1.0.7.dist-info}/WHEEL +1 -1
- meta_edc-1.0.7.dist-info/licenses/AUTHORS.rst +8 -0
- meta_reports/migrations/0054_auto_20250422_2003.py +81 -0
- meta_reports/migrations/0055_alter_glucosesummary_table.py +17 -0
- meta_reports/migrations/0056_auto_20250422_2214.py +54 -0
- meta_reports/migrations/0057_auto_20250422_2224.py +54 -0
- meta_reports/migrations/0058_auto_20250422_2232.py +54 -0
- meta_reports/models/dbviews/glucose_summary/unmanaged_model.py +13 -1
- meta_reports/models/dbviews/glucose_summary/view_definition.py +8 -5
- meta_subject/form_validators/glucose_form_validator.py +16 -1
- meta_subject/forms/study_medication_form.py +5 -3
- meta_subject/migrations/0221_auto_20250402_1913.py +42 -0
- meta_subject/migrations/0222_alter_historicalstudymedication_stock_codes_and_more.py +46 -0
- meta_analytics/dataframes/enrolled/get_glucose_df.py +0 -122
- /meta_edc-1.0.6.dist-info/AUTHORS → /meta_analytics/dataframes/glucose_endpoints/utils.py +0 -0
- {meta_edc-1.0.6.dist-info → meta_edc-1.0.7.dist-info/licenses}/LICENSE +0 -0
- {meta_edc-1.0.6.dist-info → meta_edc-1.0.7.dist-info}/top_level.txt +0 -0
@@ -5,6 +5,8 @@ from edc_crf.crf_form_validator import CrfFormValidator
|
|
5
5
|
from edc_form_validators import INVALID_ERROR
|
6
6
|
from edc_glucose.form_validators import FbgOgttFormValidatorMixin
|
7
7
|
|
8
|
+
from meta_reports.models import GlucoseSummary
|
9
|
+
|
8
10
|
from ..constants import AMENDMENT_DATE
|
9
11
|
|
10
12
|
|
@@ -79,5 +81,18 @@ class GlucoseFormValidator(FbgOgttFormValidatorMixin, CrfFormValidator):
|
|
79
81
|
elif self.cleaned_data.get("fbg_value") >= Decimal("7.0") and self.cleaned_data.get(
|
80
82
|
"ogtt_value"
|
81
83
|
) < Decimal("11.1"):
|
82
|
-
|
84
|
+
# is there a previous FBG>=7.0 in sequence or do you need to repeat?
|
85
|
+
previous_obj = (
|
86
|
+
GlucoseSummary.objects.filter(
|
87
|
+
subject_identifier=self.subject_identifier,
|
88
|
+
fbg_datetime__lt=self.cleaned_data.get("fbg_datetime"),
|
89
|
+
)
|
90
|
+
.order_by("fbg_datetime")
|
91
|
+
.last()
|
92
|
+
)
|
93
|
+
if previous_obj and previous_obj.fbg_value >= Decimal("7.0"):
|
94
|
+
value = YES
|
95
|
+
else:
|
96
|
+
# you need to schedule a repeat
|
97
|
+
value = PENDING
|
83
98
|
return value
|
@@ -38,16 +38,18 @@ class StudyMedicationFormValidator(BaseStudyMedicationFormValidator):
|
|
38
38
|
|
39
39
|
def validate_stock_codes_are_dispensed(self):
|
40
40
|
if self.cleaned_data.get("stock_codes"):
|
41
|
-
pattern = re.compile("^([A-Z0-9]{6})(,[A-Z0-9]{6})*$")
|
41
|
+
# pattern = re.compile("^([A-Z0-9]{6})(,[A-Z0-9]{6})*$")
|
42
|
+
pattern = re.compile("^([A-Z0-9]{6})(\r\n[A-Z0-9]{6})*$")
|
42
43
|
if not pattern.match(self.cleaned_data.get("stock_codes")):
|
43
44
|
raise forms.ValidationError(
|
44
45
|
{
|
45
46
|
"stock_codes": (
|
46
|
-
"Invalid format. Enter one or more valid codes
|
47
|
+
"Invalid format. Enter one or more valid codes. "
|
48
|
+
"One code per line only. No commas, spaces, etc"
|
47
49
|
)
|
48
50
|
}
|
49
51
|
)
|
50
|
-
for stock_code in self.cleaned_data.get("stock_codes").split("
|
52
|
+
for stock_code in self.cleaned_data.get("stock_codes").split("\r\n"):
|
51
53
|
try:
|
52
54
|
Stock.objects.get(
|
53
55
|
code=stock_code,
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Generated by Django 6.0 on 2025-04-02 16:13
|
2
|
+
from django.apps import apps as django_apps
|
3
|
+
from django.db import migrations
|
4
|
+
from django.db.migrations import RunPython
|
5
|
+
from edc_appointment.constants import MISSED_APPT
|
6
|
+
from edc_pdutils.dataframes import get_crf
|
7
|
+
from edc_utils import get_utcnow
|
8
|
+
from tqdm import tqdm
|
9
|
+
|
10
|
+
|
11
|
+
def update(apps, schema_editor):
|
12
|
+
"""Correct missed appointments incorrectly set to
|
13
|
+
appt_timing=ONTIME_APPT.
|
14
|
+
"""
|
15
|
+
appointment_model_cls = django_apps.get_model("edc_appointment.appointment")
|
16
|
+
df_missedvisit = get_crf(
|
17
|
+
"meta_subject.subjectvisitmissed",
|
18
|
+
subject_visit_model="meta_subject.subjectvisit",
|
19
|
+
)
|
20
|
+
df_subjects = df_missedvisit[df_missedvisit.appt_timing != MISSED_APPT][
|
21
|
+
["subject_identifier", "visit_code_str", "visit_code_sequence"]
|
22
|
+
].copy()
|
23
|
+
for tpl in tqdm(df_subjects.itertuples(), total=len(df_subjects)):
|
24
|
+
obj = appointment_model_cls.objects.get(
|
25
|
+
subject_identifier=tpl.subject_identifier,
|
26
|
+
visit_code=tpl.visit_code_str,
|
27
|
+
visit_code_sequence=tpl.visit_code_sequence,
|
28
|
+
)
|
29
|
+
obj.appt_timing = MISSED_APPT
|
30
|
+
obj.modified = get_utcnow()
|
31
|
+
obj.user_modified = "erikvw"
|
32
|
+
|
33
|
+
obj.save(update_fields=["appt_timing", "user_modified", "modified"])
|
34
|
+
|
35
|
+
|
36
|
+
class Migration(migrations.Migration):
|
37
|
+
|
38
|
+
dependencies = [
|
39
|
+
("meta_subject", "0220_historicalbloodresultsgludummy_bloodresultsgludummy"),
|
40
|
+
]
|
41
|
+
|
42
|
+
operations = [RunPython(update)]
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Generated by Django 6.0 on 2025-04-15 22:06
|
2
|
+
|
3
|
+
import django.core.validators
|
4
|
+
from django.db import migrations, models
|
5
|
+
|
6
|
+
|
7
|
+
class Migration(migrations.Migration):
|
8
|
+
|
9
|
+
dependencies = [
|
10
|
+
("meta_subject", "0221_auto_20250402_1913"),
|
11
|
+
]
|
12
|
+
|
13
|
+
operations = [
|
14
|
+
migrations.AlterField(
|
15
|
+
model_name="historicalstudymedication",
|
16
|
+
name="stock_codes",
|
17
|
+
field=models.TextField(
|
18
|
+
blank=True,
|
19
|
+
help_text="Enter the medication bottle barcode or barcodes. Type one code per line",
|
20
|
+
max_length=30,
|
21
|
+
null=True,
|
22
|
+
validators=[
|
23
|
+
django.core.validators.RegexValidator(
|
24
|
+
message="Enter one or more valid codes, one code per line",
|
25
|
+
regex="^([A-Z0-9]{6})(\r\n[A-Z0-9]{6})*$",
|
26
|
+
)
|
27
|
+
],
|
28
|
+
),
|
29
|
+
),
|
30
|
+
migrations.AlterField(
|
31
|
+
model_name="studymedication",
|
32
|
+
name="stock_codes",
|
33
|
+
field=models.TextField(
|
34
|
+
blank=True,
|
35
|
+
help_text="Enter the medication bottle barcode or barcodes. Type one code per line",
|
36
|
+
max_length=30,
|
37
|
+
null=True,
|
38
|
+
validators=[
|
39
|
+
django.core.validators.RegexValidator(
|
40
|
+
message="Enter one or more valid codes, one code per line",
|
41
|
+
regex="^([A-Z0-9]{6})(\r\n[A-Z0-9]{6})*$",
|
42
|
+
)
|
43
|
+
],
|
44
|
+
),
|
45
|
+
),
|
46
|
+
]
|
@@ -1,122 +0,0 @@
|
|
1
|
-
import numpy as np
|
2
|
-
import pandas as pd
|
3
|
-
from django_pandas.io import read_frame
|
4
|
-
from edc_pdutils.dataframes import get_eos, get_subject_consent, get_subject_visit
|
5
|
-
|
6
|
-
from meta_subject.models import Glucose, GlucoseFbg
|
7
|
-
|
8
|
-
|
9
|
-
def get_glucose_df() -> pd.DataFrame:
|
10
|
-
qs_glucose_fbg = GlucoseFbg.objects.all()
|
11
|
-
df_glucose_fbg = read_frame(qs_glucose_fbg)
|
12
|
-
df_glucose_fbg.rename(
|
13
|
-
columns={"fbg_fasting": "fasting", "subject_visit": "subject_visit_id"},
|
14
|
-
inplace=True,
|
15
|
-
)
|
16
|
-
|
17
|
-
df_glucose_fbg.loc[(df_glucose_fbg["fasting"] == "fasting"), "fasting"] = "Yes"
|
18
|
-
df_glucose_fbg.loc[(df_glucose_fbg["fasting"] == "non_fasting"), "fasting"] = "No"
|
19
|
-
df_glucose_fbg["fasting_hrs"] = np.nan
|
20
|
-
df_glucose_fbg["fasting_hrs"] = df_glucose_fbg["fasting_duration_delta"].apply(
|
21
|
-
lambda x: x.total_seconds() / 3600
|
22
|
-
)
|
23
|
-
df_glucose_fbg["fasting_hrs"] = df_glucose_fbg["fasting_hrs"].apply(
|
24
|
-
lambda x: 8.05 if not x else x
|
25
|
-
)
|
26
|
-
# df_glucose_fbg = df_glucose_fbg.loc[df_glucose_fbg["fasting_hrs"] >= 8.0]
|
27
|
-
# df_glucose_fbg.reset_index(drop=True, inplace=True)
|
28
|
-
df_glucose_fbg.loc[
|
29
|
-
:,
|
30
|
-
["ogtt_value", "ogtt_units", "ogtt_datetime"],
|
31
|
-
] = [np.nan, None, pd.NaT]
|
32
|
-
df_glucose_fbg["source"] = "meta_subject.glucosefbg"
|
33
|
-
|
34
|
-
qs_glucose = Glucose.objects.all()
|
35
|
-
df_glucose = read_frame(qs_glucose)
|
36
|
-
df_glucose.rename(columns={"subject_visit": "subject_visit_id"}, inplace=True)
|
37
|
-
df_glucose.loc[(df_glucose["fasting"] == "fasting"), "fasting"] = "Yes"
|
38
|
-
df_glucose.loc[(df_glucose["fasting"] == "non_fasting"), "fasting"] = "No"
|
39
|
-
df_glucose["fasting_hrs"] = np.nan
|
40
|
-
df_glucose["fasting_hrs"] = df_glucose[df_glucose["fasting"] == "Yes"][
|
41
|
-
"fasting_duration_delta"
|
42
|
-
].apply(lambda x: x.total_seconds() / 3600)
|
43
|
-
df_glucose["fasting_hrs"] = df_glucose["fasting_hrs"].apply(lambda x: 8.05 if not x else x)
|
44
|
-
# df_glucose = df_glucose.loc[df_glucose["fasting_hrs"] >= 8.0]
|
45
|
-
# df_glucose.reset_index(drop=True, inplace=True)
|
46
|
-
df_glucose["source"] = "meta_subject.glucose"
|
47
|
-
|
48
|
-
keep_cols = [
|
49
|
-
"subject_visit_id",
|
50
|
-
"fasting",
|
51
|
-
"fasting_hrs",
|
52
|
-
"fbg_value",
|
53
|
-
"fbg_units",
|
54
|
-
"fbg_datetime",
|
55
|
-
"ogtt_value",
|
56
|
-
"ogtt_units",
|
57
|
-
"ogtt_datetime",
|
58
|
-
"source",
|
59
|
-
"revision",
|
60
|
-
"report_datetime",
|
61
|
-
]
|
62
|
-
df_glucose = df_glucose[keep_cols]
|
63
|
-
df_glucose_fbg = df_glucose_fbg[keep_cols]
|
64
|
-
# df = pd.concat([df_glucose_fbg, df_glucose])
|
65
|
-
df = pd.merge(
|
66
|
-
df_glucose,
|
67
|
-
df_glucose_fbg,
|
68
|
-
on="subject_visit_id",
|
69
|
-
how="outer",
|
70
|
-
indicator=True,
|
71
|
-
suffixes=("", "_2"),
|
72
|
-
)
|
73
|
-
|
74
|
-
for suffix in ["", "_2"]:
|
75
|
-
cols = [f"fasting_hrs{suffix}", f"fbg_value{suffix}", f"ogtt_value{suffix}"]
|
76
|
-
df[cols] = df[cols].apply(pd.to_numeric)
|
77
|
-
cols = [f"fbg_datetime{suffix}", f"ogtt_datetime{suffix}"]
|
78
|
-
df[cols] = df[cols].apply(pd.to_datetime)
|
79
|
-
df.loc[
|
80
|
-
(df[f"fbg_units{suffix}"] != "mmol/L (millimoles/L)")
|
81
|
-
& (df[f"fbg_value{suffix}"] >= 0),
|
82
|
-
f"fbg_units{suffix}",
|
83
|
-
] = "mmol/L (millimoles/L)"
|
84
|
-
df.loc[
|
85
|
-
(df[f"ogtt_units{suffix}"] != "mmol/L (millimoles/L)")
|
86
|
-
& (df[f"ogtt_value{suffix}"] >= 0),
|
87
|
-
f"ogtt_units{suffix}",
|
88
|
-
] = "mmol/L (millimoles/L)"
|
89
|
-
# remove values if not fasted
|
90
|
-
# df.loc[(df[f"fasting{suffix}"] != YES), f"fbg_value{suffix}"] = np.nan
|
91
|
-
# df.loc[(df[f"fasting{suffix}"] != YES), f"ogtt_value{suffix}"] = np.nan
|
92
|
-
|
93
|
-
# reconcile all to single column
|
94
|
-
df.loc[(df["fbg_value"].isna()) & (df["fbg_value_2"].notna()), "fbg_value"] = df[
|
95
|
-
"fbg_value_2"
|
96
|
-
]
|
97
|
-
df.loc[(df["ogtt_value"].isna()) & (df["ogtt_value_2"].notna()), "ogtt_value"] = df[
|
98
|
-
"ogtt_value_2"
|
99
|
-
]
|
100
|
-
cols = [col for col in list(df.columns) if col.endswith("_2")]
|
101
|
-
df.drop(columns=cols, inplace=True)
|
102
|
-
cols = [col for col in list(df.columns) if col.endswith("_3")]
|
103
|
-
df.drop(columns=cols, inplace=True)
|
104
|
-
|
105
|
-
df_subject_visit = get_subject_visit("meta_subject.subjectvisit")
|
106
|
-
df_consent = get_subject_consent("meta_consent.subjectconsent")
|
107
|
-
df_eos = get_eos("meta_prn.endofstudy")
|
108
|
-
|
109
|
-
df = pd.merge(df_subject_visit, df, on="subject_visit_id", how="left")
|
110
|
-
df = pd.merge(df, df_consent, on="subject_identifier", how="left")
|
111
|
-
df = pd.merge(df, df_eos, on="subject_identifier", how="left")
|
112
|
-
|
113
|
-
df["visit_days"] = df["baseline_datetime"].rsub(df["visit_datetime"]).dt.days
|
114
|
-
df["fgb_days"] = df["baseline_datetime"].rsub(df["fbg_datetime"]).dt.days
|
115
|
-
df["ogtt_days"] = df["baseline_datetime"].rsub(df["ogtt_datetime"]).dt.days
|
116
|
-
df["visit_days"] = pd.to_numeric(df["visit_days"], downcast="integer")
|
117
|
-
df["fgb_days"] = pd.to_numeric(df["fgb_days"], downcast="integer")
|
118
|
-
df["ogtt_days"] = pd.to_numeric(df["ogtt_days"], downcast="integer")
|
119
|
-
|
120
|
-
df = df.sort_values(by=["subject_identifier", "visit_code"])
|
121
|
-
df.reset_index(drop=True, inplace=True)
|
122
|
-
return df
|
File without changes
|
File without changes
|
File without changes
|