Skip to content

Commit

Permalink
Merge pull request #2065 from coronasafe/staging
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg authored Apr 8, 2024
2 parents a69ff22 + f014b3f commit 101043b
Show file tree
Hide file tree
Showing 30 changed files with 358 additions and 139 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Create Release on Branch Push

on:
push:
branches:
- production

permissions:
contents: write

jobs:
release:
name: Release on Push
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Necessary to fetch all tags

- name: Calculate next tag
id: calc_tag
run: |
YEAR=$(date +"%y")
WEEK=$(date +"%V")
LAST_TAG=$(git tag -l "v$YEAR.$WEEK.*" | sort -V | tail -n1)
LAST_TAG=$(echo "$LAST_TAG" | tr -d '\r' | sed 's/[[:space:]]*$//')
echo "Last Tag: $LAST_TAG"
if [[ $LAST_TAG == "" ]]; then
MINOR=0
else
MINOR=$(echo $LAST_TAG | awk -F '.' '{print $NF}')
echo "Minor Version: $MINOR"
MINOR=$((MINOR + 1))
fi
TAG="v$YEAR.$WEEK.$MINOR"
echo "TAG=$TAG" >> $GITHUB_ENV
echo "Next Tag: $TAG"
- name: Configure git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Create and push tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "$TAG" \
--repo="$GITHUB_REPOSITORY" \
--title="$TAG" \
--generate-notes \
--draft
4 changes: 2 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "pypi"
[packages]
argon2-cffi = "==23.1.0"
authlib = "==1.2.1"
boto3 = "==1.34.65"
boto3 = "==1.34.75"
celery = "==5.3.6"
django = "==4.2.10"
django-environ = "==0.11.2"
Expand Down Expand Up @@ -48,7 +48,7 @@ redis-om = "==0.2.1"

[dev-packages]
black = "==23.9.1"
boto3-stubs = {extras = ["s3", "boto3"], version = "==1.34.65"}
boto3-stubs = {extras = ["s3", "boto3"], version = "==1.34.75"}
coverage = "==7.4.0"
debugpy = "==1.8.1"
django-coverage-plugin = "==3.1.0"
Expand Down
29 changes: 15 additions & 14 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion care/facility/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class AmbulanceDriverAdmin(DjangoQLSearchMixin, admin.ModelAdmin):


class PatientAdmin(DjangoQLSearchMixin, admin.ModelAdmin):
list_display = ("id", "name", "age", "gender")
list_display = ("id", "name", "year_of_birth", "gender")
djangoql_completion_enabled_by_default = True


Expand Down
31 changes: 18 additions & 13 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,12 @@ class Meta:
"created_by",
"deleted",
"ongoing_medication",
"year_of_birth",
"meta_info",
"countries_travelled_old",
"allergies",
"external_id",
)
read_only = TIMESTAMP_FIELDS
read_only = TIMESTAMP_FIELDS + ("death_datetime",)


class PatientContactDetailsSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -223,12 +222,16 @@ class Meta:
model = PatientRegistration
exclude = (
"deleted",
"year_of_birth",
"countries_travelled_old",
"external_id",
)
include = ("contacted_patients",)
read_only = TIMESTAMP_FIELDS + ("last_edited", "created_by", "is_active")
read_only = TIMESTAMP_FIELDS + (
"last_edited",
"created_by",
"is_active",
"death_datetime",
)

# def get_last_consultation(self, obj):
# last_consultation = PatientConsultation.objects.filter(patient=obj).last()
Expand All @@ -250,13 +253,15 @@ def validate_countries_travelled(self, value):

def validate(self, attrs):
validated = super().validate(attrs)
if (
not self.partial
and not validated.get("age")
and not validated.get("date_of_birth")
if not self.partial and not (
validated.get("year_of_birth") or validated.get("date_of_birth")
):
raise serializers.ValidationError(
{"non_field_errors": ["Either age or date_of_birth should be passed"]}
{
"non_field_errors": [
"Either year_of_birth or date_of_birth should be passed"
]
}
)

if validated.get("is_vaccinated"):
Expand Down Expand Up @@ -447,11 +452,11 @@ class PatientTransferSerializer(serializers.ModelSerializer):

class Meta:
model = PatientRegistration
fields = ("facility", "date_of_birth", "patient", "facility_object")
fields = ("facility", "year_of_birth", "patient", "facility_object")

def validate_date_of_birth(self, value):
if self.instance and self.instance.date_of_birth != value:
raise serializers.ValidationError("Date of birth does not match")
def validate_year_of_birth(self, value):
if self.instance and self.instance.year_of_birth != value:
raise serializers.ValidationError("Year of birth does not match")
return value

def create(self, validated_data):
Expand Down
87 changes: 67 additions & 20 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@
from django.conf import settings
from django.contrib.postgres.search import TrigramSimilarity
from django.db import models
from django.db.models import Case, OuterRef, Q, Subquery, When
from django.db.models import (
Case,
ExpressionWrapper,
F,
Func,
OuterRef,
Q,
Subquery,
Value,
When,
)
from django.db.models.functions import Coalesce, ExtractDay, Now
from django.db.models.query import QuerySet
from django_filters import rest_framework as filters
from djqscsv import render_to_csv_response
Expand Down Expand Up @@ -333,25 +344,61 @@ class PatientViewSet(
]
permission_classes = (IsAuthenticated, DRYPermissions)
lookup_field = "external_id"
queryset = PatientRegistration.objects.all().select_related(
"local_body",
"district",
"state",
"ward",
"assigned_to",
"facility",
"facility__ward",
"facility__local_body",
"facility__district",
"facility__state",
# "nearest_facility",
# "nearest_facility__local_body",
# "nearest_facility__district",
# "nearest_facility__state",
"last_consultation",
"last_consultation__assigned_to",
"last_edited",
"created_by",
queryset = (
PatientRegistration.objects.all()
.select_related(
"local_body",
"district",
"state",
"ward",
"assigned_to",
"facility",
"facility__ward",
"facility__local_body",
"facility__district",
"facility__state",
# "nearest_facility",
# "nearest_facility__local_body",
# "nearest_facility__district",
# "nearest_facility__state",
"last_consultation",
"last_consultation__assigned_to",
"last_edited",
"created_by",
)
.annotate(
coalesced_dob=Coalesce(
"date_of_birth",
Func(
F("year_of_birth"),
Value(1),
Value(1),
function="MAKE_DATE",
output_field=models.DateField(),
),
output_field=models.DateField(),
),
age_end=Case(
When(death_datetime__isnull=True, then=Now()),
default=F("death_datetime__date"),
),
)
.annotate(
age=Func(
Value("year"),
Func(
F("age_end"),
F("coalesced_dob"),
function="age",
),
function="date_part",
output_field=models.IntegerField(),
),
age_days=ExpressionWrapper(
ExtractDay(F("age_end") - F("coalesced_dob")),
output_field=models.IntegerField(),
),
)
)
ordering_fields = [
"facility__name",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.10 on 2024-03-22 11:21

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("facility", "0421_merge_20240318_1434"),
]

operations = [
migrations.AlterField(
model_name="facilityinventorylog",
name="quantity",
field=models.FloatField(
default=0, validators=[django.core.validators.MinValueValidator(0.0)]
),
),
migrations.AlterField(
model_name="facilityinventoryminquantity",
name="min_quantity",
field=models.FloatField(
default=0, validators=[django.core.validators.MinValueValidator(0.0)]
),
),
]
Loading

0 comments on commit 101043b

Please sign in to comment.