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

amirhossein ghaffari / amirmohammad rasouli #23

Open
wants to merge 14 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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/bootcamp_appointment.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-09-05 11:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0002_alter_user_expire_at'),
]

operations = [
migrations.AddField(
model_name='user',
name='profile_picture',
field=models.ImageField(blank=True, null=True, upload_to='images/'),
),
]
3 changes: 3 additions & 0 deletions digital_appointment/accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from . import managers
from PIL import Image
from django.core.files.uploadedfile import SimpleUploadedFile


class User(AbstractBaseUser):
profile_picture = models.ImageField(upload_to='images/', null=True, blank=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
username = models.CharField(max_length=100, unique=True)
Expand Down
3 changes: 2 additions & 1 deletion digital_appointment/accounts/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from . import models
from . import serializers
from rest_framework import views
from rest_framework.response import Response
from rest_framework import status
from . import serializers
from rest_framework import permissions, pagination
from rest_framework_simplejwt import authentication
from rest_framework_simplejwt.views import TokenObtainPairView
Expand All @@ -13,6 +13,7 @@ class CustomTokenObtainPairView(TokenObtainPairView):


class User(views.APIView, pagination.PageNumberPagination):
permission_classes = [permissions.IsAuthenticated]
def get(self, request):
users = models.User.objects.all().order_by("-created_at")

Expand Down
Empty file.
10 changes: 10 additions & 0 deletions digital_appointment/appointment/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django import forms
from .models import AppointmentComment

class AppointmentCommentForm(forms.ModelForm):
class Meta:
model = AppointmentComment
fields = ('comment',)
widgets = {
'comment': forms.Textarea(attrs={'rows': 4, 'cols': 40}),
}
9 changes: 7 additions & 2 deletions digital_appointment/appointment/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.7 on 2024-08-11 06:18
# Generated by Django 5.0.7 on 2024-09-04 12:02

import django.db.models.deletion
from django.conf import settings
Expand All @@ -10,7 +10,7 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('medicine', '0001_initial'),
('medicine', '__first__'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

Expand All @@ -19,6 +19,11 @@ class Migration(migrations.Migration):
name='Appointment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('patient_first_name', models.CharField(default='firstname', max_length=255)),
('patient_last_name', models.CharField(default='lastname', max_length=255)),
('patient_phone_number', models.CharField(default='1', max_length=20)),
('patient_national_id', models.CharField(default='1', max_length=20)),
('patient_gender', models.CharField(default='gender', max_length=10)),
('date', models.DateTimeField()),
('status', models.SmallIntegerField(choices=[(0, 'scheduled'), (1, 'cancelled'), (2, 'completed')], default=0)),
('created_date', models.DateTimeField(auto_now_add=True)),
Expand Down
4 changes: 2 additions & 2 deletions digital_appointment/appointment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class Appointment(models.Model):
patient_phone_number = models.CharField(max_length=20, default="1")
patient_national_id = models.CharField(max_length=20, default="1")
patient_gender = models.CharField(max_length=10, default="gender")
date = models.DateTimeField()
status = models.SmallIntegerField(choices=STATUS, default=0)
date = models.DateTimeField()
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)

def __str__(self):
return self.date
return str(self.date)

class Meta:
db_table = "appointment"
15 changes: 15 additions & 0 deletions digital_appointment/appointment/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework import serializers
from rest_framework_simplejwt.serializers import TokenObtainPairSerializer
from . import models
from medicine.serializers import ServiceSerializer

class AppointmentSerializer(serializers.ModelSerializer):
service = serializers.StringRelatedField()
user = serializers.StringRelatedField()
class Meta:
model = models.Appointment
fields = '__all__'




3 changes: 0 additions & 3 deletions digital_appointment/appointment/tests.py

This file was deleted.

4 changes: 4 additions & 0 deletions digital_appointment/appointment/urls.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
from . import views
from django.urls import path

urlpatterns = [
path("appointments/", views.AppointmentView.as_view()),
]
82 changes: 80 additions & 2 deletions digital_appointment/appointment/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,81 @@
from django.shortcuts import render
from . import models
from accounts.serializers import serializers
from medicine.models import Provider
from .forms import AppointmentCommentForm
from .models import Appointment, AppointmentComment
from rest_framework import views, status
from rest_framework.response import Response
from rest_framework import permissions
from rest_framework_simplejwt import authentication
from . import serializers
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required

# Create your views here.
class AppointmentView(views.APIView):
permission_classes = [permissions.IsAuthenticated]

def get(self, request):
appointments = models.Appointment.objects.filter(user=request.user).order_by("-date")
serializer = serializers.AppointmentSerializer(appointments, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)

def post(self, request):
data = request.data.copy()
data["user"] = request.user.id

provider_id = data.get("provider", None)
if provider_id:
try:
data["provider"] = Provider.objects.get(pk=provider_id).id
except Provider.DoesNotExist:
return Response({"error": "Provider does not exist"}, status=status.HTTP_404_NOT_FOUND)

serializer = serializers.AppointmentSerializer(data=data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def put(self, request):
appointment_id = request.data.get('id')
if not appointment_id:
return Response({"error": "Appointment ID is required"}, status=status.HTTP_400_BAD_REQUEST)

appointment, error_response = self.get_appointment(appointment_id, request.user)
if error_response:
return error_response

serializer = serializers.AppointmentSerializer(appointment, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def delete(self, request):
appointment_id = request.data.get('id')
if not appointment_id:
return Response({"error": "Appointment ID is required"}, status=status.HTTP_400_BAD_REQUEST)

appointment, error_response = self.get_appointment(appointment_id, request.user)
if error_response:
return error_response

appointment.delete()
return Response({"status": "deleted"}, status=status.HTTP_200_OK)




@login_required
def comment_appointment(request, appointment_id):
appointment = Appointment.objects.get(id=appointment_id)
if request.method == 'POST':
form = AppointmentCommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.appointment = appointment
comment.save()
return redirect('appointment_detail', appointment_id=appointment_id)
else:
form = AppointmentCommentForm()
return render(request, 'comment_appointment.html', {'form': form, 'appointment': appointment})
6 changes: 3 additions & 3 deletions digital_appointment/digital_appointment/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'bootcamp',
'USER': 'mahdi',
'PASSWORD': 'mahdi',
'NAME': 'verna',
'USER': 'postgres',
'PASSWORD': 'verna',
'HOST': 'localhost',
'PORT': '5432',
},
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions digital_appointment/medicine/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.7 on 2024-08-11 06:18
# Generated by Django 5.0.7 on 2024-09-04 12:06

import django.db.models.deletion
from django.conf import settings
Expand Down Expand Up @@ -35,7 +35,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('description', models.TextField()),
('description', models.TextField(blank=True, null=True)),
('price', models.DecimalField(decimal_places=2, max_digits=10)),
('duration', models.IntegerField(default=30)),
('created_date', models.DateTimeField(auto_now_add=True)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.0.7 on 2024-09-06 13:41

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('medicine', '0002_alter_service_description'),
]

operations = [
migrations.AddField(
model_name='provider',
name='average_rating',
field=models.DecimalField(decimal_places=2, default=0.0, max_digits=3),
),
migrations.CreateModel(
name='Rating',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rating', models.IntegerField(default=0)),
('review', models.TextField(blank=True, null=True)),
('created_date', models.DateTimeField(auto_now_add=True)),
('updated_date', models.DateTimeField(auto_now=True)),
('provider', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='medicine.provider')),
],
options={
'db_table': 'rating',
},
),
]
14 changes: 14 additions & 0 deletions digital_appointment/medicine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Provider(models.Model):
user = models.OneToOneField('accounts.User', on_delete=models.CASCADE)
speciality = models.CharField(max_length=255)
location = models.ForeignKey('medicine.Location', on_delete=models.CASCADE)
average_rating = models.DecimalField(max_digits=3, decimal_places=2, default=0.0)
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)

Expand Down Expand Up @@ -44,3 +45,16 @@ def __str__(self):

class Meta:
db_table = "service"

class Rating(models.Model):
provider = models.ForeignKey('Provider', on_delete=models.CASCADE)
rating = models.IntegerField(default=0)
review = models.TextField(null=True, blank=True)
created_date = models.DateTimeField(auto_now_add=True)
updated_date = models.DateTimeField(auto_now=True)

def __str__(self):
return f"Rating for {self.provider} - {self.rating}"

class Meta:
db_table = "rating"
7 changes: 7 additions & 0 deletions digital_appointment/medicine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ def create(self, validated_data):

class SpecialitySerializer(serializers.Serializer):
speciality = serializers.CharField(max_length=255)



class ServiceSerializer(serializers.ModelSerializer):
class Meta:
models = models.Service
fields = '__all__'
13 changes: 13 additions & 0 deletions digital_appointment/medicine/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Rating, Provider

@receiver(post_save, sender=Rating)
def update_provider_average_rating(sender, instance, **kwargs):
provider = instance.provider
ratings = provider.rating_set.all()
total_ratings = ratings.count()
if total_ratings > 0:
total_rating_sum = sum(r.rating for r in ratings)
provider.average_rating = total_rating_sum / total_ratings
provider.save()
3 changes: 0 additions & 3 deletions digital_appointment/medicine/tests.py

This file was deleted.

Loading