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

Feature/primary surgeon #154

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ teardown:
docker-compose -f ${COMPOSE_ENV}.yml down -v

recreate: teardown run

# DO NOT USE IT IN PRODUCTION as it wipes all the data
load-test-data:
docker-compose -f local.yml exec -T django python manage.py loaddata test_data.yaml
2 changes: 2 additions & 0 deletions tmh_registry/registry/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class PatientAdmin(ExportMixin, admin.ModelAdmin):
class PatientHospitalMappingAdmin(ExportMixin, admin.ModelAdmin):
model = PatientHospitalMapping


@admin.register(PreferredHospital)
class PreferredHospitalAdmin(ExportMixin, admin.ModelAdmin):
model = PreferredHospital


@admin.register(Episode)
class EpisodeAdmin(ExportMixin, admin.ModelAdmin):
model = Episode
Expand Down
18 changes: 17 additions & 1 deletion tmh_registry/registry/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Meta:


class EpisodeSerializer(ModelSerializer):
primary_surgeon = MedicalPersonnelSerializer(many=False)
secondary_surgeon = MedicalPersonnelSerializer(many=False)
tertiary_surgeon = MedicalPersonnelSerializer(many=False)
surgeons = MedicalPersonnelSerializer(many=True)
episode_type = CharField(source="get_episode_type_display")
cepod = CharField(source="get_cepod_display")
Expand All @@ -43,6 +46,9 @@ class Meta:
"id",
"surgery_date",
"episode_type",
"primary_surgeon",
"secondary_surgeon",
"tertiary_surgeon",
"surgeons",
"cepod",
"side",
Expand Down Expand Up @@ -240,6 +246,7 @@ def to_representation(self, instance):

return data


class PreferredHospitalReadSerializer(ModelSerializer):
hospital = SerializerMethodField()

Expand All @@ -251,13 +258,16 @@ def get_hospital(self, obj):
request = self.context.get("request")
if request and request.user:
try:
medical_personnel = MedicalPersonnel.objects.get(user=request.user)
medical_personnel = MedicalPersonnel.objects.get(
user=request.user
)
if obj.medical_personnel == medical_personnel:
return {"id": obj.hospital.id}
except MedicalPersonnel.DoesNotExist:
pass
return None


class PatientHospitalMappingWriteSerializer(ModelSerializer):
patient_id = PrimaryKeyRelatedField(queryset=Patient.objects.all())
hospital_id = PrimaryKeyRelatedField(queryset=Hospital.objects.all())
Expand Down Expand Up @@ -329,6 +339,9 @@ def create(self, validated_data):

class EpisodeReadSerializer(ModelSerializer):
patient_hospital_mapping = PatientHospitalMappingReadSerializer()
primary_surgeon = MedicalPersonnelSerializer(many=False)
secondary_surgeon = MedicalPersonnelSerializer(many=False)
tertiary_surgeon = MedicalPersonnelSerializer(many=False)
surgeons = MedicalPersonnelSerializer(many=True)
episode_type = CharField(source="get_episode_type_display")
cepod = CharField(source="get_cepod_display")
Expand All @@ -350,6 +363,9 @@ class Meta:
"created",
"surgery_date",
"episode_type",
"primary_surgeon",
"secondary_surgeon",
"tertiary_surgeon",
"surgeons",
"cepod",
"side",
Expand Down
10 changes: 7 additions & 3 deletions tmh_registry/registry/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

from ...users.models import MedicalPersonnel
from ..models import (
Discharge,
Episode,
Expand All @@ -42,31 +43,34 @@
PreferredHospitalReadSerializer,
ReadPatientSerializer,
)
from ...users.models import MedicalPersonnel


class HospitalViewSet(viewsets.ReadOnlyModelViewSet):
queryset = Hospital.objects.all()
serializer_class = HospitalSerializer


class PreferredHospitalViewSet(viewsets.GenericViewSet):
serializer_class = PreferredHospitalReadSerializer
permission_classes = [IsAuthenticated]

@action(detail=False, methods=['get'])
@action(detail=False, methods=["get"])
def retrieve_for_current_user(self, request, *args, **kwargs):
user = request.user
try:
medical_personnel = MedicalPersonnel.objects.get(user=user)
except MedicalPersonnel.DoesNotExist:
return Response({}, status=200)
try:
preferred_hospital = PreferredHospital.objects.get(medical_personnel=medical_personnel)
preferred_hospital = PreferredHospital.objects.get(
medical_personnel=medical_personnel
)
except PreferredHospital.DoesNotExist:
return Response({}, status=200)
serializer = self.get_serializer(preferred_hospital)
return Response(serializer.data)


class PatientFilterSet(FilterSet):
hospital_id = NumberFilter(
method="filter_hospital",
Expand Down
167 changes: 167 additions & 0 deletions tmh_registry/registry/fixtures/test_data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@

- model: auth.User
pk: 2
fields:
password: 123456
last_login: null
is_superuser: false
username: [email protected]
first_name: Sur
last_name: Doctor
email: [email protected]
is_staff: false
is_active: true
date_joined: 2024-09-11T00:00:00Z

- model: auth.User
pk: 3
fields:
password: 123456
last_login: null
is_superuser: false
username: [email protected]
first_name: Sur 2
last_name: Doctor
email: [email protected]
is_staff: false
is_active: true
date_joined: 2024-09-11T00:00:00Z

- model: auth.User
pk: 4
fields:
password: 123456
last_login: null
is_superuser: false
username: [email protected]
first_name: Sur 3
last_name: Doctor
email: [email protected]
is_staff: false
is_active: true
date_joined: 2024-09-11T00:00:00Z

- model: users.MedicalPersonnel
pk: 2
fields:
user_id: 2
level: Lead Surgeon

- model: users.MedicalPersonnel
pk: 3
fields:
user_id: 3
level: Lead Surgeon

- model: users.MedicalPersonnel
pk: 4
fields:
user_id: 4
level: Lead Surgeon

- model: registry.Hospital
pk: 10
fields:
name: Test Hospital
address: Here and there Address

- model: registry.Hospital
pk: 11
fields:
name: Different Hospital
address: Nowhere


- model: registry.Patient
pk: 100
fields:
full_name: Patient Boy
national_id: National Id
day_of_birth: 18
month_of_birth: 3
year_of_birth: 2002
gender: MALE
phone_1: 0123456789
phone_2: 9876543210
address: All the way
created_at: 2024-09-11
updated_at: 2024-09-11

- model: registry.PatientHospitalMapping
pk: 1000
fields:
patient_id: 100
hospital_id: 10
patient_hospital_id: 1100

- model: registry.Episode
pk: 10000
fields:
patient_hospital_mapping: 1000
created: 2024-09-11T00:00:00Z
surgery_date: 2024-09-11T00:00:00Z
episode_type: INGUINAL
primary_surgeon_id: null
secondary_surgeon_id: null
tertiary_surgeon_id: null
surgeons: [ 1, 2, 3, 4 ]
cepod: PLANNED
side: LEFT
occurence: PRIMARY
type: DIRECT
size: VERY_SMALL
complexity: SIMPLE
mesh_type: TNMHP
anaesthetic_type: LOCAL
diathermy_used: false
antibiotic_used: false
antibiotic_type: null
comments: Comment here

- model: registry.Episode
pk: 10001
fields:
patient_hospital_mapping: 1000
created: 2024-09-11T00:00:00Z
surgery_date: 2024-09-11T00:00:00Z
episode_type: INGUINAL
primary_surgeon_id: null
secondary_surgeon_id: null
tertiary_surgeon_id: null
surgeons: [ 1, 2 ]
cepod: PLANNED
side: LEFT
occurence: PRIMARY
type: DIRECT
size: VERY_SMALL
complexity: SIMPLE
mesh_type: TNMHP
anaesthetic_type: LOCAL
diathermy_used: false
antibiotic_used: false
antibiotic_type: null
comments: Comment here

- model: registry.Episode
pk: 10002
fields:
patient_hospital_mapping: 1000
created: 2024-09-11T00:00:00Z
surgery_date: 2024-09-11T00:00:00Z
episode_type: INGUINAL
primary_surgeon_id: null
secondary_surgeon_id: null
tertiary_surgeon_id: null
surgeons: []
cepod: PLANNED
side: LEFT
occurence: PRIMARY
type: DIRECT
size: VERY_SMALL
complexity: SIMPLE
mesh_type: TNMHP
anaesthetic_type: LOCAL
diathermy_used: false
antibiotic_used: false
antibiotic_type: null
comments: Comment here
6 changes: 3 additions & 3 deletions tmh_registry/registry/migrations/0036_followup_recurrence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
class Migration(migrations.Migration):

dependencies = [
('registry', '0035_episode_comments'),
("registry", "0035_episode_comments"),
]

operations = [
migrations.AddField(
model_name='followup',
name='recurrence',
model_name="followup",
name="recurrence",
field=models.BooleanField(null=True),
),
]
38 changes: 30 additions & 8 deletions tmh_registry/registry/migrations/0037_preferredhospital.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,43 @@
class Migration(migrations.Migration):

dependencies = [
('users', '0008_auto_20210630_1407'),
('registry', '0036_followup_recurrence'),
("users", "0008_auto_20210630_1407"),
("registry", "0036_followup_recurrence"),
]

operations = [
migrations.CreateModel(
name='PreferredHospital',
name="PreferredHospital",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('hospital', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='preferred_by_medical_personnel', to='registry.hospital')),
('medical_personnel', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='preferred_hospital', to='users.medicalpersonnel')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"hospital",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="preferred_by_medical_personnel",
to="registry.hospital",
),
),
(
"medical_personnel",
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="preferred_hospital",
to="users.medicalpersonnel",
),
),
],
options={
'verbose_name_plural': 'Medical Personnel Preferred Hospitals',
'unique_together': {('medical_personnel', 'hospital')},
"verbose_name_plural": "Medical Personnel Preferred Hospitals",
"unique_together": {("medical_personnel", "hospital")},
},
),
]
17 changes: 17 additions & 0 deletions tmh_registry/registry/migrations/0038_auto_20240915_1210.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.1.3 on 2024-09-15 12:10

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("registry", "0037_preferredhospital"),
]

operations = [
migrations.AlterModelOptions(
name="patienthospitalmapping",
options={"verbose_name_plural": "Patient-Hospital Mappings"},
),
]
Loading