# Generated by Django 4.2.4 on 2023-08-28 17:10

import _socket
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
import django_audit_fields.fields.hostname_modification_field
import django_audit_fields.fields.userfield
import django_audit_fields.fields.uuid_auto_field
import django_audit_fields.models.audit_model_mixin
import django_crypto_fields.fields.encrypted_char_field
import django_revision.revision_field
import edc_model.models.fields.duration
import edc_screening.model_mixins.screening_model_mixin
import edc_sites.model_mixins
import edc_utils.date
import edc_vitals.models.fields.blood_pressure
import simple_history.models
import uuid


class Migration(migrations.Migration):
    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("intecomm_screening", "0058_patientlogug"),
    ]

    operations = [
        migrations.CreateModel(
            name="SubjectScreeningUg",
            fields=[],
            options={
                "verbose_name": "Subject Screening (Uganda)",
                "verbose_name_plural": "Subject Screening (Uganda)",
                "proxy": True,
                "indexes": [],
                "constraints": [],
            },
            bases=("intecomm_screening.subjectscreening",),
            managers=[
                (
                    "objects",
                    edc_screening.model_mixins.screening_model_mixin.ScreeningManager(),
                ),
                ("on_site", edc_sites.model_mixins.CurrentSiteManager()),
            ],
        ),
        migrations.CreateModel(
            name="HistoricalSubjectScreeningUg",
            fields=[
                (
                    "revision",
                    django_revision.revision_field.RevisionField(
                        blank=True,
                        editable=False,
                        help_text="System field. Git repository tag:branch:commit.",
                        max_length=75,
                        null=True,
                        verbose_name="Revision",
                    ),
                ),
                (
                    "created",
                    models.DateTimeField(
                        blank=True, default=django_audit_fields.models.audit_model_mixin.utcnow
                    ),
                ),
                (
                    "modified",
                    models.DateTimeField(
                        blank=True, default=django_audit_fields.models.audit_model_mixin.utcnow
                    ),
                ),
                (
                    "user_created",
                    django_audit_fields.fields.userfield.UserField(
                        blank=True,
                        help_text="Updated by admin.save_model",
                        max_length=50,
                        verbose_name="user created",
                    ),
                ),
                (
                    "user_modified",
                    django_audit_fields.fields.userfield.UserField(
                        blank=True,
                        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,
                        help_text="System field. (modified on every save)",
                        max_length=50,
                        verbose_name="Hostname modified",
                    ),
                ),
                (
                    "device_created",
                    models.CharField(blank=True, max_length=10, verbose_name="Device created"),
                ),
                (
                    "device_modified",
                    models.CharField(
                        blank=True, max_length=10, verbose_name="Device 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.",
                    ),
                ),
                (
                    "legal_name",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        help_text=" (Encryption: RSA local)",
                        max_length=71,
                        validators=[
                            django.core.validators.RegexValidator(
                                message="Ensure full name consists of letters only in upper case separated by single spaces",
                                regex="^(([A-Z]+ )*[A-Z]+)?$",
                            )
                        ],
                        verbose_name="Full name",
                    ),
                ),
                (
                    "familiar_name",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        help_text="Should be a name. Do NOT use MR, MRS, MISS, SIR, MADAM and other such titles. (Encryption: RSA local)",
                        max_length=71,
                        validators=[
                            django.core.validators.RegexValidator(
                                message="Ensure name consists of letters only in upper case separated by single spaces",
                                regex="^(([A-Z]+ )*[A-Z]+)?$",
                            )
                        ],
                        verbose_name="By what NAME should we refer to you? (if we speak to you)",
                    ),
                ),
                ("subject_identifier", models.CharField(max_length=50)),
                (
                    "subject_identifier_as_pk",
                    models.UUIDField(default=uuid.uuid4, editable=False),
                ),
                (
                    "subject_identifier_aka",
                    models.CharField(
                        editable=False,
                        help_text="track a previously allocated identifier.",
                        max_length=50,
                        null=True,
                        verbose_name="Subject Identifier a.k.a",
                    ),
                ),
                (
                    "slug",
                    models.CharField(
                        db_index=True,
                        default="",
                        editable=False,
                        help_text="a field used for quick search",
                        max_length=250,
                        null=True,
                    ),
                ),
                ("eligible", models.BooleanField(default=False)),
                (
                    "reasons_ineligible",
                    models.TextField(
                        max_length=150, null=True, verbose_name="Reason not eligible"
                    ),
                ),
                (
                    "eligibility_datetime",
                    models.DateTimeField(
                        help_text="Date and time eligibility was determined relative to report_datetime",
                        null=True,
                    ),
                ),
                (
                    "real_eligibility_datetime",
                    models.DateTimeField(
                        help_text="Date and time eligibility was determined relative to now",
                        null=True,
                    ),
                ),
                (
                    "reference",
                    models.UUIDField(
                        db_index=True,
                        default=uuid.uuid4,
                        editable=False,
                        verbose_name="Reference",
                    ),
                ),
                (
                    "report_datetime",
                    models.DateTimeField(
                        default=edc_utils.date.get_utcnow,
                        help_text="Date and time of report.",
                        verbose_name="Report Date and Time",
                    ),
                ),
                (
                    "initials",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        help_text="Use UPPERCASE letters only. May be 2 or 3 letters. (Encryption: RSA local)",
                        max_length=71,
                        validators=[
                            django.core.validators.RegexValidator(
                                "[A-Z]{1,3}", "Invalid format"
                            ),
                            django.core.validators.MinLengthValidator(2),
                            django.core.validators.MaxLengthValidator(3),
                        ],
                    ),
                ),
                (
                    "gender",
                    models.CharField(choices=[("M", "Male"), ("F", "Female")], max_length=10),
                ),
                (
                    "age_in_years",
                    models.IntegerField(
                        validators=[
                            django.core.validators.MinValueValidator(0),
                            django.core.validators.MaxValueValidator(110),
                        ]
                    ),
                ),
                (
                    "consent_ability",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=25,
                        verbose_name="Participant or legal guardian/representative able and willing to give informed consent.",
                    ),
                ),
                (
                    "unsuitable_for_study",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        default="No",
                        help_text="If YES, patient NOT eligible, please give reason below.",
                        max_length=5,
                        verbose_name="Is there any other reason the patient is deemed to not be suitable for the study?",
                    ),
                ),
                (
                    "reasons_unsuitable",
                    models.TextField(
                        blank=True,
                        max_length=150,
                        null=True,
                        verbose_name="Reason not suitable for the study",
                    ),
                ),
                (
                    "unsuitable_agreed",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        max_length=5,
                        verbose_name="Does the study coordinator agree that the patient is not suitable for the study?",
                    ),
                ),
                ("consented", models.BooleanField(default=False, editable=False)),
                ("refused", models.BooleanField(default=False, editable=False)),
                (
                    "sys_blood_pressure_one",
                    edc_vitals.models.fields.blood_pressure.SystolicPressureField(
                        blank=True, null=True
                    ),
                ),
                (
                    "dia_blood_pressure_one",
                    edc_vitals.models.fields.blood_pressure.DiastolicPressureField(
                        blank=True, null=True
                    ),
                ),
                (
                    "sys_blood_pressure_two",
                    edc_vitals.models.fields.blood_pressure.SystolicPressureField(
                        blank=True, null=True
                    ),
                ),
                (
                    "dia_blood_pressure_two",
                    edc_vitals.models.fields.blood_pressure.DiastolicPressureField(
                        blank=True, null=True
                    ),
                ),
                (
                    "sys_blood_pressure_avg",
                    models.IntegerField(
                        blank=True,
                        null=True,
                        verbose_name="Blood pressure: systolic (average)",
                    ),
                ),
                (
                    "dia_blood_pressure_avg",
                    models.IntegerField(
                        blank=True,
                        null=True,
                        verbose_name="Blood pressure: diastolic (average)",
                    ),
                ),
                (
                    "severe_htn",
                    models.CharField(
                        blank=True,
                        choices=[("Yes", "Yes"), ("No", "No")],
                        help_text="Based on the above readings. Severe HTN is any BP reading > 180/110mmHg",
                        max_length=15,
                        null=True,
                        verbose_name="Does the patient have severe hypertension?",
                    ),
                ),
                (
                    "screening_identifier",
                    models.CharField(
                        blank=True, db_index=True, max_length=50, verbose_name="Screening ID"
                    ),
                ),
                (
                    "patient_log_identifier",
                    models.CharField(
                        db_index=True, max_length=50, verbose_name="Patient log identifier"
                    ),
                ),
                (
                    "selection_method",
                    models.CharField(
                        choices=[
                            ("random_sampling", "Random sampling"),
                            ("purposively_selected", "Purposively selected"),
                        ],
                        default="purposively_selected",
                        max_length=25,
                        verbose_name="How was the patient selected for screening?",
                    ),
                ),
                (
                    "hospital_identifier",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        db_index=True,
                        help_text=" (Encryption: RSA local)",
                        max_length=71,
                    ),
                ),
                (
                    "lives_nearby",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Does the patient live within the catchment population of the health facility",
                    ),
                ),
                (
                    "staying_nearby_6",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Is the patient planning to remain in this catchment area for at least 6 months",
                    ),
                ),
                (
                    "in_care_6m",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        help_text="for 6m or more at the health facility from which they are being recruited",
                        max_length=15,
                        verbose_name="Has the patient been in regular care at this health facility for 6 months or more",
                    ),
                ),
                (
                    "in_care_duration",
                    edc_model.models.fields.duration.DurationYMDField(blank=True, null=True),
                ),
                (
                    "hiv_dx",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Has the patient previously been diagnosed with HIV",
                    ),
                ),
                (
                    "hiv_dx_6m",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        max_length=15,
                        verbose_name="Was the initial diagnosis made more than 6 months ago",
                    ),
                ),
                (
                    "hiv_dx_ago",
                    edc_model.models.fields.duration.DurationYMDField(blank=True, null=True),
                ),
                (
                    "art_unchanged_3m",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        help_text="Meaning no modifications to the type of medication and dose for at least 3 months",
                        max_length=15,
                        verbose_name="Has the patient been on the same anti-retroviral therapy for at least 3 months",
                    ),
                ),
                (
                    "art_stable",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        help_text="considered by the clinical team not to have any complications/co-infections or that these are well managed.",
                        max_length=15,
                        verbose_name="Is the patient considered to be stable on treatment ",
                    ),
                ),
                (
                    "art_adherent",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        help_text="in regular attendance for care",
                        max_length=15,
                        verbose_name="Is the patient considered to be adherent to treatment over the last 6 months",
                    ),
                ),
                (
                    "dm_dx",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Has the patient previously been diagnosed with Diabetes",
                    ),
                ),
                (
                    "dm_dx_6m",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        max_length=15,
                        verbose_name="Was the initial diagnosis made more than 6 months ago",
                    ),
                ),
                (
                    "dm_dx_ago",
                    edc_model.models.fields.duration.DurationYMDField(blank=True, null=True),
                ),
                (
                    "dm_complications",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        max_length=15,
                        verbose_name="Does the patient suffer from any complications of diabetes that are unmanaged or uncontrolled.",
                    ),
                ),
                (
                    "htn_dx",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Has the patient previously been diagnosed with Hypertension",
                    ),
                ),
                (
                    "htn_dx_6m",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        max_length=15,
                        verbose_name="Was the initial diagnosis made more than 6 months ago",
                    ),
                ),
                (
                    "htn_dx_ago",
                    edc_model.models.fields.duration.DurationYMDField(blank=True, null=True),
                ),
                (
                    "htn_complications",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("N/A", "Not applicable")],
                        default="N/A",
                        max_length=15,
                        verbose_name="Does the patient suffer from any complications of hypertension that are unmanaged or uncontrolled.",
                    ),
                ),
                (
                    "excluded_by_bp_history",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Has the patient's blood pressure exceeded 180/110 mmHg on more than one occasion any time in the last 6 months.",
                    ),
                ),
                (
                    "excluded_by_gluc_history",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Has the patient's blood glucose exceeded 13 mmol/L any time in the last 6 months.",
                    ),
                ),
                (
                    "requires_acute_care",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No")],
                        max_length=15,
                        verbose_name="Does the patient have any clinical condition that requires health facility management",
                    ),
                ),
                (
                    "pregnant",
                    models.CharField(
                        choices=[
                            ("Yes", "Yes"),
                            ("No", "No"),
                            ("N/A", "Not Applicable: e.g. male or post-menopausal"),
                        ],
                        max_length=15,
                        verbose_name="Is the patient pregnant?",
                    ),
                ),
                (
                    "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,
                    ),
                ),
                (
                    "patient_log",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="intecomm_screening.patientlog",
                    ),
                ),
                (
                    "site",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="intecomm_screening.site",
                    ),
                ),
            ],
            options={
                "verbose_name": "historical Subject Screening (Uganda)",
                "verbose_name_plural": "historical Subject Screening (Uganda)",
                "ordering": ("-history_date", "-history_id"),
                "get_latest_by": ("history_date", "history_id"),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
    ]
