# Generated by Django 2.1.7 on 2019-05-25 14:35

from django.db import migrations, OperationalError


def save_icds(apps, schema_editor):
    Visit = apps.get_model('visit', 'Visit')
    IcdToVisit = apps.get_model('visit', 'IcdToVisit')
    try:
        visits = Visit.objects.filter(icd_codes__isnull=False)
        visits.count()
    except:
        return
    for visit in visits:
        for icd in visit.icd_codes.all():
            IcdToVisit.objects.create(icd=icd, visit=visit)


class Migration(migrations.Migration):

    dependencies = [
        ('visit', '0014_auto_20190525_1434'),
    ]

    operations = [
        migrations.RunPython(save_icds, migrations.RunPython.noop)
    ]
