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

Production Release | Dec Week 1 #1745

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ def operate_assets(self, request, *args, **kwargs):
middleware_hostname = (
asset.meta.get(
"middleware_hostname",
asset.current_location.middleware_address,
)
or asset.current_location.middleware_address
or asset.current_location.facility.middleware_address
)
asset_class: BaseAssetIntegration = AssetClasses[asset.asset_class].value(
Expand Down
1 change: 1 addition & 0 deletions care/facility/api/viewsets/daily_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

class DailyRoundFilterSet(filters.FilterSet):
rounds_type = filters.CharFilter(method="filter_rounds_type")
taken_at = filters.DateTimeFromToRangeFilter()

def filter_rounds_type(self, queryset, name, value):
rounds_type = set()
Expand Down
59 changes: 59 additions & 0 deletions care/facility/migrations/0397_truncate_discharge_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generated by Django 4.2.5 on 2023-11-30 11:58

import datetime

from django.db import migrations
from django.db.models import DateTimeField, ExpressionWrapper, F
from django.db.models.functions import TruncDay
from django.utils import timezone


class Migration(migrations.Migration):
dependencies = [
("facility", "0396_merge_20231122_0240"),
]

def clean_discharge_date(apps, schema_editor):
"""
Clean discharge_date field to be 00:00:00 IST

For example:

`2023-10-06 06:00:00 +05:30 IST` (`2023-10-06 00:30:00 +00:00 UTC`) would be updated to
`2023-10-06 00:00:00 +05:30 IST` (`2023-10-05 18:30:00 +00:00 UTC`)

Equivalent to the following SQL:

```sql
UPDATE facility_patientconsultation
SET discharge_date =
timezone('IST', discharge_date) AT TIME ZONE 'UTC' +
(date_trunc('day', timezone('IST', discharge_date)) - timezone('IST', discharge_date)) +
(interval '-5 hours -30 minutes')
WHERE discharge_date IS NOT NULL;
```
"""

current_timezone = timezone.get_current_timezone()
tz_offset = timezone.timedelta(
minutes=current_timezone.utcoffset(datetime.datetime.utcnow()).seconds / 60
)

PatientConsultation = apps.get_model("facility", "PatientConsultation")
PatientConsultation.objects.filter(discharge_date__isnull=False).exclude(
admission_date__isnull=False, discharge_date__lt=F("admission_date")
).update(
discharge_date=ExpressionWrapper(
# Convert the discharge_date to UTC by subtracting the current offset
F("discharge_date") - tz_offset +
# Get the day part of the discharge_date and subtract the actual discharge_date from it
(TruncDay(F("discharge_date")) - F("discharge_date")),
output_field=DateTimeField(),
)
)

operations = [
migrations.RunPython(
clean_discharge_date, reverse_code=migrations.RunPython.noop
),
]
2 changes: 1 addition & 1 deletion care/facility/tasks/asset_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def check_asset_status():
hostname = (
asset.meta.get(
"middleware_hostname",
asset.current_location.middleware_address,
)
or asset.current_location.middleware_address
or asset.current_location.facility.middleware_address
)
if not hostname:
Expand Down
Loading