Skip to content
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

Closed
wants to merge 2 commits into from
Closed

Added is_occupied field in Bed #1093

wants to merge 2 commits into from

Conversation

khavinshankar
Copy link
Member

Proposed Changes

  • added is_occupied field in Bed
  • update is_occupied field when consultation bed is created (switch bed), patient consultation is created, and when the patient is discharged

Associated Issue

Architecture changes

  • nil

@coronasafe/code-reviewers

Merge Checklist

  • Tests added/fixed
  • Update docs in /docs
  • Linting Complete

@khavinshankar khavinshankar requested a review from a team as a code owner November 8, 2022 05:21
@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2022

Codecov Report

Base: 55.98% // Head: 55.95% // Decreases project coverage by -0.02% ⚠️

Coverage data is based on head (8e7fbf5) compared to base (eb52c8a).
Patch coverage: 28.57% of modified lines in pull request are covered.

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              
Impacted Files Coverage Δ
care/facility/api/serializers/bed.py 41.02% <0.00%> (-0.72%) ⬇️
...e/facility/api/serializers/patient_consultation.py 32.96% <0.00%> (-0.19%) ⬇️
care/facility/api/viewsets/patient.py 47.91% <33.33%> (-0.34%) ⬇️
care/facility/models/bed.py 83.78% <100.00%> (+1.73%) ⬆️
care/users/api/viewsets/change_password.py 61.53% <0.00%> (+1.53%) ⬆️

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.
📢 Do you have feedback about the report comment? Let us know in this issue.

@sonarcloud
Copy link

sonarcloud bot commented Nov 10, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vigneshhari
Copy link
Member

@rithviknishad @sainak review.

@vigneshhari vigneshhari requested review from rithviknishad and sainak and removed request for a team August 8, 2023 18:44
@@ -179,10 +179,18 @@ def create(self, validated_data):
if occupied_beds.filter(bed=bed).exists():
Copy link
Member

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?

Comment on lines +14 to +19
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()
Copy link
Member

@rithviknishad rithviknishad Aug 8, 2023

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?

Suggested change
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"))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or even:

Suggested change
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(
Copy link
Member

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

Comment on lines +13 to +19
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create is_occupied property in Bed model
5 participants