-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
made patient notes consultation specific (#1727)
* made patient notes consultation specific * link existing patient notes to consultations * update migrations --------- Co-authored-by: Bhavik Agarwal <[email protected]>
- Loading branch information
Showing
7 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
care/facility/migrations/0398_patientnotes_consultation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.2.6 on 2023-10-18 12:18 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0397_truncate_discharge_time"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="patientnotes", | ||
name="consultation", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="facility.patientconsultation", | ||
), | ||
), | ||
] |
37 changes: 37 additions & 0 deletions
37
care/facility/migrations/0399_populate_patientnotes_consultation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 4.2.7 on 2023-11-23 12:42 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def link_patient_notes_to_consultation(apps, schema_editor): | ||
PatientConsultation = apps.get_model("facility", "PatientConsultation") | ||
PatientNotes = apps.get_model("facility", "PatientNotes") | ||
|
||
consultations = PatientConsultation.objects.order_by("created_date").filter( | ||
patient__in=models.Subquery(PatientNotes.objects.values("patient_id")) | ||
) | ||
|
||
for consultation in consultations: | ||
notes = PatientNotes.objects.order_by("created_date").filter( | ||
patient_id=consultation.patient_id, | ||
created_date__gte=consultation.created_date, | ||
) | ||
if consultation.discharge_reason: | ||
notes = notes.filter( | ||
created_date__lte=consultation.modified_date, | ||
) | ||
|
||
notes.update(consultation=consultation) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("facility", "0398_patientnotes_consultation"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
code=link_patient_notes_to_consultation, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters