Skip to content

Commit

Permalink
Merge branch 'master' into issue#6240
Browse files Browse the repository at this point in the history
  • Loading branch information
aeswibon authored Nov 16, 2023
2 parents bc0a668 + fa5ba42 commit fe9516c
Show file tree
Hide file tree
Showing 28 changed files with 1,214 additions and 267 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ jobs:
wait-for-service-stability: true

deploy-staging-gcp:
needs: build-production
needs: build-staging
name: Deploy to staging GCP cluster
runs-on: ubuntu-latest
environment:
Expand Down Expand Up @@ -527,3 +527,49 @@ jobs:
kubectl apply -f care-backend.yaml
kubectl apply -f care-celery-beat.yaml
kubectl apply -f care-celery-worker.yaml
deploy-production-meghalaya:
needs: build-production
name: Deploy to GKE Meghalaya
runs-on: ubuntu-latest
environment:
name: Production-Meghalaya
url: https://careapi.meghealth.gov.in
steps:
- name: Checkout Kube Config
uses: actions/checkout@v3
with:
repository: coronasafe/ml-care-infra
token: ${{ secrets.GIT_ACCESS_TOKEN }}
path: kube
ref: main

# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@94337306dda8180d967a56932ceb4ddcf01edae7
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}

# Get the GKE credentials, so we can deploy to the cluster
- uses: google-github-actions/get-gke-credentials@fb08709ba27618c31c09e014e1d8364b02e5042e
with:
cluster_name: ${{ secrets.GKE_CLUSTER }}
location: ${{ secrets.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}

- name: install kubectl
uses: azure/[email protected]
with:
version: "v1.23.6"
id: install

- name: Deploy Care Production Nagaland
run: |
mkdir -p $HOME/.kube/
cd kube/deployments/
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-backend.yaml
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-celery-beat.yaml
sed -i -e "s/_BUILD_NUMBER_/${GITHUB_RUN_NUMBER}/g" care-celery-worker.yaml
kubectl apply -f care-backend.yaml
kubectl apply -f care-celery-beat.yaml
kubectl apply -f care-celery-worker.yaml
30 changes: 14 additions & 16 deletions care/abdm/utils/fhir.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
from fhir.resources.reference import Reference

from care.facility.models.file_upload import FileUpload
from care.facility.models.icd11_diagnosis import REVERSE_CONDITION_VERIFICATION_STATUSES
from care.facility.models.patient_investigation import InvestigationValue
from care.facility.static_data.icd11 import ICDDiseases
from care.facility.static_data.icd11 import get_icd11_diagnosis_object_by_id


class Fhir:
Expand Down Expand Up @@ -136,8 +137,8 @@ def _organization(self):

return self._organization_profile

def _condition(self, diagnosis_id, provisional=False):
diagnosis = ICDDiseases.by.id[diagnosis_id]
def _condition(self, diagnosis_id, verification_status):
diagnosis = get_icd11_diagnosis_object_by_id(diagnosis_id)
[code, label] = diagnosis.label.split(" ", 1)
condition_profile = Condition(
id=diagnosis_id,
Expand All @@ -158,8 +159,10 @@ def _condition(self, diagnosis_id, provisional=False):
coding=[
Coding(
system="http://terminology.hl7.org/CodeSystem/condition-ver-status",
code="provisional" if provisional else "confirmed",
display="Provisional" if provisional else "Confirmed",
code=verification_status,
display=REVERSE_CONDITION_VERIFICATION_STATUSES[
verification_status
],
)
]
),
Expand Down Expand Up @@ -368,20 +371,15 @@ def _encounter(self, include_diagnosis=False):
"period": Period(start=period_start, end=period_end),
"diagnosis": list(
map(
lambda diagnosis: EncounterDiagnosis(
lambda consultation_diagnosis: EncounterDiagnosis(
condition=self._reference(
self._condition(diagnosis),
self._condition(
consultation_diagnosis.diagnosis_id,
consultation_diagnosis.verification_status,
),
)
),
self.consultation.icd11_diagnoses,
)
)
+ list(
map(
lambda diagnosis: EncounterDiagnosis(
condition=self._reference(self._condition(diagnosis))
),
self.consultation.icd11_provisional_diagnoses,
self.consultation.diagnoses.all(),
)
)
if include_diagnosis
Expand Down
127 changes: 127 additions & 0 deletions care/facility/api/serializers/consultation_diagnosis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
from typing import Any

from rest_framework import serializers

from care.facility.models import (
INACTIVE_CONDITION_VERIFICATION_STATUSES,
ConsultationDiagnosis,
)
from care.facility.models.icd11_diagnosis import ICD11Diagnosis
from care.facility.static_data.icd11 import get_icd11_diagnosis_object_by_id
from care.users.api.serializers.user import UserBaseMinimumSerializer


class ConsultationCreateDiagnosisSerializer(serializers.ModelSerializer):
def validate_verification_status(self, value):
if value in INACTIVE_CONDITION_VERIFICATION_STATUSES:
raise serializers.ValidationError("Verification status not allowed")
return value

class Meta:
model = ConsultationDiagnosis
fields = ("diagnosis", "verification_status", "is_principal")


class ConsultationDiagnosisSerializer(serializers.ModelSerializer):
id = serializers.UUIDField(source="external_id", read_only=True)
diagnosis = serializers.PrimaryKeyRelatedField(
queryset=ICD11Diagnosis.objects.all(), required=True, allow_null=False
)
diagnosis_object = serializers.SerializerMethodField()
created_by = UserBaseMinimumSerializer(read_only=True)

def get_diagnosis_object(self, obj):
return get_icd11_diagnosis_object_by_id(obj.diagnosis_id, as_dict=True)

class Meta:
model = ConsultationDiagnosis
exclude = (
"consultation",
"external_id",
"deleted",
)
read_only_fields = (
"created_by",
"created_date",
"modified_date",
"is_migrated",
)

def get_consultation_external_id(self):
return self.context["request"].parser_context["kwargs"][
"consultation_external_id"
]

def validate_diagnosis(self, value):
if self.instance and value != self.instance.diagnosis:
raise serializers.ValidationError("Diagnosis cannot be changed")

if (
not self.instance
and ConsultationDiagnosis.objects.filter(
consultation__external_id=self.get_consultation_external_id(),
diagnosis=value,
).exists()
):
raise serializers.ValidationError(
"Diagnosis already exists for consultation"
)

return value

def validate_verification_status(self, value):
if not self.instance and value in INACTIVE_CONDITION_VERIFICATION_STATUSES:
raise serializers.ValidationError("Verification status not allowed")
return value

def validate_is_principal(self, value):
if not value:
return value

qs = ConsultationDiagnosis.objects.filter(
consultation__external_id=self.get_consultation_external_id(),
is_principal=True,
)

if self.instance:
qs = qs.exclude(id=self.instance.id)

if qs.exists():
raise serializers.ValidationError(
"Consultation already has a principal diagnosis. Unset the existing principal diagnosis first."
)

return value

def update(self, instance, validated_data):
if (
"verification_status" in validated_data
and validated_data["verification_status"]
in INACTIVE_CONDITION_VERIFICATION_STATUSES
):
instance.is_principal = False
return super().update(instance, validated_data)

def validate(self, attrs: Any) -> Any:
validated = super().validate(attrs)

if (
"verification_status" in validated
and validated["verification_status"]
in INACTIVE_CONDITION_VERIFICATION_STATUSES
):
validated["is_principal"] = False

if "is_principal" in validated and validated["is_principal"]:
verification_status = validated.get(
"verification_status",
self.instance.verification_status if self.instance else None,
)
if verification_status in INACTIVE_CONDITION_VERIFICATION_STATUSES:
raise serializers.ValidationError(
{
"is_principal": "Refuted/Entered in error diagnoses cannot be marked as Principal Diagnosis"
}
)

return validated
23 changes: 18 additions & 5 deletions care/facility/api/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.db import transaction
from django.db.models import Q
from django.utils.timezone import localtime, make_aware, now
from django.utils.timezone import make_aware, now
from rest_framework import serializers

from care.abdm.api.serializers.abhanumber import AbhaNumberSerializer
Expand All @@ -27,6 +27,7 @@
PatientNotes,
PatientRegistration,
)
from care.facility.models.bed import ConsultationBed
from care.facility.models.notification import Notification
from care.facility.models.patient_base import (
BLOOD_GROUP_CHOICES,
Expand Down Expand Up @@ -453,10 +454,22 @@ def create(self, validated_data):

def save(self, **kwargs):
self.instance.facility = self.validated_data["facility"]
PatientConsultation.objects.filter(
patient=self.instance, discharge_date__isnull=True
).update(discharge_date=localtime(now()))
self.instance.save()

with transaction.atomic():
consultation = PatientConsultation.objects.filter(
patient=self.instance, discharge_date__isnull=True
).first()

if consultation:
consultation.discharge_date = now()
consultation.discharge_reason = "REF"
consultation.current_bed = None
consultation.save()

ConsultationBed.objects.filter(
consultation=consultation, end_date__isnull=True
).update(end_date=now())
self.instance.save()


class PatientNotesSerializer(serializers.ModelSerializer):
Expand Down
Loading

0 comments on commit fe9516c

Please sign in to comment.