# Generated by Django 5.0.8 on 2024-08-22 21:12

import django_db_views.migration_functions
import django_db_views.operations
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ("meta_reports", "0032_alter_endpointsproxy_options"),
    ]

    operations = [
        django_db_views.operations.ViewRunPython(
            code=django_db_views.migration_functions.ForwardViewMigration(
                '# noqa\nselect *, uuid() as id, now() as created, \'meta_reports.glucose_summary_view\' as report_model\nfrom (\n    select v.subject_identifier, fbg_value, fbg_datetime, null as \'ogtt_value\', null as \'ogtt_datetime\',\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as \'fasted\',\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id, eos.offstudy_datetime\n    from meta_subject_glucosefbg as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    left join meta_prn_endofstudy as eos on v.subject_identifier=eos.subject_identifier\n    UNION\n    select v.subject_identifier, fbg_value, fbg_datetime, ogtt_value, ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as \'fasted\',\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id, eos.offstudy_datetime\n    from meta_subject_glucose as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    left join meta_prn_endofstudy as eos on v.subject_identifier=eos.subject_identifier\n) as A\norder by subject_identifier, fbg_datetime',
                "glucose_summary_view",
                engine="django.db.backends.mysql",
            ),
            reverse_code=django_db_views.migration_functions.BackwardViewMigration(
                '# noqa\nselect *, uuid() as id, now() as created, \'meta_reports.glucose_summary_view\' as report_model\nfrom (\n    select subject_identifier, fbg_value, fbg_datetime, null as \'ogtt_value\', null as \'ogtt_datetime\',\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as \'fasted\',\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id\n    from meta_subject_glucosefbg as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    UNION\n    select subject_identifier, fbg_value, fbg_datetime, ogtt_value, ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as \'fasted\',\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id\n    from meta_subject_glucose as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id) as A\norder by subject_identifier, fbg_datetime',
                "glucose_summary_view",
                engine="django.db.backends.mysql",
            ),
            atomic=False,
        ),
        django_db_views.operations.ViewRunPython(
            code=django_db_views.migration_functions.ForwardViewMigration(
                '# noqa\nselect *, get_random_uuid() as id, now() as created, \'meta_reports.glucose_summary_view\' as report_model\nfrom (\n    select v.subject_identifier, fbg_value, fbg_datetime, null as ogtt_value, null as ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id, eos.offstudy_datetime\n    from meta_subject_glucosefbg as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    left join meta_prn_endofstudy as eos on v.subject_identifier=eos.subject_identifier\n    UNION\n    select v.subject_identifier, fbg_value, fbg_datetime, ogtt_value, ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id, eos.offstudy_datetime\n    from meta_subject_glucose as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    left join meta_prn_endofstudy as eos on v.subject_identifier=eos.subject_identifier\n) as A\norder by subject_identifier, fbg_datetime',
                "glucose_summary_view",
                engine="django.db.backends.postgresql",
            ),
            reverse_code=django_db_views.migration_functions.BackwardViewMigration(
                '# noqa\nselect *, get_random_uuid() as id, now() as created, \'meta_reports.glucose_summary_view\' as report_model\nfrom (\n    select subject_identifier, fbg_value, fbg_datetime, null as ogtt_value, null as ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id\n    from meta_subject_glucosefbg as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    UNION\n    select subject_identifier, fbg_value, fbg_datetime, ogtt_value, ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id\n    from meta_subject_glucose as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id) as A\norder by subject_identifier, fbg_datetime',
                "glucose_summary_view",
                engine="django.db.backends.postgresql",
            ),
            atomic=False,
        ),
        django_db_views.operations.ViewRunPython(
            code=django_db_views.migration_functions.ForwardViewMigration(
                '# noqa\nSELECT *, lower(\n    hex(randomblob(4)) || \'-\' || hex(randomblob(2)) || \'-\' || \'4\' ||\n    substr(hex( randomblob(2)), 2) || \'-\' ||\n    substr(\'AB89\', 1 + (abs(random()) % 4) , 1)  ||\n    substr(hex(randomblob(2)), 2) || \'-\' ||\n    hex(randomblob(6))\n  ) as id, datetime() as `created`, \'meta_reports.glucose_summary_view\' as report_model\nfrom (\n    select v.subject_identifier, fbg_value, fbg_datetime, null as ogtt_value, null as ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id, eos.offstudy_datetime\n    from meta_subject_glucosefbg as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    left join meta_prn_endofstudy as eos on v.subject_identifier=eos.subject_identifier\n    UNION\n    select v.subject_identifier, fbg_value, fbg_datetime, ogtt_value, ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id, eos.offstudy_datetime\n    from meta_subject_glucose as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    left join meta_prn_endofstudy as eos on v.subject_identifier=eos.subject_identifier    \n    ) as A\norder by subject_identifier, fbg_datetime',
                "glucose_summary_view",
                engine="django.db.backends.sqlite3",
            ),
            reverse_code=django_db_views.migration_functions.BackwardViewMigration(
                '# noqa\nSELECT *, lower(\n    hex(randomblob(4)) || \'-\' || hex(randomblob(2)) || \'-\' || \'4\' ||\n    substr(hex( randomblob(2)), 2) || \'-\' ||\n    substr(\'AB89\', 1 + (abs(random()) % 4) , 1)  ||\n    substr(hex(randomblob(2)), 2) || \'-\' ||\n    hex(randomblob(6))\n  ) as id, datetime() as `created`, \'meta_reports.glucose_summary_view\' as report_model\nfrom (\n    select subject_identifier, fbg_value, fbg_datetime, null as ogtt_value, null as ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id\n    from meta_subject_glucosefbg as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id\n    UNION\n    select subject_identifier, fbg_value, fbg_datetime, ogtt_value, ogtt_datetime,\n    case when fasting="fasting" then "Yes" when fasting="non_fasting" then "No" else fasting end as fasted,\n    fbg.site_id, v.visit_code, v.visit_code_sequence, v.appointment_id\n    from meta_subject_glucose as fbg\n    left join meta_subject_subjectvisit as v on v.id=fbg.subject_visit_id) as A\norder by subject_identifier, fbg_datetime',
                "glucose_summary_view",
                engine="django.db.backends.sqlite3",
            ),
            atomic=False,
        ),
    ]
