# Generated by Django 3.2.14 on 2022-07-26 03:11

import django.contrib.postgres.fields
import django.db.models.deletion
from django.db import migrations, models

import hawc.apps.common.models


class Migration(migrations.Migration):
    initial = True

    dependencies = [
        ("epi", "0018_django31"),
        ("study", "0011_auto_20190416_2035"),
        ("assessment", "0032_assessment_epi_version"),
    ]

    operations = [
        migrations.CreateModel(
            name="AdjustmentFactor",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text='A unique name for this adjustment set that will help you identify it later. It may be descriptive or a dummy variable ("A").',
                        max_length=32,
                    ),
                ),
                (
                    "description",
                    models.CharField(
                        help_text='Enter the list of covariates in the model, separated by commas. These can be brief and ideally entered uniformly across studies when possible. Additional detail can be added in the comments or in study evaluation (e.g., enter "smoking" for consistency instead of "pack-years")',
                        max_length=512,
                    ),
                ),
                ("comments", models.TextField(blank=True)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
            ],
            options={
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="Chemical",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="This field is commonly used in visualizations, so consider using a common acronym, e.g., BPA instead of Bisphenol A",
                        max_length=128,
                    ),
                ),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
            ],
            options={
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="Design",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "summary",
                    models.CharField(
                        help_text="Briefly describe the study population. Try to capture anything outside a typical general population samples (e.g.,people with a specific health condition, specific environments [e.g., assisted living facility, farmers, etc.], exposure scenario, etc. This field may be used in visualizations as a summary of the study, so it is important to be consistent within the assessment.",
                        max_length=128,
                        verbose_name="Population Summary",
                    ),
                ),
                (
                    "study_name",
                    models.CharField(
                        blank=True,
                        help_text="Study name assigned by authors. Typically available for cohorts.",
                        max_length=128,
                        null=True,
                        verbose_name="Study name (if applicable)",
                    ),
                ),
                (
                    "study_design",
                    models.CharField(
                        choices=[
                            ("CO", "Cohort"),
                            ("CC", "Case-control"),
                            ("NC", "Nested case-control"),
                            ("CR", "Case report"),
                            ("SE", "Case series"),
                            ("RT", "Randomized controlled trial"),
                            ("NT", "Non-randomized controlled trial"),
                            ("CS", "Cross-sectional"),
                            ("EC", "Ecological"),
                            ("OT", "Other"),
                        ],
                        help_text='Select the most appropriate design from the list. If more than one study design applies (e.g., a cohort with cross-sectional analyses of baseline measures), can either a) select one design ("cohort") and clarify different timing in remaining extraction or b) select "other" and provide details in comments.',
                        max_length=2,
                    ),
                ),
                (
                    "source",
                    models.CharField(
                        choices=[
                            ("GP", "General population"),
                            ("OC", "Occupational"),
                            ("OT", "Other"),
                        ],
                        max_length=2,
                    ),
                ),
                (
                    "age_profile",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(
                            choices=[
                                ("AD", "Adults"),
                                ("CH", "Children and adolescents <18 yrs"),
                                ("PW", "Pregnant women"),
                                ("OT", "Other"),
                            ],
                            max_length=2,
                        ),
                        help_text='Select all that apply. Note: do not select "Pregnant women" if pregnant women are only included as part of a general population sample',
                        size=None,
                        verbose_name="Population age category",
                    ),
                ),
                (
                    "age_description",
                    models.CharField(
                        blank=True, max_length=128, verbose_name="Population age details"
                    ),
                ),
                (
                    "sex",
                    models.CharField(
                        choices=[
                            ("U", "Not reported"),
                            ("M", "Male"),
                            ("F", "Female"),
                            ("B", "Male and Female"),
                        ],
                        default="B",
                        max_length=1,
                    ),
                ),
                (
                    "race",
                    models.CharField(
                        blank=True, max_length=128, verbose_name="Population race/ethnicity"
                    ),
                ),
                (
                    "participant_n",
                    models.PositiveIntegerField(
                        help_text="Enter the total number of participants enrolled in the study (after exclusions). Note: Sample size for specific result can be extracted in qualitative data extraction",
                        verbose_name="Overall study population N",
                    ),
                ),
                (
                    "years_enrolled",
                    models.CharField(
                        blank=True, max_length=32, verbose_name="Year(s) of enrollment"
                    ),
                ),
                (
                    "years_followup",
                    models.CharField(
                        blank=True, max_length=32, verbose_name="Year(s) or length of follow-up"
                    ),
                ),
                (
                    "region",
                    models.CharField(
                        blank=True, max_length=128, verbose_name="Other geographic information"
                    ),
                ),
                (
                    "criteria",
                    models.TextField(blank=True, verbose_name="Inclusion/Exclusion Criteria"),
                ),
                (
                    "susceptibility",
                    models.TextField(
                        blank=True,
                        help_text="Note whether the study presents information for potentially susceptible or vulnerable populations or sub-populations, such as pregnant women or residents of environmental justice communities.",
                        verbose_name="Susceptibility",
                    ),
                ),
                ("comments", models.TextField(blank=True)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
                (
                    "countries",
                    models.ManyToManyField(
                        blank=True, related_name="epiv2_designs", to="epi.Country"
                    ),
                ),
                (
                    "study",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="designs",
                        to="study.study",
                    ),
                ),
            ],
            options={
                "verbose_name": "Study Population",
                "verbose_name_plural": "Study Populations",
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="Exposure",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="A unique name for this exposure that will help you identify it later.",
                        max_length=128,
                    ),
                ),
                (
                    "measurement_type",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(max_length=64),
                        help_text='Select the most appropriate type from the list. If a study includes multiples exposure measurement types but they are analyzed with outcomes separately, create a separate entry for each. If more than one type are combined for analysis with an outcome, you can select multiple options from the list. "Occupational" should be used when the exposure is based on job duties, etc. (i.e., not occupational exposure measured by biomarkers or air).',
                        size=None,
                        verbose_name="Exposure measurement types",
                    ),
                ),
                (
                    "biomonitoring_matrix",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("BLP", "Blood (portion: Plasma)"),
                            ("BLW", "Blood (portion: Whole blood)"),
                            ("BLS", "Blood (portion: Serum)"),
                            ("UR", "Urine"),
                            ("TE", "Teeth"),
                            ("NL", "Nails"),
                            ("HR", "Hair"),
                            ("SA", "Saliva"),
                            ("BM", "Breast milk"),
                            ("SE", "Semen"),
                            ("FC", "Feces"),
                            ("CF", "Cerebrospinal fluid"),
                            ("EB", "Exhaled breath"),
                            ("OT", "Other"),
                        ],
                        max_length=3,
                    ),
                ),
                (
                    "biomonitoring_source",
                    models.CharField(
                        blank=True,
                        choices=[
                            ("PT", "From participant"),
                            ("ML", "Maternal"),
                            ("PL", "Paternal"),
                            ("CD", "Cord"),
                        ],
                        max_length=2,
                    ),
                ),
                (
                    "measurement_timing",
                    models.CharField(
                        blank=True,
                        help_text='Enter age or other timing (e.g., start of employment, baseline). If cross-sectional, enter "cross-sectional".',
                        max_length=256,
                        verbose_name="Timing of exposure measurement",
                    ),
                ),
                (
                    "exposure_route",
                    models.CharField(
                        choices=[
                            ("IH", "Inhalation"),
                            ("OR", "Oral"),
                            ("DE", "Dermal"),
                            ("IU", "In utero"),
                            ("IV", "Intravenous"),
                            ("UK", "Unknown/Total"),
                        ],
                        default="UK",
                        help_text='Select the most appropriate route. In most cases, biomarkers will be "Unknown/Total" unless a clear exposure source is known.',
                        max_length=2,
                    ),
                ),
                (
                    "measurement_method",
                    models.TextField(
                        blank=True,
                        help_text="Briefly state the method used to measure exposure (e.g., laboratory analytic method, job exposure matrix, etc.)",
                        verbose_name="Exposure measurement method",
                    ),
                ),
                ("comments", models.TextField(blank=True)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
                (
                    "design",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="exposures",
                        to="epiv2.design",
                    ),
                ),
            ],
            options={
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="Outcome",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "system",
                    models.CharField(
                        choices=[
                            ("CA", "Cancer"),
                            ("CV", "Cardiovascular"),
                            ("DE", "Dermal"),
                            ("DV", "Developmental"),
                            ("EN", "Endocrine"),
                            ("GI", "Gastrointestinal"),
                            ("HM", "Hematologic"),
                            ("HP", "Hepatic"),
                            ("IM", "Immune"),
                            ("MT", "Metabolic"),
                            ("MS", "Multi-System"),
                            ("MU", "Musculoskeletal"),
                            ("NV", "Nervous"),
                            ("OC", "Ocular"),
                            ("RP", "Reproductive"),
                            ("RS", "Respiratory"),
                            ("UR", "Urinary"),
                            ("WB", "Whole Body"),
                            ("OT", "Other"),
                        ],
                        help_text="Select the most relevant system from the drop down menu. If more than one system is applicable refer to assessment team instructions.",
                        max_length=2,
                    ),
                ),
                (
                    "effect",
                    models.CharField(
                        help_text="The health effect of interest. Effect is generally broader than the Endpoint/Outcome and may represent multiple endpoints (e.g., Serum lipids, Asthma, Cognition). However, if there is not a finer categorization, they may be the same. Use controlled vocabulary when available.",
                        max_length=128,
                    ),
                ),
                (
                    "effect_detail",
                    models.CharField(
                        blank=True,
                        help_text="Optional. If additional specification to the Effect is needed, it can be entered here (e.g., IQ).",
                        max_length=128,
                    ),
                ),
                (
                    "endpoint",
                    models.CharField(
                        help_text="A unique name for the specific endpoint/outcome being measured. The endpoint is generally more specific than the effect (e.g., total cholesterol, incident asthma within the previous year, WISC-IV full scale). Use controlled vocabulary when available.",
                        max_length=128,
                        verbose_name="Endpoint/Outcome",
                    ),
                ),
                ("comments", models.TextField(blank=True)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
                (
                    "design",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="outcomes",
                        to="epiv2.design",
                    ),
                ),
            ],
            options={
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="ExposureLevel",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "name",
                    models.CharField(
                        help_text="A unique name for this exposure level that will help you identify it later.",
                        max_length=64,
                    ),
                ),
                (
                    "sub_population",
                    models.CharField(
                        blank=True,
                        help_text="Specify if the exposure levels are reported for a sub-group within the study population (e.g., by case or exposure status, sex, etc.)",
                        max_length=128,
                        verbose_name="Sub-population",
                    ),
                ),
                ("median", models.FloatField(blank=True, null=True)),
                ("mean", models.FloatField(blank=True, null=True)),
                ("variance", models.FloatField(blank=True, null=True)),
                (
                    "variance_type",
                    models.PositiveSmallIntegerField(
                        choices=[
                            (0, "N/A"),
                            (1, "SD"),
                            (2, "SE"),
                            (3, "SEM"),
                            (4, "GSD"),
                            (5, "IQR (interquartile range)"),
                            (6, "other"),
                        ],
                        default=0,
                        help_text="Specify which measure of variation was reported from list",
                        verbose_name="Type of variance estimate",
                    ),
                ),
                ("units", models.CharField(blank=True, max_length=128, null=True)),
                (
                    "ci_lcl",
                    hawc.apps.common.models.NumericTextField(
                        blank=True,
                        help_text="Lower value of whichever range is selected in Lower/Upper interval type. Non-numeric values can be used if necessary, but should be limited to <, ≤, ≥, >, LOD, LOQ.",
                        max_length=16,
                        verbose_name="Lower interval",
                    ),
                ),
                (
                    "percentile_25",
                    hawc.apps.common.models.NumericTextField(
                        blank=True,
                        help_text="Non-numeric values can be used if necessary, but should be limited to <, ≤, ≥, >, LOD, LOQ.",
                        max_length=16,
                        verbose_name="25th Percentile",
                    ),
                ),
                (
                    "percentile_75",
                    hawc.apps.common.models.NumericTextField(
                        blank=True,
                        help_text="Non-numeric values can be used if necessary, but should be limited to <, ≤, ≥, >, LOD, LOQ.",
                        max_length=16,
                        verbose_name="75th Percentile",
                    ),
                ),
                (
                    "ci_ucl",
                    hawc.apps.common.models.NumericTextField(
                        blank=True,
                        help_text="Upper value of whichever range is selected in Lower/Upper interval type. Non-numeric values can be used if necessary, but should be limited to <, ≤, ≥, >, LOD, LOQ.",
                        max_length=16,
                        verbose_name="Upper interval",
                    ),
                ),
                (
                    "ci_type",
                    models.CharField(
                        choices=[
                            ("NA", "N/A"),
                            ("Rng", "Range [min, max]"),
                            ("P90", "10th/90th percentile"),
                            ("P95", "5th/95th percentile"),
                            ("P99", "1st/99th percentile"),
                            ("Oth", "Other"),
                        ],
                        default="NA",
                        max_length=3,
                        verbose_name="Lower/upper interval type",
                    ),
                ),
                (
                    "negligible_exposure",
                    models.CharField(
                        blank=True,
                        help_text="Enter the percent of the population without measureable exposure. For biomarkers and other lab results, this will generally be the percent below the LOD or LOQ. Occupational studies may report the percent unexposed. The field is free text so elaboration on the meaning of the number can be provided.",
                        max_length=64,
                        verbose_name="Percent with negligible exposure",
                    ),
                ),
                (
                    "data_location",
                    models.CharField(blank=True, help_text="e.g., table number", max_length=128),
                ),
                ("comments", models.TextField(blank=True, verbose_name="Exposure level comments")),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
                (
                    "chemical",
                    models.ForeignKey(
                        help_text="Select from chemicals entered above.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="epiv2.chemical",
                    ),
                ),
                (
                    "design",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="exposure_levels",
                        to="epiv2.design",
                    ),
                ),
                (
                    "exposure_measurement",
                    models.ForeignKey(
                        help_text="Select from exposure measurement entered above.",
                        on_delete=django.db.models.deletion.CASCADE,
                        to="epiv2.exposure",
                    ),
                ),
            ],
            options={
                "ordering": ("id",),
            },
        ),
        migrations.CreateModel(
            name="DataExtraction",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "sub_population",
                    models.CharField(
                        blank=True,
                        help_text="Specify if the result is specific to a sub-group within the study population. Leave blank if the result applies to the full population.",
                        max_length=128,
                    ),
                ),
                (
                    "outcome_measurement_timing",
                    models.CharField(
                        blank=True,
                        help_text='Enter age or other timing (e.g., X years follow-up) for measurement of outcome. If cross-sectional, enter "cross-sectional".',
                        max_length=128,
                    ),
                ),
                ("effect_estimate_type", models.CharField(blank=True, max_length=128)),
                ("effect_estimate", models.FloatField()),
                ("ci_lcl", models.FloatField(blank=True, null=True, verbose_name="Lower bound")),
                ("ci_ucl", models.FloatField(blank=True, null=True, verbose_name="Upper bound")),
                (
                    "ci_type",
                    models.CharField(
                        choices=[
                            ("NA", "N/A"),
                            ("Rng", "Range [min, max]"),
                            ("P90", "10th/90th percentile"),
                            ("P95", "5th/95th percentile"),
                            ("P99", "1st/99th percentile"),
                            ("Oth", "Other"),
                        ],
                        default="P95",
                        max_length=3,
                        verbose_name="Lower/upper bound type",
                    ),
                ),
                ("units", models.CharField(blank=True, max_length=128)),
                (
                    "variance_type",
                    models.PositiveSmallIntegerField(
                        choices=[
                            (0, "N/A"),
                            (1, "SD"),
                            (2, "SE"),
                            (3, "SEM"),
                            (4, "GSD"),
                            (5, "IQR (interquartile range)"),
                            (6, "other"),
                        ],
                        default=0,
                        help_text="Specify which measure of variation was reported from list",
                        verbose_name="Type of variance estimate",
                    ),
                ),
                ("variance", models.FloatField(blank=True, null=True)),
                ("n", models.PositiveIntegerField(blank=True, null=True)),
                ("p_value", models.CharField(blank=True, max_length=8, verbose_name="p-value")),
                (
                    "significant",
                    models.PositiveSmallIntegerField(
                        choices=[(0, "No"), (1, "Yes"), (2, "N/A"), (3, "NR")],
                        default=3,
                        verbose_name="Statistically Significant",
                    ),
                ),
                (
                    "group",
                    models.CharField(
                        blank=True,
                        help_text='If a set of results are linked (e.g., results for categories of exposure), each one is entered as a separate entry in the form. This field should be used to link the results. All linked results should have the same value for this field, and it should be unique to those results. The text can be descriptive (e.g., "Quartiles for PFNA and Asthma incidence") or a dummy variable ("Group 1").',
                        max_length=128,
                        verbose_name="Results group",
                    ),
                ),
                (
                    "exposure_rank",
                    models.PositiveSmallIntegerField(
                        default=0,
                        help_text="If a set of results are linked, use this field to order them (helpful for sorting in visualizations). Rank the comparison groups in the order you would want them to appear (e.g., lowest exposure group=1).",
                    ),
                ),
                ("exposure_transform", models.CharField(blank=True, max_length=32)),
                ("outcome_transform", models.CharField(blank=True, max_length=32)),
                (
                    "confidence",
                    models.CharField(
                        blank=True,
                        help_text="Enter the overall study confidence rating for the specific endpoint being extracted",
                        max_length=128,
                        verbose_name="Study confidence",
                    ),
                ),
                (
                    "data_location",
                    models.CharField(blank=True, help_text="e.g., table number", max_length=128),
                ),
                (
                    "effect_description",
                    models.TextField(
                        blank=True,
                        help_text="Description of the effect estimate with units, including the comparison being made (e.g., beta for IQR increase, OR for Q2 vs Q1)",
                        verbose_name="Effect estimate description",
                    ),
                ),
                (
                    "statistical_method",
                    models.TextField(
                        blank=True,
                        help_text="Briefly describe the statistical analysis method (e.g., logistic regression).",
                    ),
                ),
                ("comments", models.TextField(blank=True)),
                ("created", models.DateTimeField(auto_now_add=True)),
                ("last_updated", models.DateTimeField(auto_now=True)),
                (
                    "design",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="data_extractions",
                        to="epiv2.design",
                    ),
                ),
                (
                    "exposure_level",
                    models.ForeignKey(
                        help_text="Select from exposure levels entered above",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="exposure_levels",
                        to="epiv2.exposurelevel",
                    ),
                ),
                (
                    "factors",
                    models.ForeignKey(
                        blank=True,
                        help_text="Select from adjustment sets entered above",
                        null=True,
                        on_delete=django.db.models.deletion.SET_NULL,
                        to="epiv2.adjustmentfactor",
                        verbose_name="Adjustment factors",
                    ),
                ),
                (
                    "outcome",
                    models.ForeignKey(
                        help_text="Select from endpoints entered above",
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="outcomes",
                        to="epiv2.outcome",
                    ),
                ),
            ],
            options={
                "verbose_name": "Quantitative data extraction",
                "ordering": ("id",),
            },
        ),
        migrations.AddField(
            model_name="chemical",
            name="design",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="chemicals",
                to="epiv2.design",
            ),
        ),
        migrations.AddField(
            model_name="chemical",
            name="dsstox",
            field=models.ForeignKey(
                blank=True,
                help_text='<a rel="noopener noreferrer" target="_blank" href="https://www.epa.gov/chemical-research/distributed-structure-searchable-toxicity-dsstox-database">DssTox</a> substance identifier (recommended). When using an identifier, chemical name and CASRN are standardized using the <a href="https://comptox.epa.gov/dashboard/" rel="noopener noreferrer" target="_blank">DTXSID</a>.',
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                to="assessment.dsstox",
                verbose_name="DSSTox substance identifier",
            ),
        ),
        migrations.AddField(
            model_name="adjustmentfactor",
            name="design",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="adjustment_factors",
                to="epiv2.design",
            ),
        ),
    ]
