Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into abdm
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Jul 19, 2023
2 parents 87f06b0 + 9f84bd4 commit c7555f1
Show file tree
Hide file tree
Showing 53 changed files with 1,145,743 additions and 76 deletions.
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,14 @@
"django": true,
"justMyCode": false
},
{
"name": "Python: Django test",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": ["test", "--keepdb"],
"django": true,
"justMyCode": false
},
]
}
4 changes: 2 additions & 2 deletions aws/backend.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
{
"name": "DJANGO_ALLOWED_HOSTS",
"value": "[\"http://care-django-staging\", \"https://care.coronasafe.in\", \"https://careapi.coronasafe.in\", \"https://care.ohc.network\", \"https://careapi.ohc.network\"]"
"value": "[\"care-django-staging\", \"care.coronasafe.in\", \"careapi.coronasafe.in\", \"care.ohc.network\", \"careapi.ohc.network\"]"
},
{
"name": "DJANGO_SECURE_SSL_REDIRECT",
Expand Down Expand Up @@ -227,7 +227,7 @@
"name": "care-backend"
}
],
"memory": "512",
"memory": "1024",
"taskRoleArn": "arn:aws:iam::299650323339:role/ecsTaskExecutionRole",
"family": "care",
"requiresCompatibilities": [
Expand Down
14 changes: 7 additions & 7 deletions aws/celery.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
{
"name": "DJANGO_ALLOWED_HOSTS",
"value": "[\"http://care-django-staging\", \"https://care.coronasafe.in\", \"https://careapi.coronasafe.in\", \"https://care.ohc.network\", \"https://careapi.ohc.network\"]"
"value": "[\"care-django-staging\", \"care.coronasafe.in\", \"careapi.coronasafe.in\", \"care.ohc.network\", \"careapi.ohc.network\"]"
},
{
"name": "DJANGO_SECURE_SSL_REDIRECT",
Expand Down Expand Up @@ -96,8 +96,8 @@
"repositoryCredentials": {
"credentialsParameter": "arn:aws:secretsmanager:ap-south-1:299650323339:secret:/github/pat-UHmr0B"
},
"memory": 256,
"memoryReservation": 256,
"memory": 512,
"memoryReservation": 512,
"workingDirectory": "/app",
"secrets": [
{
Expand Down Expand Up @@ -232,8 +232,8 @@
"/app/celery_worker-ecs.sh"
],
"cpu": 384,
"memory": 768,
"memoryReservation": 768,
"memory": 1536,
"memoryReservation": 1536,
"environment": [
{
"name": "AUDIT_LOG_ENABLED",
Expand All @@ -257,7 +257,7 @@
},
{
"name": "DJANGO_ALLOWED_HOSTS",
"value": "[\"http://care-django-staging\", \"https://care.coronasafe.in\", \"https://careapi.coronasafe.in\", \"https://care.ohc.network\", \"https://careapi.ohc.network\"]"
"value": "[\"care-django-staging\", \"care.coronasafe.in\", \"careapi.coronasafe.in\", \"care.ohc.network\", \"careapi.ohc.network\"]"
},
{
"name": "DJANGO_SECURE_SSL_REDIRECT",
Expand Down Expand Up @@ -437,7 +437,7 @@
"name": "care-celery-worker"
}
],
"memory": "1024",
"memory": "2048",
"taskRoleArn": "arn:aws:iam::299650323339:role/ecsTaskExecutionRole",
"family": "care-celery",
"requiresCompatibilities": [
Expand Down
10 changes: 10 additions & 0 deletions care/facility/api/serializers/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from care.facility.api.serializers.facility import FacilityBareMinimumSerializer
from care.facility.models.asset import (
Asset,
AssetAvailabilityRecord,
AssetLocation,
AssetTransaction,
UserDefaultAssetLocation,
Expand Down Expand Up @@ -165,6 +166,15 @@ class Meta:
exclude = ("deleted", "external_id")


class AssetAvailabilitySerializer(ModelSerializer):
id = UUIDField(source="external_id", read_only=True)
asset = AssetBareMinimumSerializer(read_only=True)

class Meta:
model = AssetAvailabilityRecord
exclude = ("deleted", "external_id")


class UserDefaultAssetLocationSerializer(ModelSerializer):
location_object = AssetLocationSerializer(source="location", read_only=True)

Expand Down
45 changes: 32 additions & 13 deletions care/facility/api/serializers/patient_consultation.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,17 @@ def validate(self, attrs):
validated["referred_to"] = None
elif validated.get("referred_to"):
validated["referred_to_external"] = None
if (
validated["suggestion"] is SuggestionChoices.A
and validated.get("admitted")
and not validated.get("admission_date")
):
raise ValidationError(
{
"admission_date": [
"This field is required as the patient has been admitted."
]
}
)
if validated["suggestion"] is SuggestionChoices.A:
if not validated.get("admission_date"):
raise ValidationError(
{
"admission_date": "This field is required as the patient has been admitted."
}
)
if validated["admission_date"] > now():
raise ValidationError(
{"admission_date": "This field value cannot be in the future."}
)

if "action" in validated:
if validated["action"] == PatientRegistration.ActionEnum.REVIEW:
Expand Down Expand Up @@ -433,13 +432,33 @@ def validate(self, attrs):
if attrs.get("discharge_reason") == "EXP":
if not attrs.get("death_datetime"):
raise ValidationError({"death_datetime": "This field is required"})
if attrs.get("death_datetime") > now():
raise ValidationError(
{"death_datetime": "This field value cannot be in the future."}
)
if attrs.get("death_datetime") < self.instance.admission_date:
raise ValidationError(
{
"death_datetime": "This field value cannot be before the admission date."
}
)
if not attrs.get("death_confirmed_doctor"):
raise ValidationError(
{"death_confirmed_doctor": "This field is required"}
)
attrs["discharge_date"] = now()
attrs["discharge_date"] = attrs["death_datetime"]
elif not attrs.get("discharge_date"):
raise ValidationError({"discharge_date": "This field is required"})
elif attrs.get("discharge_date") > now():
raise ValidationError(
{"discharge_date": "This field value cannot be in the future."}
)
elif attrs.get("discharge_date") < self.instance.admission_date:
raise ValidationError(
{
"discharge_date": "This field value cannot be before the admission date."
}
)
return attrs

def save(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion care/facility/api/serializers/patient_otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def send_sms(otp, phone_number):
sendSMS(
phone_number,
(
f"CoronaSafe Network Patient Management System Login, OTP is {otp} . "
f"Open Healthcare Network Patient Management System Login, OTP is {otp} . "
"Please do not share this Confidential Login Token with anyone else"
),
)
Expand Down
27 changes: 23 additions & 4 deletions care/facility/api/serializers/prescription.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
from django.shortcuts import get_object_or_404
from rest_framework import serializers

from care.facility.models import MedicineAdministration, Prescription
from care.facility.models import MedibaseMedicine, MedicineAdministration, Prescription
from care.users.api.serializers.user import UserBaseMinimumSerializer


class PrescriptionSerializer(serializers.ModelSerializer):
class MedibaseMedicineSerializer(serializers.ModelSerializer):
id = serializers.UUIDField(source="external_id", read_only=True)

prescribed_by = UserBaseMinimumSerializer(read_only=True)
class Meta:
model = MedibaseMedicine
exclude = ("deleted",)
read_only_fields = (
"external_id",
"created_date",
"modified_date",
)


class PrescriptionSerializer(serializers.ModelSerializer):
id = serializers.UUIDField(source="external_id", read_only=True)
prescribed_by = UserBaseMinimumSerializer(read_only=True)
last_administered_on = serializers.SerializerMethodField()
medicine_object = MedibaseMedicineSerializer(read_only=True, source="medicine")
medicine = serializers.UUIDField(write_only=True)

def get_last_administered_on(self, obj):
last_administration = (
Expand All @@ -28,6 +42,7 @@ class Meta:
"deleted",
)
read_only_fields = (
"medicine_old",
"external_id",
"prescribed_by",
"created_date",
Expand All @@ -37,12 +52,16 @@ class Meta:
)

def validate(self, attrs):
if "medicine" in attrs:
attrs["medicine"] = get_object_or_404(
MedibaseMedicine, external_id=attrs["medicine"]
)

if attrs.get("is_prn"):
if not attrs.get("indicator"):
raise serializers.ValidationError(
{"indicator": "Indicator should be set for PRN prescriptions."}
)

else:
if not attrs.get("frequency"):
raise serializers.ValidationError(
Expand Down
13 changes: 13 additions & 0 deletions care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from rest_framework.viewsets import GenericViewSet

from care.facility.api.serializers.asset import (
AssetAvailabilitySerializer,
AssetLocationSerializer,
AssetSerializer,
AssetTransactionSerializer,
Expand All @@ -32,6 +33,7 @@
)
from care.facility.models.asset import (
Asset,
AssetAvailabilityRecord,
AssetLocation,
AssetTransaction,
UserDefaultAssetLocation,
Expand Down Expand Up @@ -128,6 +130,17 @@ def retrieve(self, request, *args, **kwargs):
return Response(hit)


class AssetAvailabilityFilter(filters.FilterSet):
external_id = filters.CharFilter(field_name="asset__external_id")


class AssetAvailabilityViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet):
queryset = AssetAvailabilityRecord.objects.all().select_related("asset")
serializer_class = AssetAvailabilitySerializer
filter_backends = (filters.DjangoFilterBackend,)
filterset_class = AssetAvailabilityFilter


class AssetViewSet(
ListModelMixin,
RetrieveModelMixin,
Expand Down
4 changes: 4 additions & 0 deletions care/facility/api/viewsets/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ def filter_by_category(self, queryset, name, value):
field_name="last_consultation__current_bed__bed__bed_type",
choice_dict=REVERSE_BED_TYPES,
)
last_consultation_discharge_reason = filters.ChoiceFilter(
field_name="last_consultation__discharge_reason",
choices=DISCHARGE_REASON_CHOICES,
)
last_consultation_assigned_to = filters.NumberFilter(
field_name="last_consultation__assigned_to"
)
Expand Down
45 changes: 44 additions & 1 deletion care/facility/api/viewsets/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from rest_framework.viewsets import GenericViewSet, ViewSet

from care.facility.api.serializers.prescription import (
MedicineAdministrationSerializer,
Expand Down Expand Up @@ -132,3 +132,46 @@ def administer(self, request, *args, **kwargs):
# administered_obj = MedicineAdministration.objects.get(external_id=request.query_params.get("id", None))
# administered_obj.delete()
# return Response({"success": True}, status=status.HTTP_200_OK)


class MedibaseViewSet(ViewSet):
permission_classes = (IsAuthenticated,)

def serailize_data(self, objects):
return [
{
"id": x[0],
"name": x[1],
"type": x[2],
"generic": x[3],
"company": x[4],
"contents": x[5],
"cims_class": x[6],
"atc_classification": x[7],
}
for x in objects
]

def sort(self, query, results):
exact_matches = []
partial_matches = []

for x in results:
words = f"{x[1]} {x[3]} {x[4]}".lower().split()
if query in words:
exact_matches.append(x)
else:
partial_matches.append(x)

return exact_matches + partial_matches

def list(self, request):
from care.facility.static_data.medibase import MedibaseMedicineTable

queryset = MedibaseMedicineTable

if query := request.query_params.get("query"):
query = query.strip().lower()
queryset = [x for x in queryset if query in f"{x[1]} {x[3]} {x[4]}".lower()]
queryset = self.sort(query, queryset)
return Response(self.serailize_data(queryset[:15]))
1 change: 1 addition & 0 deletions care/facility/management/commands/load_dummy_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def handle(self, *args, **options):
try:
management.call_command("loaddata", self.BASE_URL + "users.json")
management.call_command("load_data", "kerala")
management.call_command("load_medicines_data")
management.call_command("seed_data")
management.call_command("loaddata", self.BASE_URL + "facility.json")
management.call_command("loaddata", self.BASE_URL + "cypress_users.json")
Expand Down
39 changes: 39 additions & 0 deletions care/facility/management/commands/load_medicines_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

from django.core.management import BaseCommand

from care.facility.models import MedibaseMedicine


class Command(BaseCommand):
"""
Command to load medibase medicines
Usage: python manage.py load_medicines_data
"""

help = "Loads Medibase Medicines into the database from medibase.json"

def fetch_data(self):
with open("data/medibase.json", "r") as json_file:
return json.load(json_file)

def handle(self, *args, **options):
print("Loading Medibase Medicines into the database from medibase.json")

medibase_objects = self.fetch_data()
MedibaseMedicine.objects.bulk_create(
[
MedibaseMedicine(
name=medicine["name"],
type=medicine["type"],
company=medicine.get("company"),
contents=medicine.get("contents"),
cims_class=medicine.get("cims_class"),
atc_classification=medicine.get("atc_classification"),
generic=medicine.get("generic"),
)
for medicine in medibase_objects
],
batch_size=1000,
ignore_conflicts=True,
)
Loading

0 comments on commit c7555f1

Please sign in to comment.