# Generated by Django 5.2.11 on 2026-03-19 14:46

import _socket
import uuid

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
import django_audit_fields.fields.hostname_modification_field
import django_audit_fields.fields.uuid_auto_field
import django_revision.revision_field
import edc_crf.model_mixins.crf_status_model_mixin
import edc_model.validators.date
import edc_protocol.validators
import edc_visit_tracking.managers
import simple_history.models
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ("meta_lists", "0021_diagnosticdevices"),
        ("meta_subject", "0244_glucose_comment_glucosefbg_comment_and_more"),
        ("sites", "0002_alter_domain_unique"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.AlterModelOptions(
            name="glucosefbg",
            options={
                "default_manager_name": "objects",
                "default_permissions": (
                    "add",
                    "change",
                    "delete",
                    "view",
                    "export",
                    "import",
                ),
                "verbose_name": "Glucose (FBG only)",
                "verbose_name_plural": "Glucose (FBG only)",
            },
        ),
        migrations.AlterModelOptions(
            name="historicalglucosefbg",
            options={
                "get_latest_by": ("history_date", "history_id"),
                "ordering": ("-history_date", "-history_id"),
                "verbose_name": "historical Glucose (FBG only)",
                "verbose_name_plural": "historical Glucose (FBG only)",
            },
        ),
        migrations.CreateModel(
            name="HistoricalGlucoseOgtt",
            fields=[
                (
                    "revision",
                    django_revision.revision_field.RevisionField(
                        blank=True,
                        default="",
                        editable=False,
                        help_text="System field. From git repository (tag:branch:commit), project metadata, project toml, project VERSION, or settings.",
                        max_length=75,
                        verbose_name="Revision",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(blank=True, default=django.utils.timezone.now),
                ),
                (
                    "modified",
                    models.DateTimeField(blank=True, default=django.utils.timezone.now),
                ),
                (
                    "user_created",
                    django_audit_fields.fields.userfield.UserField(
                        blank=True,
                        default="",
                        help_text="Updated by admin.save_model",
                        max_length=50,
                        verbose_name="user created",
                    ),
                ),
                (
                    "user_modified",
                    django_audit_fields.fields.userfield.UserField(
                        blank=True,
                        default="",
                        help_text="Updated by admin.save_model",
                        max_length=50,
                        verbose_name="user modified",
                    ),
                ),
                (
                    "hostname_created",
                    models.CharField(
                        blank=True,
                        default=_socket.gethostname,
                        help_text="System field. (modified on create only)",
                        max_length=60,
                        verbose_name="Hostname created",
                    ),
                ),
                (
                    "hostname_modified",
                    django_audit_fields.fields.hostname_modification_field.HostnameModificationField(
                        blank=True,
                        default="",
                        help_text="System field. (modified on every save)",
                        max_length=50,
                        verbose_name="Hostname modified",
                    ),
                ),
                (
                    "device_created",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=10,
                        verbose_name="Device created",
                    ),
                ),
                (
                    "device_modified",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=10,
                        verbose_name="Device modified",
                    ),
                ),
                (
                    "locale_created",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Auto-updated by Modeladmin",
                        max_length=10,
                        verbose_name="Locale created",
                    ),
                ),
                (
                    "locale_modified",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Auto-updated by Modeladmin",
                        max_length=10,
                        verbose_name="Locale modified",
                    ),
                ),
                (
                    "id",
                    django_audit_fields.fields.uuid_auto_field.UUIDAutoField(
                        blank=True,
                        db_index=True,
                        editable=False,
                        help_text="System auto field. UUID primary key.",
                    ),
                ),
                (
                    "consent_model",
                    models.CharField(blank=True, default="", max_length=50),
                ),
                (
                    "consent_version",
                    models.CharField(blank=True, default="", max_length=10),
                ),
                (
                    "report_datetime",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="If reporting today, use today's date/time, otherwise use the date/time this information was reported.",
                        validators=[
                            edc_protocol.validators.datetime_not_before_study_start,
                            edc_model.validators.date.datetime_not_future,
                        ],
                        verbose_name="Report Date",
                    ),
                ),
                (
                    "crf_status",
                    models.CharField(
                        choices=[
                            ("INCOMPLETE", "Incomplete (some data pending)"),
                            ("COMPLETE", "Complete"),
                        ],
                        default=edc_crf.model_mixins.crf_status_model_mixin.get_crf_status_default,
                        help_text="If some data is still pending, flag this CRF as incomplete",
                        max_length=25,
                        verbose_name="CRF status",
                    ),
                ),
                (
                    "crf_status_comments",
                    models.TextField(
                        blank=True,
                        default="",
                        help_text="for example, why some data is still pending",
                        verbose_name="Any comments related to status of this CRF",
                    ),
                ),
                (
                    "fasting",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        default="",
                        help_text="As reported by patient",
                        max_length=15,
                        verbose_name="Has the participant fasted?",
                    ),
                ),
                (
                    "fasting_duration_str",
                    models.CharField(
                        blank=True,
                        help_text="As reported by patient. Duration of fast. Format is `HHhMMm`. For example 1h23m, 12h7m, etc",
                        max_length=8,
                        null=True,
                        validators=[
                            django.core.validators.RegexValidator(
                                "^([0-9]{1,3}h([0-5]?[0-9]m)?)$",
                                message="Invalid format. Expected something like 1h20m, 11h5m, etc. No spaces allowed.",
                            )
                        ],
                        verbose_name="How long have they fasted in hours and/or minutes?",
                    ),
                ),
                (
                    "fasting_duration_delta",
                    models.DurationField(
                        blank=True,
                        help_text="system calculated to microseconds. (hours=microseconds/3.6e+9)",
                        null=True,
                    ),
                ),
                (
                    "ogtt_base_datetime",
                    models.DateTimeField(
                        blank=True,
                        help_text="(glucose solution given)",
                        null=True,
                        validators=[edc_model.validators.date.datetime_not_future],
                        verbose_name="Date/time oral glucose solution given",
                    ),
                ),
                (
                    "ogtt_value",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="A `HIGH` reading may be entered as 9999.99",
                        max_digits=8,
                        null=True,
                        verbose_name="Blood glucose measure 2hrs <u>after</u> oral glucose solution given",
                    ),
                ),
                (
                    "ogtt_quantifier",
                    models.CharField(
                        choices=[
                            ("=", "="),
                            (">", ">"),
                            (">=", ">="),
                            ("<", "<"),
                            ("<=", "<="),
                        ],
                        default="=",
                        max_length=10,
                    ),
                ),
                (
                    "ogtt_units",
                    models.CharField(
                        choices=[
                            ("mg/dL", "mg/dL"),
                            ("mmol/L", "mmol/L (millimoles/L)"),
                            ("N/A", "Not applicable"),
                        ],
                        default="N/A",
                        max_length=15,
                        verbose_name="Units (Blood glucose 2hrs after...)",
                    ),
                ),
                (
                    "ogtt_datetime",
                    models.DateTimeField(
                        blank=True,
                        help_text="(2 hours after glucose solution given)",
                        null=True,
                        validators=[edc_model.validators.date.datetime_not_future],
                        verbose_name="Date/time blood glucose measured 2hrs <u>after</u> oral glucose solution given",
                    ),
                ),
                (
                    "ogtt_performed",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Was the OGTT test performed?",
                    ),
                ),
                (
                    "ogtt_not_performed_reason",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=150,
                        verbose_name="If NO, provide reason",
                    ),
                ),
                (
                    "endpoint_today",
                    models.CharField(
                        choices=[
                            ("Yes", "Yes"),
                            ("PENDING", "No. A repeat FBG will be scheduled"),
                            ("No", "No"),
                            ("N/A", "Not applicable"),
                        ],
                        default="N/A",
                        help_text="Response is applicable if reporting after 24/11/2023 and both the FBG and OGTT were performed",
                        max_length=25,
                        verbose_name="Has the participant reached a study endpoint today?",
                    ),
                ),
                (
                    "comment",
                    models.TextField(
                        blank=True,
                        default="",
                        max_length=500,
                        verbose_name="Any other comment?",
                    ),
                ),
                (
                    "history_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("history_date", models.DateTimeField(db_index=True)),
                ("history_change_reason", models.CharField(max_length=100, null=True)),
                (
                    "history_type",
                    models.CharField(
                        choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")],
                        max_length=1,
                    ),
                ),
                (
                    "history_user",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        related_name="+",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
                (
                    "ogtt_diagnostic_device",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        limit_choices_to={"name__in": ["accuchek", "hemocue", "OTHER", "N/A"]},
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="meta_lists.diagnosticdevices",
                    ),
                ),
                (
                    "site",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="sites.site",
                    ),
                ),
                (
                    "subject_visit",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="meta_subject.subjectvisit",
                    ),
                ),
            ],
            options={
                "verbose_name": "historical Glucose (OGTT only)",
                "verbose_name_plural": "historical Glucose (OGTT only)",
                "ordering": ("-history_date", "-history_id"),
                "get_latest_by": ("history_date", "history_id"),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
        migrations.CreateModel(
            name="GlucoseOgtt",
            fields=[
                (
                    "revision",
                    django_revision.revision_field.RevisionField(
                        blank=True,
                        default="",
                        editable=False,
                        help_text="System field. From git repository (tag:branch:commit), project metadata, project toml, project VERSION, or settings.",
                        max_length=75,
                        verbose_name="Revision",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(blank=True, default=django.utils.timezone.now),
                ),
                (
                    "modified",
                    models.DateTimeField(blank=True, default=django.utils.timezone.now),
                ),
                (
                    "user_created",
                    django_audit_fields.fields.userfield.UserField(
                        blank=True,
                        default="",
                        help_text="Updated by admin.save_model",
                        max_length=50,
                        verbose_name="user created",
                    ),
                ),
                (
                    "user_modified",
                    django_audit_fields.fields.userfield.UserField(
                        blank=True,
                        default="",
                        help_text="Updated by admin.save_model",
                        max_length=50,
                        verbose_name="user modified",
                    ),
                ),
                (
                    "hostname_created",
                    models.CharField(
                        blank=True,
                        default=_socket.gethostname,
                        help_text="System field. (modified on create only)",
                        max_length=60,
                        verbose_name="Hostname created",
                    ),
                ),
                (
                    "hostname_modified",
                    django_audit_fields.fields.hostname_modification_field.HostnameModificationField(
                        blank=True,
                        default="",
                        help_text="System field. (modified on every save)",
                        max_length=50,
                        verbose_name="Hostname modified",
                    ),
                ),
                (
                    "device_created",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=10,
                        verbose_name="Device created",
                    ),
                ),
                (
                    "device_modified",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=10,
                        verbose_name="Device modified",
                    ),
                ),
                (
                    "locale_created",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Auto-updated by Modeladmin",
                        max_length=10,
                        verbose_name="Locale created",
                    ),
                ),
                (
                    "locale_modified",
                    models.CharField(
                        blank=True,
                        default="",
                        help_text="Auto-updated by Modeladmin",
                        max_length=10,
                        verbose_name="Locale modified",
                    ),
                ),
                (
                    "id",
                    django_audit_fields.fields.uuid_auto_field.UUIDAutoField(
                        blank=True,
                        editable=False,
                        help_text="System auto field. UUID primary key.",
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                (
                    "consent_model",
                    models.CharField(blank=True, default="", max_length=50),
                ),
                (
                    "consent_version",
                    models.CharField(blank=True, default="", max_length=10),
                ),
                (
                    "report_datetime",
                    models.DateTimeField(
                        default=django.utils.timezone.now,
                        help_text="If reporting today, use today's date/time, otherwise use the date/time this information was reported.",
                        validators=[
                            edc_protocol.validators.datetime_not_before_study_start,
                            edc_model.validators.date.datetime_not_future,
                        ],
                        verbose_name="Report Date",
                    ),
                ),
                (
                    "crf_status",
                    models.CharField(
                        choices=[
                            ("INCOMPLETE", "Incomplete (some data pending)"),
                            ("COMPLETE", "Complete"),
                        ],
                        default=edc_crf.model_mixins.crf_status_model_mixin.get_crf_status_default,
                        help_text="If some data is still pending, flag this CRF as incomplete",
                        max_length=25,
                        verbose_name="CRF status",
                    ),
                ),
                (
                    "crf_status_comments",
                    models.TextField(
                        blank=True,
                        default="",
                        help_text="for example, why some data is still pending",
                        verbose_name="Any comments related to status of this CRF",
                    ),
                ),
                (
                    "fasting",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        default="",
                        help_text="As reported by patient",
                        max_length=15,
                        verbose_name="Has the participant fasted?",
                    ),
                ),
                (
                    "fasting_duration_str",
                    models.CharField(
                        blank=True,
                        help_text="As reported by patient. Duration of fast. Format is `HHhMMm`. For example 1h23m, 12h7m, etc",
                        max_length=8,
                        null=True,
                        validators=[
                            django.core.validators.RegexValidator(
                                "^([0-9]{1,3}h([0-5]?[0-9]m)?)$",
                                message="Invalid format. Expected something like 1h20m, 11h5m, etc. No spaces allowed.",
                            )
                        ],
                        verbose_name="How long have they fasted in hours and/or minutes?",
                    ),
                ),
                (
                    "fasting_duration_delta",
                    models.DurationField(
                        blank=True,
                        help_text="system calculated to microseconds. (hours=microseconds/3.6e+9)",
                        null=True,
                    ),
                ),
                (
                    "ogtt_base_datetime",
                    models.DateTimeField(
                        blank=True,
                        help_text="(glucose solution given)",
                        null=True,
                        validators=[edc_model.validators.date.datetime_not_future],
                        verbose_name="Date/time oral glucose solution given",
                    ),
                ),
                (
                    "ogtt_value",
                    models.DecimalField(
                        blank=True,
                        decimal_places=2,
                        help_text="A `HIGH` reading may be entered as 9999.99",
                        max_digits=8,
                        null=True,
                        verbose_name="Blood glucose measure 2hrs <u>after</u> oral glucose solution given",
                    ),
                ),
                (
                    "ogtt_quantifier",
                    models.CharField(
                        choices=[
                            ("=", "="),
                            (">", ">"),
                            (">=", ">="),
                            ("<", "<"),
                            ("<=", "<="),
                        ],
                        default="=",
                        max_length=10,
                    ),
                ),
                (
                    "ogtt_units",
                    models.CharField(
                        choices=[
                            ("mg/dL", "mg/dL"),
                            ("mmol/L", "mmol/L (millimoles/L)"),
                            ("N/A", "Not applicable"),
                        ],
                        default="N/A",
                        max_length=15,
                        verbose_name="Units (Blood glucose 2hrs after...)",
                    ),
                ),
                (
                    "ogtt_datetime",
                    models.DateTimeField(
                        blank=True,
                        help_text="(2 hours after glucose solution given)",
                        null=True,
                        validators=[edc_model.validators.date.datetime_not_future],
                        verbose_name="Date/time blood glucose measured 2hrs <u>after</u> oral glucose solution given",
                    ),
                ),
                (
                    "ogtt_performed",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Was the OGTT test performed?",
                    ),
                ),
                (
                    "ogtt_not_performed_reason",
                    models.CharField(
                        blank=True,
                        default="",
                        max_length=150,
                        verbose_name="If NO, provide reason",
                    ),
                ),
                (
                    "endpoint_today",
                    models.CharField(
                        choices=[
                            ("Yes", "Yes"),
                            ("PENDING", "No. A repeat FBG will be scheduled"),
                            ("No", "No"),
                            ("N/A", "Not applicable"),
                        ],
                        default="N/A",
                        help_text="Response is applicable if reporting after 24/11/2023 and both the FBG and OGTT were performed",
                        max_length=25,
                        verbose_name="Has the participant reached a study endpoint today?",
                    ),
                ),
                (
                    "comment",
                    models.TextField(
                        blank=True,
                        default="",
                        max_length=500,
                        verbose_name="Any other comment?",
                    ),
                ),
                (
                    "ogtt_diagnostic_device",
                    models.ForeignKey(
                        limit_choices_to={"name__in": ["accuchek", "hemocue", "OTHER", "N/A"]},
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="ogtt_only_diagnostic_device",
                        to="meta_lists.diagnosticdevices",
                    ),
                ),
                (
                    "site",
                    models.ForeignKey(
                        null=True,
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="+",
                        to="sites.site",
                    ),
                ),
                (
                    "subject_visit",
                    models.OneToOneField(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="meta_subject.subjectvisit",
                    ),
                ),
            ],
            options={
                "verbose_name": "Glucose (OGTT only)",
                "verbose_name_plural": "Glucose (OGTT only)",
                "abstract": False,
                "default_permissions": (
                    "add",
                    "change",
                    "delete",
                    "view",
                    "export",
                    "import",
                ),
                "default_manager_name": "objects",
                "indexes": [
                    models.Index(
                        fields=["subject_visit", "site"],
                        name="meta_subjec_subject_71aa93_idx",
                    ),
                    models.Index(
                        fields=["subject_visit", "report_datetime"],
                        name="meta_subjec_subject_12c997_idx",
                    ),
                ],
            },
            managers=[
                ("objects", edc_visit_tracking.managers.CrfModelManager()),
                ("on_site", edc_visit_tracking.managers.CrfCurrentSiteManager()),
            ],
        ),
    ]
