# Generated by Django 3.0.9 on 2020-12-03 00:38

import uuid

import _socket
import django.core.validators
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.firstname_field
import django_crypto_fields.fields.lastname_field
import django_revision.revision_field
import edc_sites.models
import edc_utils.date
import simple_history.models
from django.conf import settings
from django.db import migrations, models

import mocca_screening.mocca_original_sites
import mocca_screening.models.mocca_register


class Migration(migrations.Migration):

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ("mocca_lists", "0001_initial"),
        ("sites", "0002_alter_domain_unique"),
        ("mocca_screening", "0001_initial"),
    ]

    operations = [
        migrations.AlterModelManagers(
            name="moccaregister",
            managers=[
                ("on_site", edc_sites.models.CurrentSiteManager()),
                ("objects", mocca_screening.models.mocca_register.Manager()),
            ],
        ),
        migrations.AddField(
            model_name="moccaregister",
            name="site",
            field=models.ForeignKey(
                editable=False,
                null=True,
                on_delete=django.db.models.deletion.PROTECT,
                related_name="+",
                to="sites.Site",
            ),
        ),
        migrations.AlterField(
            model_name="historicalsubjectscreening",
            name="mocca_study_identifier",
            field=models.CharField(
                db_index=True,
                help_text="Format must match original identifier. e.g. 12-3456 for UG, 123456 for TZ",
                max_length=25,
                validators=[
                    django.core.validators.RegexValidator(
                        "0[0-9]{1}\\-0[0-9]{3}|[0-9]{6}",
                        "Invalid format. Expected 12-3456 for UG, 123456 for TZ",
                    )
                ],
                verbose_name="Original MOCCA study identifier",
            ),
        ),
        migrations.AlterField(
            model_name="moccaregister",
            name="initials",
            field=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,
                null=True,
                validators=[
                    django.core.validators.RegexValidator("[A-Z]{1,3}", "Invalid format"),
                    django.core.validators.MinLengthValidator(2),
                    django.core.validators.MaxLengthValidator(3),
                ],
            ),
        ),
        migrations.AlterField(
            model_name="subjectscreening",
            name="mocca_study_identifier",
            field=models.CharField(
                help_text="Format must match original identifier. e.g. 12-3456 for UG, 123456 for TZ",
                max_length=25,
                unique=True,
                validators=[
                    django.core.validators.RegexValidator(
                        "0[0-9]{1}\\-0[0-9]{3}|[0-9]{6}",
                        "Invalid format. Expected 12-3456 for UG, 123456 for TZ",
                    )
                ],
                verbose_name="Original MOCCA study identifier",
            ),
        ),
        migrations.CreateModel(
            name="HistoricalMoccaRegister",
            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,
                    ),
                ),
                (
                    "hostname_modified",
                    django_audit_fields.fields.hostname_modification_field.HostnameModificationField(
                        blank=True,
                        help_text="System field. (modified on every save)",
                        max_length=50,
                    ),
                ),
                ("device_created", models.CharField(blank=True, max_length=10)),
                ("device_modified", models.CharField(blank=True, max_length=10)),
                (
                    "id",
                    django_audit_fields.fields.uuid_auto_field.UUIDAutoField(
                        blank=True,
                        db_index=True,
                        editable=False,
                        help_text="System auto field. UUID primary key.",
                    ),
                ),
                (
                    "report_datetime",
                    models.DateTimeField(default=edc_utils.date.get_utcnow),
                ),
                (
                    "mocca_screening_identifier",
                    models.CharField(
                        blank=True,
                        help_text="If known",
                        max_length=15,
                        null=True,
                        verbose_name="MOCCA (original) screening identifier",
                    ),
                ),
                (
                    "mocca_study_identifier",
                    models.CharField(
                        help_text="Format must match original identifier. e.g. 12-3456 for UG, 123456 for TZ",
                        max_length=25,
                        validators=[
                            django.core.validators.RegexValidator(
                                "0[0-9]{1}\\-0[0-9]{3}|[0-9]{6}",
                                "Invalid format. Expected 12-3456 for UG, 123456 for TZ",
                            )
                        ],
                        verbose_name="MOCCA (original) study identifier",
                    ),
                ),
                (
                    "mocca_country",
                    models.CharField(
                        choices=[("uganda", "Uganda"), ("tanzania", "Tanzania")],
                        max_length=25,
                    ),
                ),
                (
                    "first_name",
                    django_crypto_fields.fields.firstname_field.FirstnameField(
                        blank=True,
                        help_text=" (Encryption: RSA local)",
                        max_length=71,
                        null=True,
                    ),
                ),
                (
                    "last_name",
                    django_crypto_fields.fields.lastname_field.LastnameField(
                        blank=True,
                        help_text=" (Encryption: RSA local)",
                        max_length=71,
                        null=True,
                    ),
                ),
                (
                    "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,
                        null=True,
                        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(
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(18),
                            django.core.validators.MaxValueValidator(110),
                        ],
                    ),
                ),
                (
                    "birth_year",
                    models.IntegerField(
                        null=True,
                        validators=[
                            django.core.validators.MinValueValidator(1900),
                            django.core.validators.MaxValueValidator(2002),
                        ],
                    ),
                ),
                ("dob", models.DateField(blank=True, null=True)),
                (
                    "survival_status",
                    models.CharField(
                        choices=[
                            ("alive", "Alive"),
                            ("dead", "Deceased"),
                            ("unknown", "Unknown"),
                        ],
                        default="unknown",
                        max_length=25,
                    ),
                ),
                (
                    "history_id",
                    models.UUIDField(
                        default=uuid.uuid4,
                        editable=False,
                        primary_key=True,
                        serialize=False,
                    ),
                ),
                ("history_date", models.DateTimeField()),
                ("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,
                    ),
                ),
                (
                    "mocca_site",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        limit_choices_to=mocca_screening.mocca_original_sites.get_mocca_site_limited_to,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="mocca_lists.MoccaOriginalSites",
                    ),
                ),
                (
                    "site",
                    models.ForeignKey(
                        blank=True,
                        db_constraint=False,
                        editable=False,
                        null=True,
                        on_delete=django.db.models.deletion.DO_NOTHING,
                        related_name="+",
                        to="sites.Site",
                    ),
                ),
            ],
            options={
                "verbose_name": "historical MOCCA Patient Register",
                "ordering": ("-history_date", "-history_id"),
                "get_latest_by": "history_date",
            },
            bases=(simple_history.models.HistoricalChanges, models.Model),
        ),
    ]
