From a0d0299dfa6ca1878ba7bc05a452815cdeab0719 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:29:51 +0530 Subject: [PATCH 1/4] Add assigned_clinicians field to PatientConsultation model --- ...patientconsultation_assigned_clinicians.py | 21 +++++++++++++++++++ care/facility/models/patient_consultation.py | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 care/facility/migrations/0415_patientconsultation_assigned_clinicians.py diff --git a/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py b/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py new file mode 100644 index 0000000000..3ea1661228 --- /dev/null +++ b/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py @@ -0,0 +1,21 @@ +# Generated by Django 4.2.8 on 2024-02-20 06:57 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("facility", "0414_remove_bed_old_name"), + ] + + operations = [ + migrations.AddField( + model_name="patientconsultation", + name="assigned_clinicians", + field=models.ManyToManyField( + related_name="patient_assigned_clinician", to=settings.AUTH_USER_MODEL + ), + ), + ] diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index a16c08e2ae..c37622196f 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -168,6 +168,10 @@ class PatientConsultation(PatientBaseModel, ConsultationRelatedPermissionMixin): related_name="patient_assigned_to", ) + assigned_clinicians = models.ManyToManyField( + User, related_name="patient_assigned_clinician" + ) + medico_legal_case = models.BooleanField(default=False) deprecated_verified_by = models.TextField( From 50a879f32a8c8de657c6adbac02226c8974aad5f Mon Sep 17 00:00:00 2001 From: Ashesh <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 20 Feb 2024 12:36:55 +0530 Subject: [PATCH 2/4] Make related_name more intuitive Co-authored-by: Aakash Singh --- care/facility/models/patient_consultation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index c37622196f..b30b58ca72 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -169,7 +169,7 @@ class PatientConsultation(PatientBaseModel, ConsultationRelatedPermissionMixin): ) assigned_clinicians = models.ManyToManyField( - User, related_name="patient_assigned_clinician" + User, related_name="assigned_patients" ) medico_legal_case = models.BooleanField(default=False) From a7d939b8694aa0ffb61c356d6e0cd31cab0b7d37 Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Tue, 20 Feb 2024 18:57:51 +0530 Subject: [PATCH 3/4] Fix lint and migration --- .../0415_patientconsultation_assigned_clinicians.py | 2 +- care/facility/models/patient_consultation.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py b/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py index 3ea1661228..6bb3574f7c 100644 --- a/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py +++ b/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): model_name="patientconsultation", name="assigned_clinicians", field=models.ManyToManyField( - related_name="patient_assigned_clinician", to=settings.AUTH_USER_MODEL + related_name="assigned_patients", to=settings.AUTH_USER_MODEL ), ), ] diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index b30b58ca72..e2a4fcb39a 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -168,9 +168,7 @@ class PatientConsultation(PatientBaseModel, ConsultationRelatedPermissionMixin): related_name="patient_assigned_to", ) - assigned_clinicians = models.ManyToManyField( - User, related_name="assigned_patients" - ) + assigned_clinicians = models.ManyToManyField(User, related_name="assigned_patients") medico_legal_case = models.BooleanField(default=False) From 0c7300ebd9dca2c6ba3c8bad118cec9600387beb Mon Sep 17 00:00:00 2001 From: Ashesh3 <3626859+Ashesh3@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:09:18 +0530 Subject: [PATCH 4/4] use a through model --- .../0415_consultationclinician_and_more.py | 52 +++++++++++++++++++ ...patientconsultation_assigned_clinicians.py | 21 -------- care/facility/models/patient_consultation.py | 17 +++++- 3 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 care/facility/migrations/0415_consultationclinician_and_more.py delete mode 100644 care/facility/migrations/0415_patientconsultation_assigned_clinicians.py diff --git a/care/facility/migrations/0415_consultationclinician_and_more.py b/care/facility/migrations/0415_consultationclinician_and_more.py new file mode 100644 index 0000000000..0165cef66b --- /dev/null +++ b/care/facility/migrations/0415_consultationclinician_and_more.py @@ -0,0 +1,52 @@ +# Generated by Django 4.2.8 on 2024-02-23 06:38 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("facility", "0414_remove_bed_old_name"), + ] + + operations = [ + migrations.CreateModel( + name="ConsultationClinician", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ( + "clinician", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "consultation", + models.ForeignKey( + on_delete=django.db.models.deletion.PROTECT, + to="facility.patientconsultation", + ), + ), + ], + ), + migrations.AddField( + model_name="patientconsultation", + name="assigned_clinicians", + field=models.ManyToManyField( + related_name="patient_assigned_clinician", + through="facility.ConsultationClinician", + to=settings.AUTH_USER_MODEL, + ), + ), + ] diff --git a/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py b/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py deleted file mode 100644 index 6bb3574f7c..0000000000 --- a/care/facility/migrations/0415_patientconsultation_assigned_clinicians.py +++ /dev/null @@ -1,21 +0,0 @@ -# Generated by Django 4.2.8 on 2024-02-20 06:57 - -from django.conf import settings -from django.db import migrations, models - - -class Migration(migrations.Migration): - dependencies = [ - migrations.swappable_dependency(settings.AUTH_USER_MODEL), - ("facility", "0414_remove_bed_old_name"), - ] - - operations = [ - migrations.AddField( - model_name="patientconsultation", - name="assigned_clinicians", - field=models.ManyToManyField( - related_name="assigned_patients", to=settings.AUTH_USER_MODEL - ), - ), - ] diff --git a/care/facility/models/patient_consultation.py b/care/facility/models/patient_consultation.py index e2a4fcb39a..8f1400d9ff 100644 --- a/care/facility/models/patient_consultation.py +++ b/care/facility/models/patient_consultation.py @@ -168,7 +168,11 @@ class PatientConsultation(PatientBaseModel, ConsultationRelatedPermissionMixin): related_name="patient_assigned_to", ) - assigned_clinicians = models.ManyToManyField(User, related_name="assigned_patients") + assigned_clinicians = models.ManyToManyField( + User, + related_name="patient_assigned_clinician", + through="ConsultationClinician", + ) medico_legal_case = models.BooleanField(default=False) @@ -340,3 +344,14 @@ def has_object_email_discharge_summary_permission(self, request): def has_object_generate_discharge_summary_permission(self, request): return self.has_object_read_permission(request) + + +class ConsultationClinician(models.Model): + consultation = models.ForeignKey( + PatientConsultation, + on_delete=models.PROTECT, + ) + clinician = models.ForeignKey( + User, + on_delete=models.PROTECT, + )