# Generated by Django 3.0.9 on 2020-08-26 22:28

from django.db import migrations
from edc_visit_schedule import site_visit_schedules

from inte_consent.models.signals import get_onschedule_model_name


def refresh_appointments(apps, schema_editor):
    consent_model_cls = apps.get_model("inte_consent.subjectconsent")
    for instance in consent_model_cls._default_manager.all():
        _, schedule = site_visit_schedules.get_by_onschedule_model(
            get_onschedule_model_name(instance)
        )
        schedule.refresh_schedule(subject_identifier=instance.subject_identifier)


class Migration(migrations.Migration):

    dependencies = [
        ("inte_consent", "0004_auto_20200714_1654"),
        ("inte_subject", "0043_auto_20200826_2148"),
    ]

    operations = [migrations.RunPython(refresh_appointments)]
