-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(patient notes): add edit window validation and update endpoint (#…
…1221) * feat(patient notes): add edit window validation and update endpoint - Add edit window validation to restrict updates to notes after a certain time - Add PUT and PATCH endpoints to update notes * Use editable_until logic * dummy empty commit * Merge migrations * format files * Merge migrations * fix tests * remove editable_until * bug fixes * Move update validation to viewset * Fix tests * Remove PATIENT_NOTE_EDIT_WINDOW * fix lint * edit history for patient notes * Fix tests * Create initial edit record for existing notes * optimize migration Signed-off-by: Aakash Singh <mail@singhaakash.dev> * Update care/facility/models/mixins/permissions/patient.py Co-authored-by: Aakash Singh <mail@singhaakash.dev> * Update migrations * update migrations * Update care/facility/api/serializers/patient.py Co-authored-by: Aakash Singh <mail@singhaakash.dev> * Update care/facility/models/patient.py Co-authored-by: Aakash Singh <mail@singhaakash.dev> * Update care/facility/migrations/0405_patientnotesedit.py * Update care/facility/migrations/0405_patientnotesedit.py * edited_date * Update care/facility/migrations/0405_patientnotesedit.py * Update care/facility/models/patient.py * Apply suggestions from code review * Fix N+1, update migrations, seperate endpoint for edits * Update migrations * Fix tests --------- Signed-off-by: Aakash Singh <mail@singhaakash.dev> Co-authored-by: Aakash Singh <mail@singhaakash.dev>
- Loading branch information
Showing
6 changed files
with
297 additions
and
9 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
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,76 @@ | ||
# Generated by Django 4.2.2 on 2023-08-28 14:09 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.core.paginator import Paginator | ||
from django.db import migrations, models | ||
|
||
|
||
def create_initial_patient_notes_edit_record(apps, schema_editor): | ||
PatientNotes = apps.get_model("facility", "PatientNotes") | ||
PatientNotesEdit = apps.get_model("facility", "PatientNotesEdit") | ||
|
||
notes_without_edits = PatientNotes.objects.all() | ||
|
||
paginator = Paginator(notes_without_edits, 1000) | ||
for page_number in paginator.page_range: | ||
edit_records = [] | ||
for patient_note in paginator.page(page_number).object_list: | ||
edit_record = PatientNotesEdit( | ||
patient_note=patient_note, | ||
edited_date=patient_note.created_date, | ||
edited_by=patient_note.created_by, | ||
note=patient_note.note, | ||
) | ||
|
||
edit_records.append(edit_record) | ||
|
||
PatientNotesEdit.objects.bulk_create(edit_records) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("facility", "0407_alter_dailyround_additional_symptoms_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="PatientNotesEdit", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("edited_date", models.DateTimeField(auto_now_add=True)), | ||
("note", models.TextField()), | ||
( | ||
"edited_by", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"patient_note", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="edits", | ||
to="facility.patientnotes", | ||
), | ||
), | ||
], | ||
options={ | ||
"ordering": ["-edited_date"], | ||
}, | ||
), | ||
migrations.RunPython( | ||
code=create_initial_patient_notes_edit_record, | ||
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
Oops, something went wrong.