Skip to content

Commit 1e6db21

Browse files
committed
fixed report view
1 parent 39a9a82 commit 1e6db21

5 files changed

+42
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 4.2.3 on 2023-07-28 22:08
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api', '0004_alter_user_department'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='department',
15+
name='name',
16+
field=models.CharField(max_length=50, unique=True),
17+
),
18+
migrations.AlterField(
19+
model_name='patientreport',
20+
name='created',
21+
field=models.DateField(auto_now_add=True),
22+
),
23+
]

api/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Role(models.TextChoices):
4141
class PatientReport(models.Model):
4242
record_id = models.BigAutoField(primary_key=True)
4343
patient = models.ForeignKey(User, on_delete=models.CASCADE)
44-
created = models.DateTimeField(auto_now_add=True)
44+
created = models.DateField(auto_now_add=True)
4545
department = models.ForeignKey(Department, on_delete=models.CASCADE)
4646
diagnostics = models.TextField()
4747
observations = models.TextField()

api/serializers.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,22 @@ class PatientReportSerializer(serializers.ModelSerializer):
5252
class Meta:
5353
model = PatientReport
5454
fields = ['record_id', 'patient', 'department', 'created', 'diagnostics', 'observations', 'treatments']
55+
extra_kwargs = {
56+
'created': {
57+
'read_only': True,
58+
},
59+
60+
}
5561

5662
def to_representation(self, instance):
5763
rep = super(PatientReportSerializer, self).to_representation(instance)
58-
rep['student'] = instance.student.username
64+
rep['patient'] = instance.patient.username
5965
rep['department'] = instance.department.name
6066
return rep
6167

6268
def validate(self, attrs):
6369
print(attrs)
64-
student = attrs.get('student')
65-
if student.role != User.Role.PATIENT:
66-
raise serializers.ValidationError("Report can be created for students only")
70+
patient = attrs.get('patient')
71+
if patient.role != User.Role.PATIENT:
72+
raise serializers.ValidationError("Report can be created for patients only")
6773
return attrs

api/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class PatientReportListView(ListCreateAPIView):
108108
permission_classes = [IsAuthenticated]
109109

110110
def get_queryset(self, **kwargs):
111-
qs = PatientReport.objects.all().filter(patient__role=User.Role.PATIENT)
111+
qs = PatientReport.objects.filter(patient__role=User.Role.PATIENT)
112112
return qs
113113

114114

hms_api/settings.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
# SECURITY WARNING: keep the secret key used in production secret!
2525

26-
SECRET_KEY = os.environ.get('SECRET_KEY')
27-
# SECRET_KEY='123'
28-
DEBUG = os.environ.get("DEBUG", "False").lower() == "true"
29-
# DEBUG=True
30-
# ALLOWED_HOSTS=[]
31-
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split(" ")
26+
# SECRET_KEY = os.environ.get('SECRET_KEY')
27+
SECRET_KEY='123'
28+
# DEBUG = os.environ.get("DEBUG", "False").lower() == "true"
29+
DEBUG=True
30+
ALLOWED_HOSTS=[]
31+
# ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS').split(" ")
3232

3333
# Application definition
3434

@@ -87,7 +87,7 @@
8787
}
8888

8989
database_url = os.environ.get("DATABASE_URL")
90-
DATABASES["default"] = dj_database_url.parse(database_url)
90+
# DATABASES["default"] = dj_database_url.parse(database_url)
9191

9292
# Password validation
9393
# https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators

0 commit comments

Comments
 (0)