-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added is_occupied field in Bed #1093
Conversation
Codecov ReportBase: 55.98% // Head: 55.95% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #1093 +/- ##
==========================================
- Coverage 55.98% 55.95% -0.03%
==========================================
Files 175 175
Lines 8685 8689 +4
Branches 1468 1484 +16
==========================================
Hits 4862 4862
- Misses 3771 3775 +4
Partials 52 52
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Kudos, SonarCloud Quality Gate passed!
|
@rithviknishad @sainak review. |
@@ -179,10 +179,18 @@ def create(self, validated_data): | |||
if occupied_beds.filter(bed=bed).exists(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be updated to simply check using bed.is_occupied
instead now right?
ConsultationBed = apps.get_model("facility", "ConsultationBed") | ||
for bed in Bed.objects.all(): | ||
bed.is_occupied = ConsultationBed.objects.filter( | ||
bed=bed, end_date__isnull=True | ||
).exists() | ||
bed.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could optimize the custom migration like this right?
ConsultationBed = apps.get_model("facility", "ConsultationBed") | |
for bed in Bed.objects.all(): | |
bed.is_occupied = ConsultationBed.objects.filter( | |
bed=bed, end_date__isnull=True | |
).exists() | |
bed.save() | |
Bed.objects.all().update(is_occupied=F("consultationbed__end_date__isnull")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or even:
ConsultationBed = apps.get_model("facility", "ConsultationBed") | |
for bed in Bed.objects.all(): | |
bed.is_occupied = ConsultationBed.objects.filter( | |
bed=bed, end_date__isnull=True | |
).exists() | |
bed.save() | |
Bed.objects.filter(consultationbed__end_date__isnull=True).update(is_occupied=True) |
@@ -179,10 +179,18 @@ def create(self, validated_data): | |||
if occupied_beds.filter(bed=bed).exists(): | |||
raise ValidationError({"bed:": ["Bed already in use by patient"]}) | |||
|
|||
Bed.objects.filter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that we have the value directly stored in the model we can directly get the object and check/update the status
Bed = apps.get_model("facility", "Bed") | ||
ConsultationBed = apps.get_model("facility", "ConsultationBed") | ||
for bed in Bed.objects.all(): | ||
bed.is_occupied = ConsultationBed.objects.filter( | ||
bed=bed, end_date__isnull=True | ||
).exists() | ||
bed.save() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bed = apps.get_model("facility", "Bed") | |
ConsultationBed = apps.get_model("facility", "ConsultationBed") | |
for bed in Bed.objects.all(): | |
bed.is_occupied = ConsultationBed.objects.filter( | |
bed=bed, end_date__isnull=True | |
).exists() | |
bed.save() | |
Bed = apps.get_model("facility", "Bed") | |
ConsultationBed = apps.get_model("facility", "ConsultationBed") | |
objs = [] | |
for consultation_bed in ConsultationBed.objects.filter(end_date__isnull=True).select_related("bed"): | |
consultation_bed.bed.is_occupied=True | |
objs.append(consultation_bed.bed) | |
Bed.objects.bulk_update(objs, ['is_occupied']) | |
Proposed Changes
Associated Issue
is_occupied
property in Bed model #1084Architecture changes
@coronasafe/code-reviewers
Merge Checklist
/docs