# Generated by Django 2.2.11 on 2023-05-24 13:23

from django.db import migrations


class Migration(migrations.Migration):
    def free_non_admission_beds(apps, schema_editor):
        PatientConsultation = apps.get_model("facility", "PatientConsultation")
        ConsultationBed = apps.get_model("facility", "ConsultationBed")

        for consultation in PatientConsultation.objects.exclude(suggestion="A"):
            ConsultationBed.objects.filter(
                consultation=consultation, end_date__isnull=True
            ).update(end_date=consultation.discharge_date, deleted=True)

    dependencies = [
        ("facility", "0357_auto_20230523_1304"),
    ]

    operations = [
        migrations.RunPython(free_non_admission_beds),
    ]
