# Generated by Django 4.2.4 on 2023-08-28 21:26

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_crypto_fields.fields.encrypted_text_field
import django_revision.revision_field
import edc_model.validators.phone
import edc_model_fields.fields.initials_field
import edc_model_fields.fields.other_charfield
import edc_utils
import edc_utils.date
import simple_history.models
import uuid


class Migration(migrations.Migration):
    dependencies = [
        ("intecomm_lists", "0008_medicationshortagereasons"),
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("intecomm_screening", "0059_subjectscreeningug_historicalsubjectscreeningug"),
    ]

    operations = [
        migrations.CreateModel(
            name="HistoricalPatientLogUg",
            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)",
                    ),
                ),
                (
                    "filing_identifier",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="Auto-populated when form is saved. <BR>This is a sequential-like identifier to label this patient's paper file",
                        max_length=36,
                        verbose_name="Filing number",
                    ),
                ),
                (
                    "patient_log_identifier",
                    models.CharField(
                        blank=True,
                        db_index=True,
                        help_text="Auto-populated when form is saved. <BR>You may prefer to use the FILING NUMBER. <BR>This identifier is replaced by the 'screening identifier' if the patient screens for the INTECOMM trial",
                        max_length=36,
                        verbose_name="Patient Log Reference",
                    ),
                ),
                (
                    "screening_identifier",
                    models.CharField(
                        db_index=True,
                        default=edc_utils.get_uuid,
                        help_text="Auto populated when screening form is complete",
                        max_length=36,
                    ),
                ),
                (
                    "screening_datetime",
                    models.DateTimeField(
                        blank=True,
                        help_text="Auto populated when screening form is complete",
                        null=True,
                    ),
                ),
                (
                    "subject_identifier",
                    models.CharField(
                        db_index=True,
                        default=edc_utils.get_uuid,
                        help_text="Auto populated when consent form is complete",
                        max_length=36,
                    ),
                ),
                (
                    "consent_datetime",
                    models.DateTimeField(
                        blank=True,
                        help_text="Auto populated when consent form is complete",
                        null=True,
                    ),
                ),
                (
                    "group_identifier",
                    models.CharField(
                        blank=True,
                        help_text="Auto populated when group is randomized",
                        max_length=25,
                        null=True,
                    ),
                ),
                (
                    "initials",
                    edc_model_fields.fields.initials_field.InitialsField(
                        help_text="Type 2-3 letters, all in uppercase and no spaces",
                        max_length=3,
                        verbose_name="Initials",
                    ),
                ),
                (
                    "gender",
                    models.CharField(choices=[("M", "Male"), ("F", "Female")], max_length=10),
                ),
                (
                    "age_in_years",
                    models.IntegerField(
                        validators=[
                            django.core.validators.MinValueValidator(18),
                            django.core.validators.MaxValueValidator(110),
                        ],
                        verbose_name="Age",
                    ),
                ),
                ("report_datetime", models.DateTimeField(default=edc_utils.date.get_utcnow)),
                (
                    "hospital_identifier",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        db_index=True,
                        help_text="Must be unique (Encryption: RSA local)",
                        max_length=71,
                        verbose_name="Hospital identifier",
                    ),
                ),
                (
                    "last_4_hospital_identifier",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        editable=False,
                        help_text="auto-populated (Encryption: RSA local)",
                        max_length=71,
                        null=True,
                        verbose_name="Last 4 digits of hospital_identifier",
                    ),
                ),
                (
                    "contact_number",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        help_text="If unknown, type 'UNKNOWN' (Encryption: RSA local)",
                        max_length=71,
                        validators=[edc_model.validators.phone.phone_number],
                    ),
                ),
                (
                    "alt_contact_number",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        help_text=" (Encryption: RSA local)",
                        max_length=71,
                        null=True,
                        validators=[edc_model.validators.phone.phone_number],
                    ),
                ),
                (
                    "last_4_contact_number",
                    django_crypto_fields.fields.encrypted_char_field.EncryptedCharField(
                        blank=True,
                        editable=False,
                        help_text="auto-populated (Encryption: RSA local)",
                        max_length=71,
                        null=True,
                        verbose_name="Last 4 digits of contact number",
                    ),
                ),
                (
                    "may_contact",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("tbd", "To be determined")],
                        default="tbd",
                        max_length=15,
                        verbose_name="Has the patient agreed to be contacted prior to consent?",
                    ),
                ),
                (
                    "location_description",
                    django_crypto_fields.fields.encrypted_text_field.EncryptedTextField(
                        blank=True,
                        help_text="Street, landmarks near home, etc (Encryption: AES local)",
                        max_length=71,
                        null=True,
                    ),
                ),
                (
                    "stable",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("tbd", "To be determined")],
                        default="tbd",
                        help_text="Refer to the SOP for the definition of 'stable'.",
                        max_length=15,
                        verbose_name="Do the facility health care staff consider the patient stable in care",
                    ),
                ),
                (
                    "last_appt_date",
                    models.DateField(
                        blank=True,
                        help_text="If known, the last appointment may help to estimate the next appointment or the expected frequency of routine appointments",
                        null=True,
                        verbose_name="When was the patient last seen at this health facility",
                    ),
                ),
                (
                    "next_appt_date",
                    models.DateField(
                        blank=True,
                        help_text="If known, this date will help prioritize efforts to contact the patient",
                        null=True,
                        verbose_name="Next scheduled routine appointment at this health facility",
                    ),
                ),
                (
                    "first_health_talk",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("tbd", "To be determined")],
                        default="tbd",
                        max_length=15,
                        verbose_name="Attended general health talk",
                    ),
                ),
                (
                    "first_health_talk_date",
                    models.DateField(blank=True, null=True, verbose_name="General talk date"),
                ),
                (
                    "second_health_talk",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("tbd", "To be determined")],
                        default="tbd",
                        max_length=15,
                        verbose_name="Attended sensitisation session",
                    ),
                ),
                (
                    "second_health_talk_date",
                    models.DateField(
                        blank=True, null=True, verbose_name="Sensitisation session date"
                    ),
                ),
                (
                    "call_attempts",
                    models.IntegerField(blank=True, default=0, help_text="auto-updated"),
                ),
                (
                    "willing_to_screen",
                    models.CharField(
                        choices=[("Yes", "Yes"), ("No", "No"), ("tbd", "To be determined")],
                        default="tbd",
                        max_length=15,
                        verbose_name="Has the patient agreed to be screened for the INTECOMM study",
                    ),
                ),
                (
                    "screening_refusal_reason_other",
                    edc_model_fields.fields.other_charfield.OtherCharField(
                        blank=True,
                        max_length=35,
                        null=True,
                        verbose_name="If other, please specify ...",
                    ),
                ),
                ("printed", models.BooleanField(default=False)),
                (
                    "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,
                    ),
                ),
                (
                    "screening_refusal_reason",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="intecomm_lists.screeningrefusalreasons",
                        verbose_name="Reason subject unwilling to screen",
                    ),
                ),
                (
                    "site",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        help_text="This question is asked to confirm you are logged in to the correct site.",
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="intecomm_screening.site",
                        verbose_name="Which site is this?",
                    ),
                ),
            ],
            options={
                "verbose_name": "historical Patient Log (Uganda)",
                "verbose_name_plural": "historical Patient Log (Uganda)",
                "ordering": ("-history_date", "-history_id"),
                "get_latest_by": ("history_date", "history_id"),
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
    ]
