Skip to content

Commit

Permalink
Merge pull request #14 from MohamedHamed12/account
Browse files Browse the repository at this point in the history
Account
  • Loading branch information
MohamedHamed12 authored May 11, 2024
2 parents 1d03652 + b32152a commit d403afc
Show file tree
Hide file tree
Showing 31 changed files with 106 additions and 254 deletions.
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
],
"django": true,
"autoStartBrowser": false,
"program": "${workspaceFolder}/project/manage.py"
"program": "${workspaceFolder}/project/manage.py",
"console": "integratedTerminal",
// show my code only false
// "justMyCode": false
}
]
}
11 changes: 11 additions & 0 deletions project/accounts/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ class Meta:


}

class UserImageFilter(filters.FilterSet):
class Meta:
model = UserImage
fields = {
'user_id': ['exact'],
}




class DoctorFilter(filters.FilterSet):
class Meta:
model = Doctor
Expand Down
58 changes: 30 additions & 28 deletions project/accounts/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 5.0.3 on 2024-05-07 13:39
# Generated by Django 5.0.3 on 2024-05-11 14:42

import django.db.models.deletion
import shortuuidfield.fields
from django.conf import settings
from django.db import migrations, models

Expand Down Expand Up @@ -29,24 +28,30 @@ class Migration(migrations.Migration):
),
("full_name", models.CharField(max_length=255)),
("email", models.CharField(max_length=255, null=True, unique=True)),
("gender", models.CharField(max_length=255)),
("gender", models.CharField(blank=True, max_length=255, null=True)),
(
"marital_status",
models.CharField(blank=True, max_length=255, null=True),
),
("nationality", models.CharField(default="Egypt", max_length=255)),
("national_id", models.CharField(max_length=255)),
("national_id", models.CharField(max_length=255, unique=True)),
("date_of_birth", models.DateField(blank=True, null=True)),
("notes", models.TextField(blank=True)),
("address", models.JSONField()),
("phone", models.JSONField()),
("notes", models.TextField(blank=True, null=True)),
("address", models.JSONField(blank=True, null=True)),
("phone", models.JSONField(blank=True, null=True)),
("is_deleted", models.BooleanField(default=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("speciality", models.CharField(max_length=255)),
("license_number", models.CharField(max_length=255)),
("experience_years", models.PositiveIntegerField()),
("work_days", models.CharField(max_length=255)),
(
"license_number",
models.CharField(blank=True, max_length=255, null=True),
),
(
"experience_years",
models.PositiveIntegerField(blank=True, null=True),
),
("work_days", models.CharField(blank=True, max_length=255, null=True)),
(
"user",
models.OneToOneField(
Expand Down Expand Up @@ -74,17 +79,17 @@ class Migration(migrations.Migration):
),
("full_name", models.CharField(max_length=255)),
("email", models.CharField(max_length=255, null=True, unique=True)),
("gender", models.CharField(max_length=255)),
("gender", models.CharField(blank=True, max_length=255, null=True)),
(
"marital_status",
models.CharField(blank=True, max_length=255, null=True),
),
("nationality", models.CharField(default="Egypt", max_length=255)),
("national_id", models.CharField(max_length=255)),
("national_id", models.CharField(max_length=255, unique=True)),
("date_of_birth", models.DateField(blank=True, null=True)),
("notes", models.TextField(blank=True)),
("address", models.JSONField()),
("phone", models.JSONField()),
("notes", models.TextField(blank=True, null=True)),
("address", models.JSONField(blank=True, null=True)),
("phone", models.JSONField(blank=True, null=True)),
("is_deleted", models.BooleanField(default=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
Expand Down Expand Up @@ -115,28 +120,25 @@ class Migration(migrations.Migration):
),
("full_name", models.CharField(max_length=255)),
("email", models.CharField(max_length=255, null=True, unique=True)),
("gender", models.CharField(max_length=255)),
("gender", models.CharField(blank=True, max_length=255, null=True)),
(
"marital_status",
models.CharField(blank=True, max_length=255, null=True),
),
("nationality", models.CharField(default="Egypt", max_length=255)),
("national_id", models.CharField(max_length=255)),
("national_id", models.CharField(max_length=255, unique=True)),
("date_of_birth", models.DateField(blank=True, null=True)),
("notes", models.TextField(blank=True)),
("address", models.JSONField()),
("phone", models.JSONField()),
("notes", models.TextField(blank=True, null=True)),
("address", models.JSONField(blank=True, null=True)),
("phone", models.JSONField(blank=True, null=True)),
("is_deleted", models.BooleanField(default=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("disease_type", models.CharField(max_length=255)),
("blood_type", models.CharField(max_length=255)),
(
"code",
shortuuidfield.fields.ShortUUIDField(
blank=True, editable=False, max_length=22, unique=True
),
"disease_type",
models.CharField(blank=True, max_length=255, null=True),
),
("blood_type", models.CharField(blank=True, max_length=255, null=True)),
(
"user",
models.OneToOneField(
Expand Down Expand Up @@ -168,9 +170,9 @@ class Migration(migrations.Migration):
("is_deleted", models.BooleanField(default=False)),
(
"user",
models.ForeignKey(
models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name="images",
related_name="image",
to=settings.AUTH_USER_MODEL,
),
),
Expand Down

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions project/accounts/migrations/0004_remove_patient_code.py

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion project/accounts/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Profile(models.Model):
gender = models.CharField(max_length=255, null=True,blank=True)
marital_status = models.CharField(max_length=255 ,null=True,blank=True)
nationality = models.CharField(max_length=255 ,default="Egypt")
national_id= models.CharField(max_length=255)
national_id= models.CharField(max_length=255 ,unique=True)
date_of_birth = models.DateField(blank=True, null=True)
notes= models.TextField(blank=True,null=True)
address = models.JSONField(null=True, blank=True)
Expand Down
2 changes: 1 addition & 1 deletion project/accounts/models/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class UserImage(models.Model):
image = models.ImageField(upload_to='user_images' )
# user = models.OneToOneField(User, on_delete=models.CASCADE ,related_name='user_images' )
user = models.ForeignKey(User, on_delete=models.CASCADE ,related_name='images' )
user = models.OneToOneField(User, on_delete=models.CASCADE ,related_name='image' )
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_deleted = models.BooleanField(default=False)
Expand Down
2 changes: 1 addition & 1 deletion project/accounts/serializers/patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Meta:

class PatientSerializer(serializers.ModelSerializer):

image = UserImageSerializer(many=True, read_only=True, source='user.images')
image = UserImageSerializer( read_only=True, source='user.image')
address =AddressSerializer( required=False)
phone=PhoneSerializer(PhoneSerializer,required=False)
class Meta:
Expand Down
6 changes: 6 additions & 0 deletions project/accounts/tests/test_patient.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ def test_create_patient(self):
url, obj, HTTP_AUTHORIZATION='Bearer ' + self.staff_token )

self.assertEqual(response.status_code, 201)

response = self.client.get(
'/accounts/user-image/?user_id='+str(user.id), format='json', HTTP_AUTHORIZATION='Bearer ' + self.staff_token)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)

# remvove image
os.remove("test_image.jpg")

Expand Down
14 changes: 8 additions & 6 deletions project/accounts/views/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class DoctorViewSet(viewsets.ModelViewSet):


def create(self , request, *args, **kwargs):
msg,user=create_user(request.data)
if msg!="created":
return Response(msg,status=status.HTTP_400_BAD_REQUEST)

request.data.update({'user':user.id})
serializer = DoctorSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
doctor=serializer.save()

user=User.objects.create_user(username=serializer.data['national_id'],password=serializer.data['national_id'])
doctor.user=user
doctor.save()

return super().create(request, *args, **kwargs)
return Response(DoctorSerializer(doctor).data, status=status.HTTP_201_CREATED)

11 changes: 10 additions & 1 deletion project/accounts/views/employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ class EmployeeViewSet(viewsets.ModelViewSet):
queryset = Employee.objects.all()
serializer_class = EmployeeSerializer
permission_classes = [OwnPermission]

def create(self , request, *args, **kwargs):
serializer = EmployeeSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
employee=serializer.save()

user=User.objects.create_user(username=serializer.data['national_id'],password=serializer.data['national_id'])
employee.user=user
employee.save()

return Response(EmployeeSerializer(employee).data, status=status.HTTP_201_CREATED)



Expand Down
Loading

0 comments on commit d403afc

Please # to comment.