diff --git a/.gitignore b/.gitignore index bc7a548db..a88681399 100644 --- a/.gitignore +++ b/.gitignore @@ -75,4 +75,4 @@ package-lock.json .DS_Store - +**/generated.pdf diff --git a/FusionIIIT/applications/health_center/admin.py b/FusionIIIT/applications/health_center/admin.py index 7299eff00..a988d7b5f 100644 --- a/FusionIIIT/applications/health_center/admin.py +++ b/FusionIIIT/applications/health_center/admin.py @@ -3,19 +3,19 @@ from .models import * admin.site.register(Doctor) -admin.site.register(Appointment) -admin.site.register(Ambulance_request) -admin.site.register(Hospital_admit) -admin.site.register(Complaint) -admin.site.register(Stock) -admin.site.register(Counter) -admin.site.register(Expiry) -admin.site.register(Hospital) -admin.site.register(Prescription) -admin.site.register(Medicine) -admin.site.register(Prescribed_medicine) +# admin.site.register(Appointment) +# admin.site.register(Ambulance_request) +# admin.site.register(Hospital_admit) +# admin.site.register(Complaint) +admin.site.register(Present_Stock) +# admin.site.register(Counter) +# admin.site.register(Expiry) +# admin.site.register(Hospital) +admin.site.register(All_Prescription) +admin.site.register(All_Medicine) +admin.site.register(All_Prescribed_medicine) admin.site.register(Doctors_Schedule) admin.site.register(Pathologist_Schedule) -admin.site.register(Announcements) -admin.site.register(SpecialRequest) -admin.site.register(Pathologist) \ No newline at end of file +# admin.site.register(Announcements) +# admin.site.register(SpecialRequest) +admin.site.register(Pathologist) \ No newline at end of file diff --git a/FusionIIIT/applications/health_center/api/serializers.py b/FusionIIIT/applications/health_center/api/serializers.py index 5eb2740b2..edfaa6dc7 100644 --- a/FusionIIIT/applications/health_center/api/serializers.py +++ b/FusionIIIT/applications/health_center/api/serializers.py @@ -1,114 +1,114 @@ -from django.contrib.auth import get_user_model -from rest_framework.authtoken.models import Token -from rest_framework import serializers -from applications.health_center.models import * +# from django.contrib.auth import get_user_model +# from rest_framework.authtoken.models import Token +# from rest_framework import serializers +# from applications.health_center.models import * -class DoctorSerializer(serializers.ModelSerializer): +# class DoctorSerializer(serializers.ModelSerializer): - class Meta: - model=Doctor - fields=('__all__') +# class Meta: +# model=Doctor +# fields=('__all__') -class PathologistSerializer(serializers.ModelSerializer): +# class PathologistSerializer(serializers.ModelSerializer): - class Meta: - model=Pathologist - fields=('__all__') +# class Meta: +# model=Pathologist +# fields=('__all__') -class ComplaintSerializer(serializers.ModelSerializer): +# class ComplaintSerializer(serializers.ModelSerializer): - class Meta: - model=Complaint - fields=('__all__') +# class Meta: +# model=Complaint +# fields=('__all__') -class StockSerializer(serializers.ModelSerializer): +# class StockSerializer(serializers.ModelSerializer): - class Meta: - model=Stock - fields=('__all__') +# class Meta: +# model=Stock +# fields=('__all__') -class MedicineSerializer(serializers.ModelSerializer): +# class MedicineSerializer(serializers.ModelSerializer): - class Meta: - model=Medicine - fields=('__all__') +# class Meta: +# model=Medicine +# fields=('__all__') -class HospitalSerializer(serializers.ModelSerializer): +# class HospitalSerializer(serializers.ModelSerializer): - class Meta: - model=Hospital - fields=('__all__') +# class Meta: +# model=Hospital +# fields=('__all__') -class ExpirySerializer(serializers.ModelSerializer): +# class ExpirySerializer(serializers.ModelSerializer): - class Meta: - model=Expiry - fields=('__all__') +# class Meta: +# model=Expiry +# fields=('__all__') -class DoctorsScheduleSerializer(serializers.ModelSerializer): +# class DoctorsScheduleSerializer(serializers.ModelSerializer): - class Meta: - model=Doctors_Schedule - fields=('__all__') -class PathologistScheduleSerializer(serializers.ModelSerializer): +# class Meta: +# model=Doctors_Schedule +# fields=('__all__') +# class PathologistScheduleSerializer(serializers.ModelSerializer): - class Meta: - model=Pathologist_Schedule - fields=('__all__') +# class Meta: +# model=Pathologist_Schedule +# fields=('__all__') -class AnnouncementSerializer(serializers.ModelSerializer): +# class AnnouncementSerializer(serializers.ModelSerializer): - class Meta: - model=Announcements - fields=('__all__') +# class Meta: +# model=Announcements +# fields=('__all__') -class CounterSerializer(serializers.ModelSerializer): +# class CounterSerializer(serializers.ModelSerializer): - class Meta: - model=Counter - fields=('__all__') +# class Meta: +# model=Counter +# fields=('__all__') -class AppointmentSerializer(serializers.ModelSerializer): +# class AppointmentSerializer(serializers.ModelSerializer): - class Meta: - model=Appointment - fields=('__all__') +# class Meta: +# model=Appointment +# fields=('__all__') -class PrescriptionSerializer(serializers.ModelSerializer): +# class PrescriptionSerializer(serializers.ModelSerializer): - class Meta: - model=Prescription - fields=('__all__') +# class Meta: +# model=Prescription +# fields=('__all__') -class PrescribedMedicineSerializer(serializers.ModelSerializer): +# class PrescribedMedicineSerializer(serializers.ModelSerializer): - class Meta: - model=Prescribed_medicine - fields=('__all__') +# class Meta: +# model=Prescribed_medicine +# fields=('__all__') -class AmbulanceRequestSerializer(serializers.ModelSerializer): +# class AmbulanceRequestSerializer(serializers.ModelSerializer): - class Meta: - model=Ambulance_request - fields=('__all__') +# class Meta: +# model=Ambulance_request +# fields=('__all__') -class HospitalAdmitSerializer(serializers.ModelSerializer): +# class HospitalAdmitSerializer(serializers.ModelSerializer): - class Meta: - model=Hospital_admit - fields=('__all__') +# class Meta: +# model=Hospital_admit +# fields=('__all__') -class MedicalReliefSerializer(serializers.ModelSerializer): +# class MedicalReliefSerializer(serializers.ModelSerializer): - class Meta: - model=medical_relief - fields=('__all__') \ No newline at end of file +# class Meta: +# model=medical_relief +# fields=('__all__') \ No newline at end of file diff --git a/FusionIIIT/applications/health_center/api/urls.py b/FusionIIIT/applications/health_center/api/urls.py index 49fee2d6e..30e998166 100644 --- a/FusionIIIT/applications/health_center/api/urls.py +++ b/FusionIIIT/applications/health_center/api/urls.py @@ -4,8 +4,8 @@ urlpatterns = [ - url(r'^compounder/$', views.compounder_view_api, name='compounder_view_api'), - url(r'^compounder/request$', views.compounder_request_api , name='compounder_request_api'), - url(r'^student/$', views.student_view_api, name='student_view'), - url(r'^student/request$', views.student_request_api, name='student_request_api') + # url(r'^compounder/$', views.compounder_view_api, name='compounder_view_api'), + # url(r'^compounder/request$', views.compounder_request_api , name='compounder_request_api'), + # url(r'^student/$', views.student_view_api, name='student_view'), + # url(r'^student/request$', views.student_request_api, name='student_request_api') ] \ No newline at end of file diff --git a/FusionIIIT/applications/health_center/api/views.py b/FusionIIIT/applications/health_center/api/views.py index a3f8b1c67..d900c1461 100644 --- a/FusionIIIT/applications/health_center/api/views.py +++ b/FusionIIIT/applications/health_center/api/views.py @@ -1,407 +1,407 @@ -from django.contrib.auth import get_user_model -from django.shortcuts import get_object_or_404, redirect -from applications.globals.models import ExtraInfo, HoldsDesignation, Designation, DepartmentInfo -from applications.health_center.models import * -from datetime import datetime, timedelta, time,date -from django.db import transaction -from notification.views import healthcare_center_notif -from rest_framework.permissions import IsAuthenticated -from rest_framework.authentication import TokenAuthentication -from rest_framework import status -from rest_framework.decorators import api_view, permission_classes,authentication_classes -from rest_framework.permissions import AllowAny -from rest_framework.response import Response +# from django.contrib.auth import get_user_model +# from django.shortcuts import get_object_or_404, redirect +# from applications.globals.models import ExtraInfo, HoldsDesignation, Designation, DepartmentInfo +# from applications.health_center.models import * +# from datetime import datetime, timedelta, time,date +# from django.db import transaction +# from notification.views import healthcare_center_notif +# from rest_framework.permissions import IsAuthenticated +# from rest_framework.authentication import TokenAuthentication +# from rest_framework import status +# from rest_framework.decorators import api_view, permission_classes,authentication_classes +# from rest_framework.permissions import AllowAny +# from rest_framework.response import Response -from . import serializers +# from . import serializers -from notifications.models import Notification +# from notifications.models import Notification -User = get_user_model() +# User = get_user_model() -def getDesignation(request): - user = request.user - design = HoldsDesignation.objects.select_related('user','designation').filter(working=user) +# def getDesignation(request): +# user = request.user +# design = HoldsDesignation.objects.select_related('user','designation').filter(working=user) - designation=[] +# designation=[] - if str(user.extrainfo.user_type) == "student": - designation.append(str(user.extrainfo.user_type)) +# if str(user.extrainfo.user_type) == "student": +# designation.append(str(user.extrainfo.user_type)) - for i in design: - if str(i.designation) != str(user.extrainfo.user_type): - # print('-------') - # print(i.designation) - # print(user.extrainfo.user_type) - # print('') - designation.append(str(i.designation)) - # for i in designation: - # print(i) - return designation +# for i in design: +# if str(i.designation) != str(user.extrainfo.user_type): +# # print('-------') +# # print(i.designation) +# # print(user.extrainfo.user_type) +# # print('') +# designation.append(str(i.designation)) +# # for i in designation: +# # print(i) +# return designation -@api_view(['POST','DELETE']) -def student_request_api(request): - # design=request.session['currentDesignationSelected'] - usertype = ExtraInfo.objects.get(user=request.user).user_type - design = getDesignation(request) - if 'student' in design or 'Compounder' not in design: - # if design == 'student' or usertype == 'faculty' or usertype == 'staff': - # if 'ambulancerequest' in request.data and request.method=='POST': - # comp_id = ExtraInfo.objects.filter(user_type='compounder') - # request.data['user_id'] = get_object_or_404(User,username=request.user.username) - # request.data['date_request']=datetime.now() - # serializer = serializers.AmbulanceRequestSerializer(data=request.data) - # if serializer.is_valid(): - # serializer.save() - # healthcare_center_notif(request.user, request.user, 'amb_request') - # for cmp in comp_id: - # healthcare_center_notif(request.user, cmp.user, 'amb_req') - # return Response(serializer.data, status=status.HTTP_201_CREATED) - # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +# @api_view(['POST','DELETE']) +# def student_request_api(request): +# # design=request.session['currentDesignationSelected'] +# usertype = ExtraInfo.objects.get(user=request.user).user_type +# design = getDesignation(request) +# if 'student' in design or 'Compounder' not in design: +# # if design == 'student' or usertype == 'faculty' or usertype == 'staff': +# # if 'ambulancerequest' in request.data and request.method=='POST': +# # comp_id = ExtraInfo.objects.filter(user_type='compounder') +# # request.data['user_id'] = get_object_or_404(User,username=request.user.username) +# # request.data['date_request']=datetime.now() +# # serializer = serializers.AmbulanceRequestSerializer(data=request.data) +# # if serializer.is_valid(): +# # serializer.save() +# # healthcare_center_notif(request.user, request.user, 'amb_request') +# # for cmp in comp_id: +# # healthcare_center_notif(request.user, cmp.user, 'amb_req') +# # return Response(serializer.data, status=status.HTTP_201_CREATED) +# # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - # elif 'ambulancecancel' in request.data and request.method == 'DELETE': - # try: - # amb_id=int(request.data['amb_id']) - # except: - # return Response({'message': 'Please enter ambulance id'}, status=status.HTTP_404_NOT_FOUND) - # ambulance = get_object_or_404(Ambulance_request,pk=amb_id) - # ambulance.delete() - # resp = {'message': 'ambulance request is cancelled'} - # return Response(data=resp,status=status.HTTP_200_OK) +# # elif 'ambulancecancel' in request.data and request.method == 'DELETE': +# # try: +# # amb_id=int(request.data['amb_id']) +# # except: +# # return Response({'message': 'Please enter ambulance id'}, status=status.HTTP_404_NOT_FOUND) +# # ambulance = get_object_or_404(Ambulance_request,pk=amb_id) +# # ambulance.delete() +# # resp = {'message': 'ambulance request is cancelled'} +# # return Response(data=resp,status=status.HTTP_200_OK) - # elif 'appointmentadd' in request.data and request.method == 'POST': - # request.data['user_id'] = get_object_or_404(User,username=request.user.username) - # try: - # day = datetime.strptime(request.data['date'], "%Y-%m-%d").weekday() - # except: - # return Response({'message': 'Please enter valid date'}, status=status.HTTP_404_NOT_FOUND) - # try: - # doctor_id = request.data['doctor_id'] - # except: - # return Response({'message': 'Please enter doctor id'}, status=status.HTTP_404_NOT_FOUND) - # request.data['schedule'] =get_object_or_404(Doctors_Schedule,doctor_id=request.data['doctor_id'],day=day).id - # comp_id = ExtraInfo.objects.filter(user_type='compounder') - # serializer = serializers.AppointmentSerializer(data=request.data) - # if serializer.is_valid(): - # serializer.save() - # healthcare_center_notif(request.user, request.user, 'appoint') - # for cmp in comp_id: - # healthcare_center_notif(request.user, cmp.user, 'appoint_req') - # return Response(serializer.data, status=status.HTTP_201_CREATED) - # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +# # elif 'appointmentadd' in request.data and request.method == 'POST': +# # request.data['user_id'] = get_object_or_404(User,username=request.user.username) +# # try: +# # day = datetime.strptime(request.data['date'], "%Y-%m-%d").weekday() +# # except: +# # return Response({'message': 'Please enter valid date'}, status=status.HTTP_404_NOT_FOUND) +# # try: +# # doctor_id = request.data['doctor_id'] +# # except: +# # return Response({'message': 'Please enter doctor id'}, status=status.HTTP_404_NOT_FOUND) +# # request.data['schedule'] =get_object_or_404(Doctors_Schedule,doctor_id=request.data['doctor_id'],day=day).id +# # comp_id = ExtraInfo.objects.filter(user_type='compounder') +# # serializer = serializers.AppointmentSerializer(data=request.data) +# # if serializer.is_valid(): +# # serializer.save() +# # healthcare_center_notif(request.user, request.user, 'appoint') +# # for cmp in comp_id: +# # healthcare_center_notif(request.user, cmp.user, 'appoint_req') +# # return Response(serializer.data, status=status.HTTP_201_CREATED) +# # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - # elif 'appointmentdelete' in request.data and request.method == 'DELETE': - # try: - # app_id = request.data['app_id'] - # except: - # return Response({'message': 'Please enter valid appointment id'}, status=status.HTTP_404_NOT_FOUND) - # appointment=get_object_or_404(Appointment,pk=app_id) - # appointment.delete() - # resp = {'message': 'Your appointment is cancelled'} - # return Response(data=resp,status=status.HTTP_200_OK) +# # elif 'appointmentdelete' in request.data and request.method == 'DELETE': +# # try: +# # app_id = request.data['app_id'] +# # except: +# # return Response({'message': 'Please enter valid appointment id'}, status=status.HTTP_404_NOT_FOUND) +# # appointment=get_object_or_404(Appointment,pk=app_id) +# # appointment.delete() +# # resp = {'message': 'Your appointment is cancelled'} +# # return Response(data=resp,status=status.HTTP_200_OK) - if 'complaintadd' in request.data and request.method == 'POST': - request.data['user_id'] = get_object_or_404(User,username=request.user.username) - serializer = serializers.ComplaintSerializer(data=request.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) - else: - resp = {'message': 'invalid request'} - return Response(data=resp,status=status.HTTP_404_NOT_FOUND) +# if 'complaintadd' in request.data and request.method == 'POST': +# request.data['user_id'] = get_object_or_404(User,username=request.user.username) +# serializer = serializers.ComplaintSerializer(data=request.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) +# else: +# resp = {'message': 'invalid request'} +# return Response(data=resp,status=status.HTTP_404_NOT_FOUND) - elif 'Compounder' in design: - return redirect('/healthcenter/api/compounder/request/') - else: - resp = {'message': 'invalid request'} - return Response(data=resp,status=status.HTTP_404_NOT_FOUND) +# elif 'Compounder' in design: +# return redirect('/healthcenter/api/compounder/request/') +# else: +# resp = {'message': 'invalid request'} +# return Response(data=resp,status=status.HTTP_404_NOT_FOUND) -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -@authentication_classes([TokenAuthentication]) -def student_view_api(request): - # student view starts here - # design=request.session['currentDesignationSelected'] - # usertype = ExtraInfo.objects.get(user=request.user).user_type - design = getDesignation(request) - if 'student' in design or 'Compounder' not in design: - # users = ExtraInfo.objects.all() - user_id = ExtraInfo.objects.get(user=request.user) - # hospitals = serializers.HospitalAdmitSerializer(Hospital_admit.objects.filter(user_id=user_id).order_by('-admission_date'),many=True).data - # appointments = serializers.AppointmentSerializer(Appointment.objects.filter(user_id=user_id).order_by('-date'),many=True).data - # ambulances = serializers.AmbulanceRequestSerializer(Ambulance_request.objects.filter(user_id=user_id).order_by('-date_request'),many=True).data - prescription = serializers.PrescriptionSerializer(Prescription.objects.filter(user_id=user_id).order_by('-date'),many=True).data - medicines_presc = serializers.PrescribedMedicineSerializer(Prescribed_medicine.objects.all(),many=True).data - complaints = serializers.ComplaintSerializer(Complaint.objects.filter(user_id=user_id).order_by('-date'),many=True).data - days = Constants.DAYS_OF_WEEK - # schedule=serializers.ScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data - doctor_schedule=serializers.DoctorsScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data - pathologist_schedule=serializers.PathologistScheduleSerializer(Pathologist_Schedule.objects.all().order_by('pathologist_id'), many=True).data - doctors=serializers.DoctorSerializer(Doctor.objects.filter(active=True),many=True).data - pathologists=serializers.PathologistSerializer(Pathologist.objects.filter(active=True),many=True).data - count=Counter.objects.all() - if count: - Counter.objects.all().delete() - Counter.objects.create(count=0,fine=0) - count= serializers.CounterSerializer(Counter.objects.get()).data - resp={ - 'complaints': complaints, - 'medicines_presc': medicines_presc, - # 'ambulances': ambulances, - 'doctors': doctors, - 'pathologists': pathologists, - 'days': days, - 'count':count, - # 'hospitals': hospitals, - # 'appointments': appointments, - 'prescription': prescription, - # 'schedule': schedule - 'doctor_schedule': doctor_schedule, - 'pathologist_schedule': pathologist_schedule, - } - return Response(data=resp,status=status.HTTP_200_OK) - elif 'Compounder' in design: - return redirect('/healthcenter/api/compounder/') - else: - resp = {'message': 'invalid request'} - return Response(data=resp,status=status.HTTP_404_NOT_FOUND) +# @api_view(['GET']) +# @permission_classes([IsAuthenticated]) +# @authentication_classes([TokenAuthentication]) +# def student_view_api(request): +# # student view starts here +# # design=request.session['currentDesignationSelected'] +# # usertype = ExtraInfo.objects.get(user=request.user).user_type +# design = getDesignation(request) +# if 'student' in design or 'Compounder' not in design: +# # users = ExtraInfo.objects.all() +# user_id = ExtraInfo.objects.get(user=request.user) +# # hospitals = serializers.HospitalAdmitSerializer(Hospital_admit.objects.filter(user_id=user_id).order_by('-admission_date'),many=True).data +# # appointments = serializers.AppointmentSerializer(Appointment.objects.filter(user_id=user_id).order_by('-date'),many=True).data +# # ambulances = serializers.AmbulanceRequestSerializer(Ambulance_request.objects.filter(user_id=user_id).order_by('-date_request'),many=True).data +# prescription = serializers.PrescriptionSerializer(Prescription.objects.filter(user_id=user_id).order_by('-date'),many=True).data +# medicines_presc = serializers.PrescribedMedicineSerializer(Prescribed_medicine.objects.all(),many=True).data +# complaints = serializers.ComplaintSerializer(Complaint.objects.filter(user_id=user_id).order_by('-date'),many=True).data +# days = Constants.DAYS_OF_WEEK +# # schedule=serializers.ScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data +# doctor_schedule=serializers.DoctorsScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data +# pathologist_schedule=serializers.PathologistScheduleSerializer(Pathologist_Schedule.objects.all().order_by('pathologist_id'), many=True).data +# doctors=serializers.DoctorSerializer(Doctor.objects.filter(active=True),many=True).data +# pathologists=serializers.PathologistSerializer(Pathologist.objects.filter(active=True),many=True).data +# count=Counter.objects.all() +# if count: +# Counter.objects.all().delete() +# Counter.objects.create(count=0,fine=0) +# count= serializers.CounterSerializer(Counter.objects.get()).data +# resp={ +# 'complaints': complaints, +# 'medicines_presc': medicines_presc, +# # 'ambulances': ambulances, +# 'doctors': doctors, +# 'pathologists': pathologists, +# 'days': days, +# 'count':count, +# # 'hospitals': hospitals, +# # 'appointments': appointments, +# 'prescription': prescription, +# # 'schedule': schedule +# 'doctor_schedule': doctor_schedule, +# 'pathologist_schedule': pathologist_schedule, +# } +# return Response(data=resp,status=status.HTTP_200_OK) +# elif 'Compounder' in design: +# return redirect('/healthcenter/api/compounder/') +# else: +# resp = {'message': 'invalid request'} +# return Response(data=resp,status=status.HTTP_404_NOT_FOUND) -@api_view(['POST','PATCH','DELETE']) -@permission_classes([IsAuthenticated]) -@authentication_classes([TokenAuthentication]) -def compounder_request_api(request): - design = getDesignation(request) - if 'Compounder' in design: - if 'doctoradd' in request.data and request.method == 'POST': - request.data['active']=True - serializer = serializers.DoctorSerializer(data=request.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) +# @api_view(['POST','PATCH','DELETE']) +# @permission_classes([IsAuthenticated]) +# @authentication_classes([TokenAuthentication]) +# def compounder_request_api(request): +# design = getDesignation(request) +# if 'Compounder' in design: +# if 'doctoradd' in request.data and request.method == 'POST': +# request.data['active']=True +# serializer = serializers.DoctorSerializer(data=request.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) - elif 'doctorremove' in request.data and request.method == 'PATCH': - try: - doctor=request.data['id'] - except: - return Response({'message': 'Please enter valid doctor id'}, status=status.HTTP_404_NOT_FOUND) - request.data['active']=False - doctor= get_object_or_404(Doctor,id=doctor) - serializer = serializers.DoctorSerializer(doctor,data=request.data,partial=True) - 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) +# elif 'doctorremove' in request.data and request.method == 'PATCH': +# try: +# doctor=request.data['id'] +# except: +# return Response({'message': 'Please enter valid doctor id'}, status=status.HTTP_404_NOT_FOUND) +# request.data['active']=False +# doctor= get_object_or_404(Doctor,id=doctor) +# serializer = serializers.DoctorSerializer(doctor,data=request.data,partial=True) +# 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) - elif 'doctorscheduleadd' in request.data and request.method == 'POST': - try: - doctor_id = int(request.data['doctor_id']) - except: - return Response({'message': 'Please enter valid doctor id'}, status=status.HTTP_404_NOT_FOUND) - try: - day = request.data['day'] - except: - return Response({'message': 'Please enter valid day'}, status=status.HTTP_404_NOT_FOUND) - sc = Doctor.objects.filter(doctor_id=doctor_id, day=day) - if sc.count() == 0: - serializer = serializers.DoctorsScheduleSerializer(data=request.data) - else: - sc = get_object_or_404(Doctors_Schedule,doctor_id=doctor_id,day=day) - serializer = serializers.DoctorsScheduleSerializer(sc,data=request.data,partial=True) - 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) +# elif 'doctorscheduleadd' in request.data and request.method == 'POST': +# try: +# doctor_id = int(request.data['doctor_id']) +# except: +# return Response({'message': 'Please enter valid doctor id'}, status=status.HTTP_404_NOT_FOUND) +# try: +# day = request.data['day'] +# except: +# return Response({'message': 'Please enter valid day'}, status=status.HTTP_404_NOT_FOUND) +# sc = Doctor.objects.filter(doctor_id=doctor_id, day=day) +# if sc.count() == 0: +# serializer = serializers.DoctorsScheduleSerializer(data=request.data) +# else: +# sc = get_object_or_404(Doctors_Schedule,doctor_id=doctor_id,day=day) +# serializer = serializers.DoctorsScheduleSerializer(sc,data=request.data,partial=True) +# 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) - elif 'doctorscheduleremove' in request.data and request.method == 'DELETE': - try: - doctor_id = request.data['doctor_id'] - except: - return Response({'message': 'Please enter valid doctor id'}, status=status.HTTP_404_NOT_FOUND) - try: - day = request.data['day'] - except: - return Response({'message': 'Please enter valid day'}, status=status.HTTP_404_NOT_FOUND) - sc = get_object_or_404(Doctors_Schedule,doctor_id=doctor_id,day=day) - sc.delete() - resp={'message':'Schedule Deleted successfully'} - return Response(data=resp,status=status.HTTP_200_OK) +# elif 'doctorscheduleremove' in request.data and request.method == 'DELETE': +# try: +# doctor_id = request.data['doctor_id'] +# except: +# return Response({'message': 'Please enter valid doctor id'}, status=status.HTTP_404_NOT_FOUND) +# try: +# day = request.data['day'] +# except: +# return Response({'message': 'Please enter valid day'}, status=status.HTTP_404_NOT_FOUND) +# sc = get_object_or_404(Doctors_Schedule,doctor_id=doctor_id,day=day) +# sc.delete() +# resp={'message':'Schedule Deleted successfully'} +# return Response(data=resp,status=status.HTTP_200_OK) - # elif 'hospitaladmit' in request.data and request.method == 'POST': - # serializer = serializers.HospitalAdmitSerializer(data=request.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) +# # elif 'hospitaladmit' in request.data and request.method == 'POST': +# # serializer = serializers.HospitalAdmitSerializer(data=request.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) - # elif 'hospitaldischarge' in request.data and request.method == 'PATCH': - # try: - # pk = request.data['id'] - # except: - # return Response({'message': 'Please enter valid id'}, status=status.HTTP_404_NOT_FOUND) - # request.data['discharge_date']=date.today() - # Ha = get_object_or_404(Hospital_admit,id=pk) - # serializer = serializers.HospitalAdmitSerializer(Ha,data=request.data,partial=True) - # 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) +# # elif 'hospitaldischarge' in request.data and request.method == 'PATCH': +# # try: +# # pk = request.data['id'] +# # except: +# # return Response({'message': 'Please enter valid id'}, status=status.HTTP_404_NOT_FOUND) +# # request.data['discharge_date']=date.today() +# # Ha = get_object_or_404(Hospital_admit,id=pk) +# # serializer = serializers.HospitalAdmitSerializer(Ha,data=request.data,partial=True) +# # 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) - elif 'medicineadd' in request.data and request.method =='POST': - stock = serializers.StockSerializer(data=request.data) - if stock.is_valid(): - stock.save() - else: - return Response(stock.errors,status=status.HTTP_400_BAD_REQUEST) - request.data['medicine_id'] = (Stock.objects.get(medicine_name=request.data['medicine_name'])).id - expiry = serializers.ExpirySerializer(data=request.data) - if expiry.is_valid(): - expiry.save() - else: - return Response(expiry.errors,status=status.HTTP_400_BAD_REQUEST) - return Response(stock.data,status=status.HTTP_201_CREATED) +# elif 'medicineadd' in request.data and request.method =='POST': +# stock = serializers.StockSerializer(data=request.data) +# if stock.is_valid(): +# stock.save() +# else: +# return Response(stock.errors,status=status.HTTP_400_BAD_REQUEST) +# request.data['medicine_id'] = (Stock.objects.get(medicine_name=request.data['medicine_name'])).id +# expiry = serializers.ExpirySerializer(data=request.data) +# if expiry.is_valid(): +# expiry.save() +# else: +# return Response(expiry.errors,status=status.HTTP_400_BAD_REQUEST) +# return Response(stock.data,status=status.HTTP_201_CREATED) - elif 'stockadd' in request.data and request.method == 'POST': - serializer = serializers.ExpirySerializer(data=request.data) - if serializer.is_valid(): - serializer.save() - else: - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - quantity = (Stock.objects.get(id=request.data['medicine_id'])).quantity - quantity = quantity + int(request.data['quantity']) - stock = get_object_or_404(Stock,id=request.data['medicine_id']) - serializer = serializers.StockSerializer(stock,data={'quantity': quantity,'threshold':request.data['threshold']},partial=True) - if serializer.is_valid(): - serializer.save() - else: - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - resp = {'message': 'stock added successfully'} - return Response(data=resp,status=status.HTTP_200_OK) +# elif 'stockadd' in request.data and request.method == 'POST': +# serializer = serializers.ExpirySerializer(data=request.data) +# if serializer.is_valid(): +# serializer.save() +# else: +# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +# quantity = (Stock.objects.get(id=request.data['medicine_id'])).quantity +# quantity = quantity + int(request.data['quantity']) +# stock = get_object_or_404(Stock,id=request.data['medicine_id']) +# serializer = serializers.StockSerializer(stock,data={'quantity': quantity,'threshold':request.data['threshold']},partial=True) +# if serializer.is_valid(): +# serializer.save() +# else: +# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +# resp = {'message': 'stock added successfully'} +# return Response(data=resp,status=status.HTTP_200_OK) - elif 'prescriptionsubmit' in request.data and request.method == 'POST': - serializer = serializers.PrescriptionSerializer(data=request.data) - user = ExtraInfo.objects.get(id=request.data['user_id']) - if serializer.is_valid(): - serializer.save() - healthcare_center_notif(request.user, user.user, 'Presc') - return Response(serializer.data, status=status.HTTP_201_CREATED) - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +# elif 'prescriptionsubmit' in request.data and request.method == 'POST': +# serializer = serializers.PrescriptionSerializer(data=request.data) +# user = ExtraInfo.objects.get(id=request.data['user_id']) +# if serializer.is_valid(): +# serializer.save() +# healthcare_center_notif(request.user, user.user, 'Presc') +# return Response(serializer.data, status=status.HTTP_201_CREATED) +# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - elif 'prescripmedicineadd' in request.data and request.method == 'POST': - with transaction.atomic(): - medicine_id=request.data['medicine_id'] - quantity = int(request.data['quantity']) - expiry=Expiry.objects.filter(medicine_id=medicine_id,quantity__gt=0,returned=False,expiry_date__gte=date.today()).order_by('expiry_date') - stock=(Stock.objects.get(id=medicine_id)).quantity - if stock>quantity: - for e in expiry: - q=e.quantity - em=e.id - if q>quantity: - q=q-quantity - Expiry.objects.filter(id=em).update(quantity=q) - qty = Stock.objects.get(id=medicine_id).quantity - qty = qty-quantity - Stock.objects.filter(id=medicine_id).update(quantity=qty) - break - else: - quan=Expiry.objects.get(id=em).quantity - Expiry.objects.filter(id=em).update(quantity=0) - qty = Stock.objects.get(id=medicine_id).quantity - qty = qty-quan - Stock.objects.filter(id=medicine_id).update(quantity=qty) - quantity=quantity-quan - serializer = serializers.PrescribedMedicineSerializer(data=request.data) - if serializer.is_valid(): - serializer.save() - return Response(serializer.data,status=status.HTTP_200_OK) - else: - transaction.set_rollback(True) - return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST) - else: - resp= {'message': 'Required Medicines is not available'} - return Response(data=resp,status=status.HTTP_400_BAD_REQUEST) +# elif 'prescripmedicineadd' in request.data and request.method == 'POST': +# with transaction.atomic(): +# medicine_id=request.data['medicine_id'] +# quantity = int(request.data['quantity']) +# expiry=Expiry.objects.filter(medicine_id=medicine_id,quantity__gt=0,returned=False,expiry_date__gte=date.today()).order_by('expiry_date') +# stock=(Stock.objects.get(id=medicine_id)).quantity +# if stock>quantity: +# for e in expiry: +# q=e.quantity +# em=e.id +# if q>quantity: +# q=q-quantity +# Expiry.objects.filter(id=em).update(quantity=q) +# qty = Stock.objects.get(id=medicine_id).quantity +# qty = qty-quantity +# Stock.objects.filter(id=medicine_id).update(quantity=qty) +# break +# else: +# quan=Expiry.objects.get(id=em).quantity +# Expiry.objects.filter(id=em).update(quantity=0) +# qty = Stock.objects.get(id=medicine_id).quantity +# qty = qty-quan +# Stock.objects.filter(id=medicine_id).update(quantity=qty) +# quantity=quantity-quan +# serializer = serializers.PrescribedMedicineSerializer(data=request.data) +# if serializer.is_valid(): +# serializer.save() +# return Response(serializer.data,status=status.HTTP_200_OK) +# else: +# transaction.set_rollback(True) +# return Response(serializer.errors,status=status.HTTP_400_BAD_REQUEST) +# else: +# resp= {'message': 'Required Medicines is not available'} +# return Response(data=resp,status=status.HTTP_400_BAD_REQUEST) - elif 'complaintresponse' in request.data and request.method == 'PATCH': - try: - pk = request.data['complaint_id'] - except: - return Response({'message': 'Please enter valid complaint id'}, status=status.HTTP_404_NOT_FOUND) - try: - complain = Complaint.objects.get(id = pk) - except Complaint.DoesNotExist: - return Response({'message': 'Complaint does not exist'}, status=status.HTTP_404_NOT_FOUND) - serializer = serializers.ComplaintSerializer(complain,data=request.data,partial=True) - 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) - else: - resp = {'message': 'invalid request'} - return Response(data=resp,status=status.HTTP_404_NOT_FOUND) +# elif 'complaintresponse' in request.data and request.method == 'PATCH': +# try: +# pk = request.data['complaint_id'] +# except: +# return Response({'message': 'Please enter valid complaint id'}, status=status.HTTP_404_NOT_FOUND) +# try: +# complain = Complaint.objects.get(id = pk) +# except Complaint.DoesNotExist: +# return Response({'message': 'Complaint does not exist'}, status=status.HTTP_404_NOT_FOUND) +# serializer = serializers.ComplaintSerializer(complain,data=request.data,partial=True) +# 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) +# else: +# resp = {'message': 'invalid request'} +# return Response(data=resp,status=status.HTTP_404_NOT_FOUND) - else: - resp = {'message': 'invalid request'} - return Response(data=resp,status=status.HTTP_404_NOT_FOUND) +# else: +# resp = {'message': 'invalid request'} +# return Response(data=resp,status=status.HTTP_404_NOT_FOUND) -@api_view(['GET']) -@permission_classes([IsAuthenticated]) -@authentication_classes([TokenAuthentication]) -def compounder_view_api(request): # compounder view starts here - # usertype = ExtraInfo.objects.get(user=request.user).user_type - design = getDesignation(request) - if 'Compounder' in design: - all_complaints = serializers.ComplaintSerializer(Complaint.objects.all(),many=True).data - # all_hospitals = serializers.HospitalAdmitSerializer(Hospital_admit.objects.all().order_by('-admission_date'),many=True).data - # hospitals_list = serializers.HospitalSerializer(Hospital.objects.all().order_by('hospital_name'),many=True).data - # all_ambulances = serializers.AmbulanceRequestSerializer(Ambulance_request.objects.all().order_by('-date_request'),many=True).data - # appointments_today = serializers.AppointmentSerializer(Appointment.objects.filter(date=datetime.now()).order_by('date'),many=True).data - # appointments_future= serializers.AppointmentSerializer(Appointment.objects.filter(date__gt=datetime.now()).order_by('date'),many=True).data - stocks = serializers.StockSerializer(Stock.objects.all(),many=True).data - days = Constants.DAYS_OF_WEEK - # schedule= serializers.ScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data - expired= serializers.ExpirySerializer(Expiry.objects.filter(expiry_date__lt=datetime.now(),returned=False).order_by('expiry_date'),many=True).data - live_meds= serializers.ExpirySerializer(Expiry.objects.filter(returned=False).order_by('quantity'),many=True).data - count= Counter.objects.all() - presc_hist= serializers.PrescriptionSerializer(Prescription.objects.all().order_by('-date'),many=True).data - medicines_presc= serializers.PrescribedMedicineSerializer(Prescribed_medicine.objects.all(),many=True).data +# @api_view(['GET']) +# @permission_classes([IsAuthenticated]) +# @authentication_classes([TokenAuthentication]) +# def compounder_view_api(request): # compounder view starts here +# # usertype = ExtraInfo.objects.get(user=request.user).user_type +# design = getDesignation(request) +# if 'Compounder' in design: +# all_complaints = serializers.ComplaintSerializer(Complaint.objects.all(),many=True).data +# # all_hospitals = serializers.HospitalAdmitSerializer(Hospital_admit.objects.all().order_by('-admission_date'),many=True).data +# # hospitals_list = serializers.HospitalSerializer(Hospital.objects.all().order_by('hospital_name'),many=True).data +# # all_ambulances = serializers.AmbulanceRequestSerializer(Ambulance_request.objects.all().order_by('-date_request'),many=True).data +# # appointments_today = serializers.AppointmentSerializer(Appointment.objects.filter(date=datetime.now()).order_by('date'),many=True).data +# # appointments_future= serializers.AppointmentSerializer(Appointment.objects.filter(date__gt=datetime.now()).order_by('date'),many=True).data +# stocks = serializers.StockSerializer(Stock.objects.all(),many=True).data +# days = Constants.DAYS_OF_WEEK +# # schedule= serializers.ScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data +# expired= serializers.ExpirySerializer(Expiry.objects.filter(expiry_date__lt=datetime.now(),returned=False).order_by('expiry_date'),many=True).data +# live_meds= serializers.ExpirySerializer(Expiry.objects.filter(returned=False).order_by('quantity'),many=True).data +# count= Counter.objects.all() +# presc_hist= serializers.PrescriptionSerializer(Prescription.objects.all().order_by('-date'),many=True).data +# medicines_presc= serializers.PrescribedMedicineSerializer(Prescribed_medicine.objects.all(),many=True).data - if count: - Counter.objects.all().delete() - Counter.objects.create(count=0,fine=0) - count= serializers.CounterSerializer(Counter.objects.get()).data - # hospitals=serializers.HospitalSerializer(Hospital.objects.all(),many=True).data - doctor_schedule=serializers.DoctorsScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data - pathologist_schedule=serializers.PathologistScheduleSerializer(Pathologist_Schedule.objects.all().order_by('pathologist_id'), many=True).data - doctors=serializers.DoctorSerializer(Doctor.objects.filter(active=True),many=True).data - pathologists=serializers.PathologistSerializer(Pathologist.objects.filter(active=True),many=True).data +# if count: +# Counter.objects.all().delete() +# Counter.objects.create(count=0,fine=0) +# count= serializers.CounterSerializer(Counter.objects.get()).data +# # hospitals=serializers.HospitalSerializer(Hospital.objects.all(),many=True).data +# doctor_schedule=serializers.DoctorsScheduleSerializer(Doctors_Schedule.objects.all().order_by('doctor_id'),many=True).data +# pathologist_schedule=serializers.PathologistScheduleSerializer(Pathologist_Schedule.objects.all().order_by('pathologist_id'), many=True).data +# doctors=serializers.DoctorSerializer(Doctor.objects.filter(active=True),many=True).data +# pathologists=serializers.PathologistSerializer(Pathologist.objects.filter(active=True),many=True).data - resp= { - 'days': days, - 'count': count, - 'expired':expired, - 'stocks': stocks, - 'all_complaints': all_complaints, - # 'all_hospitals': all_hospitals, - # 'hospitals':hospitals, - # 'all_ambulances': all_ambulances, - # 'appointments_today': appointments_today, - 'doctors': doctors, - # 'appointments_future': appointments_future, - # 'schedule': schedule, - 'doctor_schedule': doctor_schedule, - 'pathologist_schedule': pathologist_schedule, - 'pathologists': pathologists, - 'live_meds': live_meds, - 'presc_hist': presc_hist, - 'medicines_presc': medicines_presc, - # 'hospitals_list': hospitals_list - } - return Response(data=resp,status=status.HTTP_200_OK) +# resp= { +# 'days': days, +# 'count': count, +# 'expired':expired, +# 'stocks': stocks, +# 'all_complaints': all_complaints, +# # 'all_hospitals': all_hospitals, +# # 'hospitals':hospitals, +# # 'all_ambulances': all_ambulances, +# # 'appointments_today': appointments_today, +# 'doctors': doctors, +# # 'appointments_future': appointments_future, +# # 'schedule': schedule, +# 'doctor_schedule': doctor_schedule, +# 'pathologist_schedule': pathologist_schedule, +# 'pathologists': pathologists, +# 'live_meds': live_meds, +# 'presc_hist': presc_hist, +# 'medicines_presc': medicines_presc, +# # 'hospitals_list': hospitals_list +# } +# return Response(data=resp,status=status.HTTP_200_OK) - else: - resp = {'message': 'invalid request'} - return Response(data=resp,status=status.HTTP_404_NOT_FOUND) # compounder view ends \ No newline at end of file +# else: +# resp = {'message': 'invalid request'} +# return Response(data=resp,status=status.HTTP_404_NOT_FOUND) # compounder view ends \ No newline at end of file diff --git a/FusionIIIT/applications/health_center/migrations/0001_initial.py b/FusionIIIT/applications/health_center/migrations/0001_initial.py index 7dfe99418..887666ff8 100644 --- a/FusionIIIT/applications/health_center/migrations/0001_initial.py +++ b/FusionIIIT/applications/health_center/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 3.1.5 on 2024-07-16 15:44 +# Generated by Django 3.1.5 on 2024-04-27 23:48 import datetime from django.db import migrations, models diff --git a/FusionIIIT/applications/health_center/migrations/0002_auto_20240710_2356.py b/FusionIIIT/applications/health_center/migrations/0002_auto_20240710_2356.py new file mode 100644 index 000000000..9a50335f6 --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0002_auto_20240710_2356.py @@ -0,0 +1,201 @@ +# Generated by Django 3.1.5 on 2024-07-10 23:56 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='All_Medicine', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('medicine_name', models.CharField(default='NOT_SET', max_length=50)), + ('brand_name', models.CharField(default='NOT_SET', max_length=50)), + ('constituents', models.TextField(default='NOT_SET')), + ('manufacturer_name', models.CharField(default='NOT_SET', max_length=50)), + ('pack_size_label', models.CharField(default='NOT_SET', max_length=50)), + ], + ), + migrations.CreateModel( + name='All_Prescribed_medicine', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', models.IntegerField(default=0)), + ('days', models.IntegerField(default=0)), + ('times', models.IntegerField(default=0)), + ('revoked', models.BooleanField(default=False)), + ('revoked_date', models.DateField(null=True)), + ('medicine_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.all_medicine')), + ], + ), + migrations.CreateModel( + name='All_Prescription', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('user_id', models.CharField(max_length=15)), + ('details', models.TextField(null=True)), + ('date', models.DateField()), + ('suggestions', models.TextField(null=True)), + ('test', models.CharField(blank=True, max_length=200, null=True)), + ('file_id', models.IntegerField(default=0)), + ('is_dependent', models.BooleanField(default=False)), + ('dependent_name', models.CharField(default='SELF', max_length=30)), + ('dependent_relation', models.CharField(default='SELF', max_length=20)), + ('doctor_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='health_center.doctor')), + ], + ), + migrations.CreateModel( + name='Prescription_followup', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('details', models.TextField(null=True)), + ('date', models.DateField()), + ('test', models.CharField(blank=True, max_length=200, null=True)), + ('suggestions', models.TextField(null=True)), + ('file_id', models.IntegerField(default=0)), + ('Doctor_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.doctor')), + ('prescription_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.all_prescription')), + ], + ), + migrations.CreateModel( + name='Present_Stock', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', models.IntegerField(default=0)), + ], + ), + migrations.CreateModel( + name='Stock_entry', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', models.IntegerField(default=0)), + ('supplier', models.CharField(default='NOT_SET', max_length=50)), + ('Expiry_date', models.DateField()), + ('date', models.DateField(auto_now=True)), + ('medicine_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.all_medicine')), + ], + ), + migrations.RemoveField( + model_name='ambulance_request', + name='user_id', + ), + migrations.RemoveField( + model_name='announcements', + name='anno_id', + ), + migrations.RemoveField( + model_name='appointment', + name='doctor_id', + ), + migrations.RemoveField( + model_name='appointment', + name='schedule', + ), + migrations.RemoveField( + model_name='appointment', + name='user_id', + ), + migrations.RemoveField( + model_name='complaint', + name='user_id', + ), + migrations.DeleteModel( + name='Counter', + ), + migrations.RemoveField( + model_name='expiry', + name='medicine_id', + ), + migrations.RemoveField( + model_name='hospital_admit', + name='doctor_id', + ), + migrations.RemoveField( + model_name='hospital_admit', + name='hospital_name', + ), + migrations.RemoveField( + model_name='hospital_admit', + name='user_id', + ), + migrations.RemoveField( + model_name='medicine', + name='medicine_id', + ), + migrations.RemoveField( + model_name='medicine', + name='patient', + ), + migrations.RemoveField( + model_name='prescribed_medicine', + name='medicine_id', + ), + migrations.RemoveField( + model_name='prescribed_medicine', + name='prescription_id', + ), + migrations.RemoveField( + model_name='prescription', + name='doctor_id', + ), + migrations.RemoveField( + model_name='prescription', + name='user_id', + ), + migrations.RemoveField( + model_name='specialrequest', + name='request_ann_maker', + ), + migrations.DeleteModel( + name='Ambulance_request', + ), + migrations.DeleteModel( + name='Announcements', + ), + migrations.DeleteModel( + name='Appointment', + ), + migrations.DeleteModel( + name='Complaint', + ), + migrations.DeleteModel( + name='Expiry', + ), + migrations.DeleteModel( + name='Hospital', + ), + migrations.DeleteModel( + name='Hospital_admit', + ), + migrations.DeleteModel( + name='Medicine', + ), + migrations.DeleteModel( + name='Prescribed_medicine', + ), + migrations.DeleteModel( + name='Prescription', + ), + migrations.DeleteModel( + name='SpecialRequest', + ), + migrations.DeleteModel( + name='Stock', + ), + migrations.AddField( + model_name='present_stock', + name='stock_id', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.stock_entry'), + ), + migrations.AddField( + model_name='all_prescribed_medicine', + name='prescription_id', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.all_prescription'), + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0003_all_medicine_threshold.py b/FusionIIIT/applications/health_center/migrations/0003_all_medicine_threshold.py new file mode 100644 index 000000000..bfc404d98 --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0003_all_medicine_threshold.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2024-07-11 15:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0002_auto_20240710_2356'), + ] + + operations = [ + migrations.AddField( + model_name='all_medicine', + name='threshold', + field=models.IntegerField(default=100), + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0004_auto_20240713_1159.py b/FusionIIIT/applications/health_center/migrations/0004_auto_20240713_1159.py new file mode 100644 index 000000000..bed6b2da1 --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0004_auto_20240713_1159.py @@ -0,0 +1,32 @@ +# Generated by Django 3.1.5 on 2024-07-13 11:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0003_all_medicine_threshold'), + ] + + operations = [ + migrations.AddField( + model_name='all_prescribed_medicine', + name='stock', + field=models.ForeignKey(default='1', on_delete=django.db.models.deletion.CASCADE, to='health_center.present_stock'), + preserve_default=False, + ), + migrations.AddField( + model_name='present_stock', + name='Expiry_date', + field=models.DateField(default='2024-04-12'), + preserve_default=False, + ), + migrations.AddField( + model_name='present_stock', + name='medicine_id', + field=models.ForeignKey(default='1', on_delete=django.db.models.deletion.CASCADE, to='health_center.all_medicine'), + preserve_default=False, + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0005_all_prescribed_medicine_prescription_followup_id.py b/FusionIIIT/applications/health_center/migrations/0005_all_prescribed_medicine_prescription_followup_id.py new file mode 100644 index 000000000..2619ec86a --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0005_all_prescribed_medicine_prescription_followup_id.py @@ -0,0 +1,19 @@ +# Generated by Django 3.1.5 on 2024-07-15 00:19 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0004_auto_20240713_1159'), + ] + + operations = [ + migrations.AddField( + model_name='all_prescribed_medicine', + name='prescription_followup_id', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='health_center.prescription_followup'), + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0006_auto_20240717_1943.py b/FusionIIIT/applications/health_center/migrations/0006_auto_20240717_1943.py new file mode 100644 index 000000000..42e9f1974 --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0006_auto_20240717_1943.py @@ -0,0 +1,49 @@ +# Generated by Django 3.1.5 on 2024-07-17 19:43 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0005_all_prescribed_medicine_prescription_followup_id'), + ] + + operations = [ + migrations.AlterField( + model_name='all_medicine', + name='brand_name', + field=models.CharField(default='NOT_SET', max_length=1000, null=True), + ), + migrations.AlterField( + model_name='all_medicine', + name='constituents', + field=models.TextField(default='NOT_SET', null=True), + ), + migrations.AlterField( + model_name='all_medicine', + name='manufacturer_name', + field=models.CharField(default='NOT_SET', max_length=1000, null=True), + ), + migrations.AlterField( + model_name='all_medicine', + name='medicine_name', + field=models.CharField(default='NOT_SET', max_length=1000, null=True), + ), + migrations.AlterField( + model_name='all_medicine', + name='pack_size_label', + field=models.CharField(default='NOT_SET', max_length=1000, null=True), + ), + migrations.AlterField( + model_name='all_medicine', + name='threshold', + field=models.IntegerField(default=0, null=True), + ), + migrations.AlterField( + model_name='prescription_followup', + name='Doctor_id', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='health_center.doctor'), + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0007_auto_20240719_0031.py b/FusionIIIT/applications/health_center/migrations/0007_auto_20240719_0031.py new file mode 100644 index 000000000..cbc2ab6fa --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0007_auto_20240719_0031.py @@ -0,0 +1,26 @@ +# Generated by Django 3.1.5 on 2024-07-19 00:31 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0006_auto_20240717_1943'), + ] + + operations = [ + migrations.CreateModel( + name='files', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file_data', models.BinaryField()), + ], + ), + migrations.AddField( + model_name='all_prescribed_medicine', + name='revoked_priscription', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='revoked_priscription', to='health_center.prescription_followup'), + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0008_required_medicine.py b/FusionIIIT/applications/health_center/migrations/0008_required_medicine.py new file mode 100644 index 000000000..a21ca45da --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0008_required_medicine.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.5 on 2024-07-21 11:09 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0007_auto_20240719_0031'), + ] + + operations = [ + migrations.CreateModel( + name='Required_medicine', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', models.IntegerField()), + ('threshold', models.IntegerField()), + ('medicine_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='health_center.all_medicine')), + ], + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0009_auto_20240721_2316.py b/FusionIIIT/applications/health_center/migrations/0009_auto_20240721_2316.py new file mode 100644 index 000000000..1c604c5c3 --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0009_auto_20240721_2316.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.5 on 2024-07-21 23:16 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0008_required_medicine'), + ] + + operations = [ + migrations.RenameField( + model_name='all_prescribed_medicine', + old_name='revoked_priscription', + new_name='revoked_prescription', + ), + ] diff --git a/FusionIIIT/applications/health_center/migrations/0010_auto_20240727_2352.py b/FusionIIIT/applications/health_center/migrations/0010_auto_20240727_2352.py new file mode 100644 index 000000000..ad10be188 --- /dev/null +++ b/FusionIIIT/applications/health_center/migrations/0010_auto_20240727_2352.py @@ -0,0 +1,26 @@ +# Generated by Django 3.1.5 on 2024-07-27 23:52 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('health_center', '0009_auto_20240721_2316'), + ] + + operations = [ + migrations.CreateModel( + name='Required_tabel_last_updated', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date', models.DateField()), + ], + ), + migrations.AlterField( + model_name='all_prescribed_medicine', + name='stock', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='health_center.present_stock'), + ), + ] diff --git a/FusionIIIT/applications/health_center/models.py b/FusionIIIT/applications/health_center/models.py index 534abb438..7f46307f0 100644 --- a/FusionIIIT/applications/health_center/models.py +++ b/FusionIIIT/applications/health_center/models.py @@ -4,11 +4,10 @@ from django.contrib.auth.models import User from applications.globals.models import ExtraInfo - +from applications.hr2.models import EmpDependents # Create your models here. - class Constants: DAYS_OF_WEEK = ( (0, 'Monday'), @@ -50,52 +49,51 @@ class Pathologist(models.Model): def __str__(self): return self.pathologist_name +# class Complaint(models.Model): +# user_id = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) +# feedback = models.CharField(max_length=100, null=True, blank=False) #This is the feedback given by the compounder +# complaint = models.CharField(max_length=100, null=True, blank=False) #Here Complaint given by user cannot be NULL! +# date = models.DateField(auto_now=True) -class Complaint(models.Model): - user_id = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) - feedback = models.CharField(max_length=100, null=True, blank=False) #This is the feedback given by the compounder - complaint = models.CharField(max_length=100, null=True, blank=False) #Here Complaint given by user cannot be NULL! - date = models.DateField(auto_now=True) - +class All_Medicine(models.Model): + medicine_name = models.CharField(max_length=1000,default="NOT_SET", null=True) + brand_name = models.CharField(max_length=1000,default="NOT_SET", null=True) + constituents = models.TextField(default="NOT_SET", null=True) + manufacturer_name = models.CharField(max_length=1000,default="NOT_SET", null=True) + threshold = models.IntegerField(default=0, null=True) + pack_size_label = models.CharField(max_length=1000,default="NOT_SET", null=True) -class Stock(models.Model): - medicine_name = models.CharField(max_length=100) + def __str__(self): + return self.brand_name + +class Stock_entry(models.Model): + medicine_id = models.ForeignKey(All_Medicine, on_delete=models.CASCADE) quantity = models.IntegerField(default=0) - threshold = models.IntegerField(default=10) + supplier = models.CharField(max_length=50,default="NOT_SET") + Expiry_date = models.DateField() + date = models.DateField(auto_now=True) # generic_name = models.CharField(max_length=80) - def __str__(self): - return self.medicine_name + return self.medicine_id.medicine_name + +class Required_medicine(models.Model): + medicine_id = models.ForeignKey(All_Medicine,on_delete = models.CASCADE) + quantity = models.IntegerField() + threshold = models.IntegerField() -class Medicine(models.Model): - patient = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) - medicine_id = models.ForeignKey(Stock,on_delete=models.CASCADE) +class Present_Stock(models.Model): quantity = models.IntegerField(default=0) - days = models.IntegerField(default=0) - times = models.IntegerField(default=0) + stock_id = models.ForeignKey(Stock_entry,on_delete=models.CASCADE) + medicine_id = models.ForeignKey(All_Medicine, on_delete=models.CASCADE) + Expiry_date =models.DateField() - def __str__(self): - return self.medicine_id - -class Hospital(models.Model): - hospital_name=models.CharField(max_length=100) - phone=models.CharField(max_length=10) - def __str__(self): - return self.hospital_name + # generic_name = models.CharField(max_length=80) -class Expiry(models.Model): - medicine_id=models.ForeignKey(Stock,on_delete=models.CASCADE) - quantity = models.IntegerField(default=0) - supplier=models.CharField(max_length=50) - expiry_date=models.DateField() - returned=models.BooleanField(default=False) - return_date=models.DateField(null=True,blank=True) - date=models.DateField(auto_now=True) def __str__(self): - return self.medicine_id.medicine_name + return str(self.Expiry_date) class Doctors_Schedule(models.Model): doctor_id = models.ForeignKey(Doctor,on_delete=models.CASCADE) @@ -115,117 +113,48 @@ class Pathologist_Schedule(models.Model): room = models.IntegerField() date = models.DateField(auto_now=True) - -class Counter(models.Model): - count=models.IntegerField(default=0) - fine=models.IntegerField(default=0) - doc_count=models.IntegerField(default=0) - patho_count=models.IntegerField(default=0) - - def doctor_count(self): - self.doc_count+=1 - return "" - def pathologist_count(self): - self.doc_count+=1 - return "" - def increment(self): - self.count+=1 - return "" - def increment_fine(self): - self.fine+=1 - return "" - def range_count(self): - if self.count==0: - dif=0 - elif self.count<=4: - dif=self.doc_count-self.count - elif self.count<=4: - dif=self.count-self.doc_count - elif self.count<=4: - dif=self.patho_count-self.count - else: - dif=self.count-self.patho_count - return range(dif) - def empty_fine(self): - self.count=0 - self.fine=0 - return "" - def empty_count(self): - self.count=0 - return "" - -class Appointment(models.Model): - user_id = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) - doctor_id = models.ForeignKey(Doctor,on_delete=models.CASCADE) - description = models.CharField(max_length=50) - schedule = models.ForeignKey(Doctors_Schedule, on_delete=models.CASCADE,null=True, blank=True) - date = models.DateField() - - def __str__(self): - return self.description - - -class Prescription(models.Model): - user_id = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) +class All_Prescription(models.Model): + user_id = models.CharField(max_length=15) doctor_id = models.ForeignKey(Doctor, on_delete=models.CASCADE,null=True, blank=True) - details = models.CharField(max_length=100) + details = models.TextField(null=True) date = models.DateField() + suggestions = models.TextField(null=True) test = models.CharField(max_length=200, null=True, blank=True) file_id=models.IntegerField(default=0) + is_dependent = models.BooleanField(default=False) + dependent_name = models.CharField(max_length=30,default="SELF") + dependent_relation = models.CharField(max_length=20,default="SELF") # appointment = models.ForeignKey(Appointment, on_delete=models.CASCADE,null=True, blank=True) def __str__(self): - return self.details + return self.user_id - -class Prescribed_medicine(models.Model): - prescription_id = models.ForeignKey(Prescription,on_delete=models.CASCADE) - medicine_id = models.ForeignKey(Stock,on_delete=models.CASCADE) +class Prescription_followup(models.Model): + prescription_id=models.ForeignKey(All_Prescription,on_delete=models.CASCADE) + details = models.TextField(null=True) + date = models.DateField() + test = models.CharField(max_length=200, null=True, blank=True) + suggestions = models.TextField(null=True) + Doctor_id = models.ForeignKey(Doctor,on_delete=models.CASCADE, null=True, blank=True) + file_id=models.IntegerField(default=0) +class All_Prescribed_medicine(models.Model): + prescription_id = models.ForeignKey(All_Prescription,on_delete=models.CASCADE) + medicine_id = models.ForeignKey(All_Medicine,on_delete=models.CASCADE) + stock = models.ForeignKey(Present_Stock,on_delete=models.CASCADE,null=True) + prescription_followup_id = models.ForeignKey(Prescription_followup,on_delete=models.CASCADE,null=True) quantity = models.IntegerField(default=0) days = models.IntegerField(default=0) times = models.IntegerField(default=0) + revoked = models.BooleanField(default=False) + revoked_date = models.DateField(null=True) + revoked_prescription = models.ForeignKey(Prescription_followup,on_delete=models.CASCADE,null=True,related_name="revoked_priscription") def __str__(self): return self.medicine_id.medicine_name - - -class Ambulance_request(models.Model): - user_id = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) - date_request = models.DateTimeField() - start_date = models.DateField() - end_date = models.DateField(null=True, blank=True) - reason = models.CharField(max_length=50) - -class Hospital_admit(models.Model): - user_id = models.ForeignKey(ExtraInfo,on_delete=models.CASCADE) - doctor_id = models.ForeignKey(Doctor, on_delete=models.CASCADE,null=True, blank=True) - hospital_doctor = models.CharField(max_length=100) - hospital_name = models.ForeignKey(Hospital,on_delete=models.CASCADE) - admission_date = models.DateField() - discharge_date = models.DateField(null=True, blank=True) - reason = models.CharField(max_length=50) - -class Announcements(models.Model): - anno_id = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE, related_name='announcements_made') - ann_date = models.DateTimeField(default="04-04-2021") - message = models.CharField(max_length=200) - upload_announcement = models.FileField(upload_to='health_center/upload_announcement', null=True, default=" ") - def __str__(self): - return str(self.anno_id.user.username) - - -class SpecialRequest(models.Model): - request_ann_maker = models.ForeignKey(ExtraInfo, on_delete=models.CASCADE, related_name='special_requests_made') - request_date = models.DateTimeField(default=date.today) - brief = models.CharField(max_length=20, default='--') - request_details = models.CharField(max_length=200) - upload_request = models.FileField(blank=True) - status = models.CharField(max_length=50,default='Pending') - remarks = models.CharField(max_length=300, default="--") - request_receiver = models.CharField(max_length=30, default="--") - - def __str__(self): - return str(self.request_ann_maker.user.username) +class Required_tabel_last_updated(models.Model): + date=models.DateField() +class files(models.Model): + file_data = models.BinaryField() class medical_relief(models.Model): description = models.CharField(max_length=200) @@ -256,4 +185,5 @@ class MedicalProfile(models.Model): ] blood_type = models.CharField(max_length=3, choices=blood_type_choices) height = models.DecimalField(max_digits=5, decimal_places=2) - weight = models.DecimalField(max_digits=5, decimal_places=2) \ No newline at end of file + weight = models.DecimalField(max_digits=5, decimal_places=2) + diff --git a/FusionIIIT/applications/health_center/static/health_center/add_medicine_example.xlsx b/FusionIIIT/applications/health_center/static/health_center/add_medicine_example.xlsx new file mode 100644 index 000000000..a1a53eae2 Binary files /dev/null and b/FusionIIIT/applications/health_center/static/health_center/add_medicine_example.xlsx differ diff --git a/FusionIIIT/applications/health_center/static/health_center/add_stock_example.xlsx b/FusionIIIT/applications/health_center/static/health_center/add_stock_example.xlsx new file mode 100644 index 000000000..09db7915e Binary files /dev/null and b/FusionIIIT/applications/health_center/static/health_center/add_stock_example.xlsx differ diff --git a/FusionIIIT/applications/health_center/static/health_center/institute_logo.jpg b/FusionIIIT/applications/health_center/static/health_center/institute_logo.jpg new file mode 100644 index 000000000..20c7be439 Binary files /dev/null and b/FusionIIIT/applications/health_center/static/health_center/institute_logo.jpg differ diff --git a/FusionIIIT/applications/health_center/urls.py b/FusionIIIT/applications/health_center/urls.py index 2580313f9..982564fa2 100644 --- a/FusionIIIT/applications/health_center/urls.py +++ b/FusionIIIT/applications/health_center/urls.py @@ -7,10 +7,12 @@ urlpatterns = [ - #health_center home page + # health_center home page url(r'^$', healthcenter, name='healthcenter'), #views + url(r'^compounder/view_prescription/(?P[0-9]+)/$',compounder_view_prescription,name='view_prescription'), + url(r'^compounder/view_file/(?P[\w-]+)/$',view_file, name='view_file'), url(r'^compounder/$', compounder_view, name='compounder_view'), url(r'^student/$', student_view, name='student_view'), url(r'announcement/', announcement, name='announcement'), @@ -21,6 +23,6 @@ url(r'^doctor_entry', doctor_entry, name='doctor_entry'), url(r'^compounder_entry', compounder_entry, name='compounder_entry'), - #api - url(r'^api/',include('applications.health_center.api.urls')) + # #api + # url(r'^api/',include('applications.health_center.api.urls')) ] \ No newline at end of file diff --git a/FusionIIIT/applications/health_center/utils.py b/FusionIIIT/applications/health_center/utils.py index 2b20c555d..220efea76 100644 --- a/FusionIIIT/applications/health_center/utils.py +++ b/FusionIIIT/applications/health_center/utils.py @@ -1,4 +1,7 @@ import json +import os +import pandas as pd +from django.db import transaction from datetime import datetime, timedelta,date from applications.globals.models import ExtraInfo from django.core import serializers @@ -6,13 +9,16 @@ from applications.globals.models import ExtraInfo, HoldsDesignation, Designation, DepartmentInfo from django.http import HttpResponse, JsonResponse from notification.views import healthcare_center_notif -from .models import (Ambulance_request, Appointment, Complaint, Doctor, - Expiry, Hospital, Hospital_admit, Medicine, - Prescribed_medicine, Prescription, Doctors_Schedule,Pathologist_Schedule, - Stock, Announcements, SpecialRequest, Pathologist, medical_relief, MedicalProfile) +from .models import ( Doctor, Stock_entry,Present_Stock,All_Medicine, + Doctors_Schedule,Pathologist_Schedule, + Pathologist, medical_relief, MedicalProfile,All_Prescription,All_Prescribed_medicine, + Prescription_followup,files,Required_medicine) from applications.filetracking.sdk.methods import * from django.core.exceptions import ObjectDoesNotExist from django.shortcuts import get_object_or_404 +from django.db.models import Q +from applications.globals.models import ExtraInfo +from applications.hr2.models import EmpDependents def datetime_handler(date): ''' @@ -27,9 +33,8 @@ def compounder_view_handler(request): ''' handles rendering of pages for compounder view ''' - # compounder response to patients feedback - if 'feed_com' in request.POST: + if 'feed_com' in request.POST: pk = request.POST.get('com_id') feedback = request.POST.get('feed') comp_id = ExtraInfo.objects.select_related('user','department').filter(user_type='compounder') @@ -117,26 +122,75 @@ def compounder_view_handler(request): return JsonResponse(data) elif 'add_stock' in request.POST: - medicine = request.POST.get('medicine_id') - threshold_a = request.POST.get('threshold_a') - medicine_name = Stock.objects.get(id=medicine) - qty = int(request.POST.get('quantity')) - supplier=request.POST.get('supplier') - expiry=request.POST.get('expiry_date') - Expiry.objects.create( - medicine_id=medicine_name, - quantity=qty, - supplier=supplier, - expiry_date=expiry, - date=datetime.now(), - ) - quantity = (Stock.objects.get(id=medicine)).quantity - quantity = quantity + qty - Stock.objects.filter(id=medicine).update(quantity=quantity) - Stock.objects.filter(id=medicine).update(threshold=threshold_a) - data = {'status': 1} - return JsonResponse(data) - + try: + medicine = request.POST.get('medicine_id') + # threshold_a = request.POST.get('threshold_a') + med_brand_name = medicine.split(',')[0] + id = medicine.split(',')[1] + medicine_id = All_Medicine.objects.get(id = id) + qty = int(request.POST.get('quantity')) + supplier=request.POST.get('supplier') + expiry=request.POST.get('expiry_date') + tot_rows = Stock_entry.objects.all().count() + tot_rows1 = Present_Stock.objects.all().count() + stk=Stock_entry.objects.create( + id = tot_rows+1, + quantity=qty, + medicine_id=medicine_id, + supplier=supplier, + Expiry_date=expiry, + date=date.today() + ) + Present_Stock.objects.create( + id = tot_rows1+1, + quantity=qty, + stock_id=stk, + medicine_id=medicine_id, + Expiry_date=expiry + ) + if Required_medicine.objects.filter(medicine_id = medicine_id).exists(): + req=Required_medicine.objects.get(medicine_id = medicine_id) + req.quantity+=qty + if(req.quantity Req.threshold : + Req.delete() + else : Req.save() + else : + medicine_stock = Present_Stock.objects.filter(Q(medicine_id = threshold_med) & Q(Expiry_date__gt = date.today())) + qty=0 + for med in medicine_stock: + qty+=med.quantity + if qty < threshold_med.threshold : + Required_medicine.objects.create( + medicine_id = threshold_med, + quantity = qty, + threshold = threshold_med.threshold + ) + status=1 + except: + status=0 + finally: + data={'status':status} + return JsonResponse(data) # edit schedule for doctors elif 'edit_1' in request.POST: doctor = request.POST.get('doctor') @@ -199,27 +253,40 @@ def compounder_view_handler(request): elif 'add_medicine' in request.POST: medicine = request.POST.get('new_medicine') - quantity = request.POST.get('new_quantity') + # quantity = request.POST.get('new_quantity') threshold = request.POST.get('threshold') - new_supplier = request.POST.get('new_supplier') - new_expiry_date = request.POST.get('new_expiry_date') - Stock.objects.create( + brand_name = request.POST.get('brand_name') + constituents = request.POST.get('constituents') + manufacture_name = request.POST.get('manufacture_name') + packsize = request.POST.get('packsize') + # new_supplier = request.POST.get('new_supplier') + # new_expiry_date = request.POST.get('new_expiry_date') + tot_rows = All_Medicine.objects.all().count() + All_Medicine.objects.create( + id = tot_rows+1, medicine_name=medicine, - quantity=quantity, - threshold=threshold + brand_name=brand_name, + constituents=constituents, + threshold=threshold, + manufacturer_name=manufacture_name, + pack_size_label=packsize ) - medicine_id = Stock.objects.get(medicine_name=medicine) - Expiry.objects.create( - medicine_id=medicine_id, - quantity=quantity, - supplier=new_supplier, - expiry_date=new_expiry_date, - returned=False, - return_date=None, - date=datetime.now() - ) - data = {'medicine': medicine, 'quantity': quantity, 'threshold': threshold, - 'new_supplier': new_supplier, 'new_expiry_date': new_expiry_date } + # Stock.objects.create( + # medicine_name=medicine, + # quantity=quantity, + # threshold=threshold + # ) + # medicine_id = Stock.objects.get(medicine_name=medicine) + # Expiry.objects.create( + # medicine_id=medicine_id, + # quantity=quantity, + # supplier=new_supplier, + # expiry_date=new_expiry_date, + # returned=False, + # return_date=None, + # date=datetime.now() + # ) + data = {'medicine': medicine, 'threshold': threshold,} return JsonResponse(data) elif 'admission' in request.POST: @@ -245,63 +312,97 @@ def compounder_view_handler(request): data={'status':1} return JsonResponse(data) - elif 'medicine_name' in request.POST: - app = request.POST.get('user') - user = Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').get(id=app).user_id - quantity = int(request.POST.get('quantity')) - days = int(request.POST.get('days')) - times = int(request.POST.get('times')) - medicine_id = request.POST.get('medicine_name') - medicine = Stock.objects.get(id=medicine_id) - Medicine.objects.create( - patient=user, - medicine_id=medicine, - quantity=quantity, - days=days, - times=times - ) - user_medicine = Medicine.objects.filter(patient=user) - list = [] - for med in user_medicine: - list.append({'medicine': med.medicine_id.medicine_name, 'quantity': med.quantity, - 'days': med.days, 'times': med.times}) - sches = json.dumps(list, default=datetime_handler) - return HttpResponse(sches, content_type='json') - + # elif 'medicine_name' in request.POST: + # app = request.POST.get('user') + # user = Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').get(id=app).user_id + # quantity = int(request.POST.get('quantity')) + # days = int(request.POST.get('days')) + # times = int(request.POST.get('times')) + # medicine_id = request.POST.get('medicine_name') + # medicine = Stock.objects.get(id=medicine_id) + # Medicine.objects.create( + # patient=user, + # medicine_id=medicine, + # quantity=quantity, + # days=days, + # times=times + # ) + # user_medicine = Medicine.objects.filter(patient=user) + # list = [] + # for med in user_medicine: + # list.append({'medicine': med.medicine_id.medicine_name, 'quantity': med.quantity, + # 'days': med.days, 'times': med.times}) + # sches = json.dumps(list, default=datetime_handler) + # return HttpResponse(sches, content_type='json') + elif 'get_stock' in request.POST: + try: + medicine_name_and_id = request.POST.get('medicine_name_for_stock') + medicine_name = medicine_name_and_id.split(",")[0] + id=0 + if(len(medicine_name_and_id.split(",")) > 1) : + id=medicine_name_and_id.split(",")[1] + if id == 0: + status=1 + similar_name_qs = All_Medicine.objects.filter(brand_name__istartswith=medicine_name)[:10] + else : + status=2 + similar_name_qs = All_Medicine.objects.filter(id=id) + similar_name = list(similar_name_qs.values('id', 'medicine_name','constituents','manufacturer_name','pack_size_label','brand_name','threshold')) + val_to_return = [] + + try: + med = All_Medicine.objects.get(id = id) + stk = Stock_entry.objects.filter(medicine_id=med).order_by('Expiry_date') + for s in stk: + if s.Expiry_date > date.today(): + obj = {} + obj['brand_name'] = s.medicine_id.brand_name + obj['supplier'] = s.supplier + obj['expiry'] = s.Expiry_date + p_s = Present_Stock.objects.get(stock_id=s) + if p_s.quantity > 0: + obj['quantity'] = p_s.quantity + obj['id'] = p_s.id + val_to_return.append(obj) + except All_Medicine.DoesNotExist: + val_to_return = [] + except Present_Stock.DoesNotExist: + val_to_return = [] + except Exception as e: + val_to_return = [] + finally: + return JsonResponse({"val": val_to_return, "sim": similar_name, "status": status}) elif 'medicine_name_b' in request.POST: user_id = request.POST.get('user') - user = ExtraInfo.objects.select_related('user','department').get(id=user_id) + if not User.objects.filter(username__iexact = user_id).exists(): + return JsonResponse({"status":-2}) quantity = int(request.POST.get('quantity')) days = int(request.POST.get('days')) times = int(request.POST.get('times')) medicine_id = request.POST.get('medicine_name_b') - medicine = Stock.objects.get(id=medicine_id) - Medicine.objects.create( - patient=user, - medicine_id=medicine, - quantity=quantity, - days=days, - times=times - ) - schs = Medicine.objects.filter(patient=user) - list = [] - for s in schs: - list.append({'medicine': s.medicine_id.medicine_name, 'quantity': s.quantity, - 'days': s.days, 'times': s.times}) - sches = json.dumps(list, default=datetime_handler) - return HttpResponse(sches, content_type='json') + stock = request.POST.get('stock') + medicine_brand_name = medicine_id.split(",")[0] + id= medicine_id.split(",")[1] + med_name = All_Medicine.objects.get(id=id).brand_name + if(stock == "" or stock == "N/A at moment") : + return JsonResponse({"status":1,"med_name":med_name,"id":id}) + stk=stock.split(",") + qty = int(stk[2]) + status=1 + if quantity>qty : status=0 + return JsonResponse({"status":status,"med_name":med_name,"id":id}) - elif 'doct' in request.POST: - doctor_id = request.POST.get('doct') - schedule = Schedule.objects.select_related('doctor_id').filter(doctor_id=doctor_id) - list = [] - for s in schedule: - list.append({'room': s.room, 'id': s.id, 'doctor': s.doctor_id.doctor_name, - 'day': s.get_day_display(), 'from_time': s.from_time, - 'to_time': s.to_time}) - - sches = json.dumps(list, default=datetime_handler) - return HttpResponse(sches, content_type='json') + # elif 'doct' in request.POST: + # doctor_id = request.POST.get('doct') + # schedule = Schedule.objects.select_related('doctor_id').filter(doctor_id=doctor_id) + # list = [] + # for s in schedule: + # list.append({'room': s.room, 'id': s.id, 'doctor': s.doctor_id.doctor_name, + # 'day': s.get_day_display(), 'from_time': s.from_time, + # 'to_time': s.to_time}) + + # sches = json.dumps(list, default=datetime_handler) + # return HttpResponse(sches, content_type='json') elif 'prescribe' in request.POST: app_id = request.POST.get('user') @@ -361,92 +462,354 @@ def compounder_view_handler(request): healthcare_center_notif(request.user, user.user, 'presc','') data = {'status': status, 'stock': stock} return JsonResponse(data) + elif 'user_for_dependents' in request.POST: + user = request.POST.get('user_for_dependents') + if not User.objects.filter(username__iexact = user).exists(): + return JsonResponse({"status":-1}) + user_id = User.objects.get(username__iexact = user) + info = ExtraInfo.objects.get(user = user_id) + dep_info = EmpDependents.objects.filter(extra_info = info) + dep=[] + for d in dep_info: + obj={} + obj['name'] = d.name + obj['relation'] = d.relationship + dep.append(obj) + if(len(dep) == 0) : + return JsonResponse({'status':-2}) + return JsonResponse({'status':1,'dep':dep}) elif 'prescribe_b' in request.POST: user_id = request.POST.get('user') - user = ExtraInfo.objects.select_related('user','department').get(id=user_id) doctor_id = request.POST.get('doctor') - if doctor_id == "": + if not User.objects.filter(username__iexact = user_id).exists(): + return JsonResponse({"status":-1}) + if doctor_id == 'null' : doctor = None else: doctor = Doctor.objects.get(id=doctor_id) - details = request.POST.get('details') - tests = request.POST.get('tests') - # app = Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').filter(user_id=user_id,date=datetime.now()) - # if app: - # appointment = Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').get(user_id=user_id,date=datetime.now()) - # else: - # appointment = None - designation=request.POST.get('user') - uploaded_file = request.FILES.get('file') - d = HoldsDesignation.objects.get(user__username=designation) - form_object=Prescription( - user_id=user, - doctor_id=doctor, - details=details, - date=datetime.now(), - test=tests, - # appointment=appointment - ) - form_object.save() - request_object = Prescription.objects.get(pk=form_object.pk) - send_file_id = create_file( - uploader=request.user.username, - uploader_designation=request.session['currentDesignationSelected'], - receiver=designation, - receiver_designation=d.designation, - src_module="health_center", - src_object_id=str(request_object.id), - file_extra_JSON={"value": 2}, - attached_file=uploaded_file - ) - request_object.file_id=send_file_id - request_object.save() + - query = Medicine.objects.select_related('patient','patient__user','patient__department').filter(patient=user) - prescribe = Prescription.objects.select_related('user_id','user_id__user','user_id__department','doctor_id').all().last() - for medicine in query: - medicine_id = medicine.medicine_id - quantity = medicine.quantity - days = medicine.days - times = medicine.times - Prescribed_medicine.objects.create( - prescription_id=prescribe, - medicine_id=medicine_id, - quantity=quantity, - days=days, - times=times + is_dependent=request.POST.get('is_dependent') + fid=0 + uploaded_file = request.FILES.get('file') + if uploaded_file != None : + f=uploaded_file.read() + new_file=files.objects.create( + file_data=f ) - today=datetime.now() - expiry=Expiry.objects.select_related('medicine_id').filter(medicine_id=medicine_id,quantity__gt=0,returned=False,expiry_date__gte=today).order_by('expiry_date') - stock=Stock.objects.get(medicine_name=medicine_id).quantity - if stock>quantity: - for e in expiry: - q=e.quantity - em=e.id - if q>quantity: - q=q-quantity - Expiry.objects.select_related('medicine_id').filter(id=em).update(quantity=q) - qty = Stock.objects.get(medicine_name=medicine_id).quantity - qty = qty-quantity - Stock.objects.filter(medicine_name=medicine_id).update(quantity=qty) - break - else: - quan=Expiry.objects.select_related('medicine_id').get(id=em).quantity - Expiry.objects.select_related('medicine_id').filter(id=em).update(quantity=0) - qty = Stock.objects.get(medicine_name=medicine_id).quantity - qty = qty-quan - Stock.objects.filter(medicine_name=medicine_id).update(quantity=qty) - quantity=quantity-quan - status = 1 + fid=new_file.id + # with open(uploaded_file.name, 'wb+') as destination: + # destination.write(f) + if is_dependent == "self": + pres=All_Prescription.objects.create( + user_id = user_id, + doctor_id=doctor, + details = request.POST.get('details'), + date=date.today(), + test=request.POST.get('tests'), + file_id=fid + ) + else : + pres=All_Prescription.objects.create( + user_id = user_id, + doctor_id=doctor, + details = request.POST.get('details'), + date=date.today(), + test=request.POST.get('tests'), + is_dependent = True, + dependent_name = request.POST.get('dependent_name'), + dependent_relation = request.POST.get('dependent_relation'), + file_id=fid + ) + # designation=request.POST.get('user') + # d = HoldsDesignation.objects.get(user__username=designation) + # send_file_id = create_file( + # uploader=request.user.username, + # uploader_designation=request.session['currentDesignationSelected'], + # receiver=designation, + # receiver_designation=d.designation, + # src_module="health_center", + # src_object_id=str(pres.id), + # file_extra_JSON={"value": 2}, + # attached_file=uploaded_file + # ) + # pres.file_id=send_file_id + # pres.save() - else: - status = 0 - Medicine.objects.select_related('patient','patient__user','patient__department').all().delete() + pre_medicine = request.POST.get('pre_medicine') + + medicine=eval('('+pre_medicine+')') + + for med in medicine: + med_name = med["brand_name"] + id=med_name.split(",")[1] + quant = int(med['quantity']) + days = med['Days'] + times = med['Times'] + stock = med['stock'] + med_id = All_Medicine.objects.get(id=id) + if(stock == "," or stock == 'N/A at moment,') : + All_Prescribed_medicine.objects.create( + prescription_id = pres, + medicine_id = med_id, + quantity = quant, + days = days, + times=times + ) + else : + stk = stock.split(",") + p_stock = Present_Stock.objects.get(id=int(stk[2])) + All_Prescribed_medicine.objects.create( + prescription_id = pres, + medicine_id = med_id, + stock = p_stock, + quantity = quant, + days = days, + times=times + ) + p_stock.quantity -= quant + p_stock.save() + stock_of_medicine = Present_Stock.objects.filter(Q(medicine_id = med_id) & Q( Expiry_date__gt = date.today())) + qty=0 + for stk in stock_of_medicine : + qty+=stk.quantity + + if qtyquantity: + # for e in expiry: + # q=e.quantity + # em=e.id + # if q>quantity: + # q=q-quantity + # Expiry.objects.select_related('medicine_id').filter(id=em).update(quantity=q) + # qty = Stock.objects.get(medicine_name=medicine_id).quantity + # qty = qty-quantity + # Stock.objects.filter(medicine_name=medicine_id).update(quantity=qty) + # break + # else: + # quan=Expiry.objects.select_related('medicine_id').get(id=em).quantity + # Expiry.objects.select_related('medicine_id').filter(id=em).update(quantity=0) + # qty = Stock.objects.get(medicine_name=medicine_id).quantity + # qty = qty-quan + # Stock.objects.filter(medicine_name=medicine_id).update(quantity=qty) + # quantity=quantity-quan + # status = 1 + + # else: + # status = 0 + # Medicine.objects.select_related('patient','patient__user','patient__department').all().delete() - healthcare_center_notif(request.user, user.user, 'presc','') - data = {'status': status} - return JsonResponse(data) + # healthcare_center_notif(request.user, user.user, 'presc','') + # data = {'status': status} + # return JsonResponse(data) + return JsonResponse({"status":1}) + + elif 'presc_followup' in request.POST: + pre_id=request.POST.get("pre_id") + presc = All_Prescription.objects.get(id=int(pre_id)) + + doctor_id = request.POST.get('doctor') + if doctor_id == "null": + doctor = None + else: + doctor = Doctor.objects.get(id=doctor_id) + + fid=0 + uploaded_file = request.FILES.get('file') + if uploaded_file != None : + f=uploaded_file.read() + new_file=files.objects.create( + file_data=f + ) + fid=new_file.id + + followup = Prescription_followup.objects.create( + prescription_id=presc, + Doctor_id=doctor, + details = request.POST.get('details'), + test = request.POST.get('tests'), + date = date.today(), + file_id = fid + ) + + pre_medicine = request.POST.get('pre_medicine') + + medicine=eval('('+pre_medicine+')') + for med in medicine: + med_name = med["med_name"] + id = med_name.split(',')[1] + quant = int(med['quantity']) + days = med['Days'] + times = med['Times'] + stock = med['stock'] + med_id = All_Medicine.objects.get(id = id) + if(stock == ',' or stock == "N/A at moment,"): + All_Prescribed_medicine.objects.create( + prescription_id = presc, + medicine_id = med_id, + quantity = quant, + days = days, + times=times, + prescription_followup_id = followup + ) + else : + stk = stock.split(",") + p_stock = Present_Stock.objects.get(id=int(stk[2])) + All_Prescribed_medicine.objects.create( + prescription_id = presc, + medicine_id = med_id, + stock = p_stock, + quantity = quant, + days = days, + times=times, + prescription_followup_id = followup + ) + p_stock.quantity -= quant + p_stock.save() + stock_of_medicine = Present_Stock.objects.filter(Q(medicine_id = med_id) & Q(Expiry_date__gt = date.today())) + qty=0 + for stk in stock_of_medicine : + qty+=stk.quantity + + if qty 1, + 'has_next': new_current_page < total_pages, + 'previous_page_number': new_current_page - 1 if new_current_page > 1 else None, + 'next_page_number': new_current_page + 1 if new_current_page < total_pages else None, + }) + elif 'datatype' in request.POST and request.POST['datatype'] == 'manage_stock_view': + search = request.POST.get('search_view_stock') + page_size_stock = 2 + new_current_page_stock = int(request.POST.get('page_stock_view')) + new_offset_stock = (new_current_page_stock - 1) * page_size_stock + new_live_meds = [] + new_live =Stock_entry.objects.filter(Q(Expiry_date__gte=date.today()) & Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).order_by('Expiry_date')[new_offset_stock:new_offset_stock + page_size_stock] + total_pages_stock = ( Stock_entry.objects.filter(Q(Expiry_date__gte=date.today()) & Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).count() + page_size_stock - 1) // page_size_stock + for e in new_live: + obj={} + obj['id']=e.id + obj['medicine_id']=e.medicine_id.brand_name + obj['Expiry_date']=e.Expiry_date + obj['supplier']=e.supplier + try: + qty=Present_Stock.objects.get(stock_id=e).quantity + except: + qty=0 + obj['quantity']=qty + new_live_meds.append(obj) + return JsonResponse({ + 'report_stock_view': new_live_meds, + 'page_stock_view': new_current_page_stock, + 'total_pages_stock_view': total_pages_stock, + 'has_previous': new_current_page_stock > 1, + 'has_next': new_current_page_stock < total_pages_stock, + 'previous_page_number': new_current_page_stock - 1 if new_current_page_stock > 1 else None, + 'next_page_number': new_current_page_stock + 1 if new_current_page_stock < total_pages_stock else None, + }) + elif 'datatype' in request.POST and request.POST['datatype'] == 'manage_stock_expired': + search = request.POST.get('search_view_expired') + new_page_size_stock_expired = 2 + new_current_page_stock_expired = int(request.POST.get('page_stock_expired')) + new_offset_stock_expired = (new_current_page_stock_expired - 1 )* new_page_size_stock_expired + new_expired=[] + new_expiredData=Stock_entry.objects.filter(Q(Expiry_date__lt=date.today())&Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).order_by('Expiry_date')[new_offset_stock_expired:new_offset_stock_expired + new_page_size_stock_expired] + new_total_pages_stock_expired = ( Stock_entry.objects.filter(Q(Expiry_date__lt=date.today())&Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).count() + new_page_size_stock_expired - 1) // new_page_size_stock_expired + for e in new_expiredData: + obj={} + obj['medicine_id']=e.medicine_id.brand_name + obj['Expiry_date']=e.Expiry_date + obj['supplier']=e.supplier + try: + qty=Present_Stock.objects.get(stock_id=e).quantity + except: + qty=0 + obj['quantity']=qty + new_expired.append(obj) + return JsonResponse({ + 'report_stock_expired': new_expired, + 'page_stock_expired': new_current_page_stock_expired, + 'total_pages_stock_view': new_total_pages_stock_expired, + 'has_previous': new_current_page_stock_expired > 1, + 'has_next': new_current_page_stock_expired < new_total_pages_stock_expired, + 'previous_page_number': new_current_page_stock_expired - 1 if new_current_page_stock_expired > 1 else None, + 'next_page_number': new_current_page_stock_expired + 1 if new_current_page_stock_expired < new_total_pages_stock_expired else None, + }) + elif 'datatype' in request.POST and request.POST['datatype'] == 'manage_stock_required': + search = request.POST.get('search_view_required') + new_page_size_stock_required = 2 + new_current_page_stock_required = int(request.POST.get('page_stock_required')) + new_offset_stock_required = (new_current_page_stock_required - 1 )* new_page_size_stock_required + new_required=[] + new_requiredData=Required_medicine.objects.filter( Q(medicine_id__brand_name__icontains = search))[new_offset_stock_required:new_offset_stock_required + new_page_size_stock_required] + new_total_pages_stock_required = (Required_medicine.objects.filter( Q(medicine_id__brand_name__icontains = search)).count() + new_page_size_stock_required - 1) // new_page_size_stock_required + for e in new_requiredData: + obj={} + obj['medicine_id']=e.medicine_id.brand_name + obj['quantity']=e.quantity + obj['threshold']=e.threshold + new_required.append(obj) + return JsonResponse({ + 'report_stock_required': new_required, + 'page_stock_required': new_current_page_stock_required, + 'total_pages_stock_required': new_total_pages_stock_required, + 'has_previous': new_current_page_stock_required > 1, + 'has_next': new_current_page_stock_required < new_total_pages_stock_required, + 'previous_page_number': new_current_page_stock_required - 1 if new_current_page_stock_required > 1 else None, + 'next_page_number': new_current_page_stock_required + 1 if new_current_page_stock_required < new_total_pages_stock_required else None, + }) + + elif 'search_patientlog' in request.POST: + search = request.POST.get('search_patientlog') + current_page = 1 + page_size_prescription = 2 # Default to 2 if not specified + offset = (current_page - 1) * page_size_prescription + prescriptions = All_Prescription.objects.filter(Q(user_id__icontains = search) | Q(details__icontains = search)).order_by('-date', '-id')[offset:offset + page_size_prescription] + + report = [] + for pre in prescriptions: + doc = None + if pre.doctor_id != None : doc=pre.doctor_id.doctor_name + dic = { + 'id': pre.pk, + 'user_id': pre.user_id, + 'doctor_id': doc, + 'date': pre.date, + 'details': pre.details, + 'test': pre.test, + 'file_id': pre.file_id, + # 'file': view_file(file_id=pre.file_id)['upload_file'] if pre.file_id else None + } + report.append(dic) + # Handle total count for pagination context + total_count = All_Prescription.objects.filter(Q(user_id__icontains = search) | Q(details__icontains = search)).count() + # Calculate total number of pages + total_pages = (total_count + page_size_prescription - 1) // page_size_prescription # This ensures rounding up + prescContext = { + 'count': total_pages, + 'page': { + 'object_list': report, + 'number': current_page, + 'has_previous': current_page > 1, + 'has_next': current_page < total_pages, + 'previous_page_number': current_page - 1 if current_page > 1 else None, + 'next_page_number': current_page + 1 if current_page < total_pages else None, + } + } + return JsonResponse({'status':1,"presc_context":prescContext}) + elif 'search_view_stock' in request.POST: + search = request.POST.get('search_view_stock') + current_page_stock = 1 + page_size_stock = 2 + offset_stock = (current_page_stock - 1 )* page_size_stock + live_meds=[] + live=Stock_entry.objects.filter(Q(Expiry_date__gte=date.today()) & Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).order_by('Expiry_date')[offset_stock:offset_stock + page_size_stock] + total_pages_stock = ( Stock_entry.objects.filter(Q(Expiry_date__gte=date.today()) & Q(Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).count() + page_size_stock - 1) // page_size_stock + for e in live: + obj={} + obj['id']=e.id + obj['medicine_id']=e.medicine_id.brand_name + obj['Expiry_date']=e.Expiry_date + obj['supplier']=e.supplier + try: + qty=Present_Stock.objects.get(stock_id=e).quantity + except: + qty=0 + obj['quantity']=qty + live_meds.append(obj) + stockContext = { + 'count_stock_view':total_pages_stock, + 'page_stock_view':{ + 'object_list': live_meds, + 'number': current_page_stock, + 'has_previous': current_page_stock > 1, + 'has_next': current_page_stock < total_pages_stock, + 'previous_page_number': current_page_stock - 1 if current_page_stock > 1 else None, + 'next_page_number': current_page_stock + 1 if current_page_stock < total_pages_stock else None, + } + } + return JsonResponse({'status':1,'stock_context':stockContext}) + elif 'search_view_expired' in request.POST: + search = request.POST.get('search_view_expired') + current_page_stock_expired = 1 + page_size_stock_expired = 2 + offset_stock_expired = (current_page_stock_expired - 1 )* page_size_stock_expired + expired=[] + expiredData=Stock_entry.objects.filter(Q(Expiry_date__lt=date.today())&Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).order_by('Expiry_date')[offset_stock_expired:offset_stock_expired + page_size_stock_expired] + total_pages_stock_expired = ( Stock_entry.objects.filter(Q(Expiry_date__lt=date.today())&Q( Q(medicine_id__brand_name__icontains = search) | Q(supplier__icontains = search))).count() + page_size_stock_expired - 1) // page_size_stock_expired + for e in expiredData: + obj={} + obj['medicine_id']=e.medicine_id.brand_name + obj['Expiry_date']=e.Expiry_date + obj['supplier']=e.supplier + try: + qty=Present_Stock.objects.get(stock_id=e).quantity + except: + qty=0 + obj['quantity']=qty + expired.append(obj) + ExpiredstockContext = { + 'count_stock_expired':total_pages_stock_expired, + 'page_stock_expired':{ + 'object_list': expired, + 'number': current_page_stock_expired, + 'has_previous': current_page_stock_expired > 1, + 'has_next': current_page_stock_expired < total_pages_stock_expired, + 'previous_page_number': current_page_stock_expired - 1 if current_page_stock_expired > 1 else None, + 'next_page_number': current_page_stock_expired + 1 if current_page_stock_expired < total_pages_stock_expired else None, + } + } + return JsonResponse({'status':1,'expired_context':ExpiredstockContext}) + elif 'search_view_required' in request.POST: + search = request.POST.get('search_view_required') + current_required_page = 1 + page_size_required = 2 + offset_stock_required = (current_required_page - 1 )* page_size_required + required_data = Required_medicine.objects.filter( Q(medicine_id__brand_name__icontains = search) )[offset_stock_required:offset_stock_required + page_size_required] + total_pages_stock_required = (Required_medicine.objects.filter( Q(medicine_id__brand_name__icontains = search) ).count() + page_size_required -1) // page_size_required + required=[] + for e in required_data: + obj={} + obj['medicine_id']=e.medicine_id.brand_name + obj['quantity']=e.quantity + obj['threshold'] = e.threshold + required.append(obj) + stocks = { + "count_stock_required" : total_pages_stock_required, + "page_stock_required":{ + "object_list":required, + 'number' : current_required_page, + 'has_previous' : current_required_page > 1 , + 'has_next': current_required_page < total_pages_stock_required, + 'previous_page_number' : current_required_page - 1 if current_required_page > 1 else None, + 'next_page_number' : current_required_page + 1 if current_required_page < total_pages_stock_required else None, + } + } + return JsonResponse({'status':1,'stocks':stocks}) def student_view_handler(request): if 'amb_submit' in request.POST: diff --git a/FusionIIIT/applications/health_center/views.py b/FusionIIIT/applications/health_center/views.py index 4d8881496..a178a9d68 100644 --- a/FusionIIIT/applications/health_center/views.py +++ b/FusionIIIT/applications/health_center/views.py @@ -1,4 +1,6 @@ import json +import pandas as pd +from django.http import FileResponse,Http404 from datetime import date, datetime, timedelta, time import xlrd import os @@ -7,17 +9,18 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.core import serializers -from django.core.paginator import Paginator +from django.core.paginator import EmptyPage from django.http import HttpResponse, HttpResponseRedirect, JsonResponse from django.shortcuts import get_object_or_404, render, redirect from notification.views import healthcare_center_notif -from applications.health_center.api.serializers import MedicalReliefSerializer -from .models import (Ambulance_request, Appointment, Complaint, Constants, - Counter, Doctor,Pathologist, Expiry, Hospital, Hospital_admit, - Medicine, Prescribed_medicine, Prescription, Doctors_Schedule,Pathologist_Schedule, - Stock,SpecialRequest,Announcements,medical_relief,MedicalProfile) +# from applications.health_center.api.serializers import MedicalReliefSerializer +from .models import ( Constants,All_Medicine,All_Prescribed_medicine,All_Prescription,Prescription_followup, + Present_Stock,Doctor,Pathologist, + Doctors_Schedule,Pathologist_Schedule,Stock_entry, + medical_relief,MedicalProfile,Required_medicine,files,Required_tabel_last_updated) from .utils import datetime_handler, compounder_view_handler, student_view_handler from applications.filetracking.sdk.methods import * +from django.db.models import Q @@ -75,52 +78,190 @@ def compounder_view(request): else: notifs = request.user.notifications.all() - all_complaints = Complaint.objects.select_related('user_id','user_id__user','user_id__department').all() - all_hospitals = Hospital_admit.objects.select_related('user_id','user_id__user','user_id__department','doctor_id').all().order_by('-admission_date') - hospitals_list = Hospital.objects.all().order_by('hospital_name') - all_ambulances = Ambulance_request.objects.select_related('user_id','user_id__user','user_id__department').all().order_by('-date_request') - appointments_today =Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').filter(date=datetime.now()).order_by('date') - appointments_future=Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').filter(date__gt=datetime.now()).order_by('date') + # all_complaints = Complaint.objects.select_related('user_id','user_id__user','user_id__department').all() + # all_hospitals = Hospital_admit.objects.select_related('user_id','user_id__user','user_id__department','doctor_id').all().order_by('-admission_date') + # hospitals_list = Hospital.objects.all().order_by('hospital_name') + # all_ambulances = Ambulance_request.objects.select_related('user_id','user_id__user','user_id__department').all().order_by('-date_request') + # appointments_today =Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').filter(date=datetime.now()).order_by('date') + # appointments_future=Appointment.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','schedule','schedule__doctor_id').filter(date__gt=datetime.now()).order_by('date') users = ExtraInfo.objects.select_related('user','department').filter(user_type='student') - stocks = Stock.objects.all() - days = Constants.DAYS_OF_WEEK schedule=Doctors_Schedule.objects.select_related('doctor_id').all().order_by('doctor_id') schedule1=Pathologist_Schedule.objects.select_related('pathologist_id').all().order_by('pathologist_id') - expired=Expiry.objects.select_related('medicine_id').filter(expiry_date__lt=datetime.now(),returned=False).order_by('expiry_date') - live_meds=Expiry.objects.select_related('medicine_id').filter(returned=False).order_by('quantity') - count=Counter.objects.all() - announcements_data=Announcements.objects.all().values() + # expired=Expiry.objects.select_related('medicine_id').filter(expiry_date__lt=datetime.now(),returned=False).order_by('expiry_date') + # live_meds=Expiry.objects.select_related('medicine_id').filter(returned=False).order_by('quantity') + page_size=2 + fir=Required_tabel_last_updated.objects.first() + if fir == None: + exp = Stock_entry.objects.filter(Expiry_date__lt = date.today()) + for e in exp: + med=e.medicine_id + p_s = Present_Stock.objects.filter(Q(medicine_id = med) & Q(Expiry_date__gte = date.today())) + qty=0 + for ps in p_s: + qty+=ps.quantity + if Required_medicine.objects.filter(medicine_id=med).exists() : + req=Required_medicine.objects.get(medicine_id=med) + if qty>=med.threshold : req.delete() + else : + req.quantity = qty + req.save() + else : + if qtymed.threshold) : req.delete() + else : + req.quantity = qty + req.save() + else : + if qty 1 , + 'has_next': current_required_page < total_pages_stock_required, + 'previous_page_number' : current_required_page - 1 if current_required_page > 1 else None, + 'next_page_number' : current_required_page + 1 if current_required_page < total_pages_stock_required else None, + } + } + + current_page_stock_expired = 1 + page_size_stock_expired = page_size + offset_stock_expired = (current_page_stock_expired - 1 )* page_size_stock_expired + expired=[] + expiredData=Stock_entry.objects.filter(Expiry_date__lt=date.today()).order_by('Expiry_date')[offset_stock_expired:offset_stock_expired + page_size_stock_expired] + total_pages_stock_expired = ( Stock_entry.objects.filter(Expiry_date__lt=date.today()).count() + page_size_stock_expired - 1) // page_size_stock_expired + for e in expiredData: + obj={} + obj['medicine_id']=e.medicine_id.brand_name + obj['Expiry_date']=e.Expiry_date + obj['supplier']=e.supplier + try: + qty=Present_Stock.objects.get(stock_id=e).quantity + except: + qty=0 + obj['quantity']=qty + expired.append(obj) + ExpiredstockContext = { + 'count_stock_expired':total_pages_stock_expired, + 'page_stock_expired':{ + 'object_list': expired, + 'number': current_page_stock_expired, + 'has_previous': current_page_stock_expired > 1, + 'has_next': current_page_stock_expired < total_pages_stock_expired, + 'previous_page_number': current_page_stock_expired - 1 if current_page_stock_expired > 1 else None, + 'next_page_number': current_page_stock_expired + 1 if current_page_stock_expired < total_pages_stock_expired else None, + } + } + + + current_page_stock = 1 + page_size_stock = page_size + offset_stock = (current_page_stock - 1 )* page_size_stock + live_meds=[] + live=Stock_entry.objects.filter(Expiry_date__gte=date.today()).order_by('Expiry_date')[offset_stock:offset_stock + page_size_stock] + total_pages_stock = ( Stock_entry.objects.filter(Expiry_date__gte=date.today()).count() + page_size_stock - 1) // page_size_stock + for e in live: + obj={} + obj['id']=e.id + obj['medicine_id']=e.medicine_id.brand_name + obj['Expiry_date']=e.Expiry_date + obj['supplier']=e.supplier + try: + qty=Present_Stock.objects.get(stock_id=e).quantity + except: + qty=0 + obj['quantity']=qty + live_meds.append(obj) + stockContext = { + 'count_stock_view':total_pages_stock, + 'page_stock_view':{ + 'object_list': live_meds, + 'number': current_page_stock, + 'has_previous': current_page_stock > 1, + 'has_next': current_page_stock < total_pages_stock, + 'previous_page_number': current_page_stock - 1 if current_page_stock > 1 else None, + 'next_page_number': current_page_stock + 1 if current_page_stock < total_pages_stock else None, + } + } + - medicines_presc=Prescribed_medicine.objects.select_related('prescription_id','prescription_id__user_id','prescription_id__user_id__user','prescription_id__user_id__department','prescription_id__doctor_id').all() - print(medicines_presc) - if count: - Counter.objects.all().delete() - Counter.objects.create(count=0,fine=0) - count=Counter.objects.get() - hospitals=Hospital.objects.all() schedule=Doctors_Schedule.objects.select_related('doctor_id').all().order_by('day','doctor_id') schedule1=Pathologist_Schedule.objects.select_related('pathologist_id').all().order_by('day','pathologist_id') doctors=Doctor.objects.filter(active=True).order_by('id') pathologists=Pathologist.objects.filter(active=True).order_by('id') - prescription= Prescription.objects.all() - report=[] - for pre in prescription: - dic={} - dic['id']=pre.pk - dic['user_id']=pre.user_id_id - dic['doctor_id'] = pre.doctor_id # Use dot notation - dic['date'] = pre.date # Use dot notation - dic['details'] = pre.details # Use dot notation - dic['test'] = pre.test # Use dot notation - if pre.file_id: - dic['file'] = view_file(file_id=pre.file_id)['upload_file'] - else: - dic['file']=None + medicine_presc = All_Prescribed_medicine.objects.all() + + #Logic for the padination and view prescriptions is below , used ajax for pagination + current_page = 1 + page_size_prescription = page_size # Default to 2 if not specified + offset = (current_page - 1) * page_size_prescription + # Fetch the prescriptions with limit and offset + prescriptions = All_Prescription.objects.all().order_by('-date', '-id')[offset:offset + page_size_prescription] + + report = [] + for pre in prescriptions: + dic = { + 'id': pre.pk, + 'user_id': pre.user_id, + 'doctor_id': pre.doctor_id, + 'date': pre.date, + 'details': pre.details, + 'test': pre.test, + 'file_id': pre.file_id, + # 'file': view_file(file_id=pre.file_id)['upload_file'] if pre.file_id else None + } report.append(dic) - + # Handle total count for pagination context + total_count = All_Prescription.objects.count() + # Calculate total number of pages + total_pages = (total_count + page_size_prescription - 1) // page_size_prescription # This ensures rounding up + prescContext = { + 'count': total_pages, + 'page': { + 'object_list': report, + 'number': current_page, + 'has_previous': current_page > 1, + 'has_next': current_page < total_pages, + 'previous_page_number': current_page - 1 if current_page > 1 else None, + 'next_page_number': current_page + 1 if current_page < total_pages else None, + } + } + #adding file tracking inbox part for compounder @@ -136,20 +277,18 @@ def compounder_view(request): dic['uploader']=ib['uploader'] dic['upload_date']=datetime.fromisoformat(ib['upload_date']).date() dic['desc']=mr.description - dic['file']=view_file(file_id=ib['id'])['upload_file'] + # dic['file']=view_file(file_id=ib['id'])['upload_file'] dic['status']=mr.compounder_forward_flag dic['status1']=mr.acc_admin_forward_flag inbox.append(dic) # print(inbox_files) - return render(request, 'phcModule/phc_compounder.html', - {'days': days, 'users': users, 'count': count,'expired':expired, - 'stocks': stocks, 'all_complaints': all_complaints, - 'all_hospitals': all_hospitals, 'hospitals':hospitals, 'all_ambulances': all_ambulances, - 'appointments_today': appointments_today, 'doctors': doctors, 'pathologists':pathologists, - 'appointments_future': appointments_future, 'schedule': schedule, 'schedule1': schedule1, 'live_meds': live_meds, 'presc_hist': report, 'medicines_presc': medicines_presc, 'hospitals_list': hospitals_list,'inbox_files':inbox,'announcements':announcements_data,}) + {'days': days, 'users': users,'expired':ExpiredstockContext, + 'stocks': stocks, + 'doctors': doctors, 'pathologists':pathologists, + 'schedule': schedule, 'schedule1': schedule1, 'live_meds': stockContext, 'presc_hist': prescContext,'inbox_files':inbox,'medicines_presc':medicine_presc}) else: return HttpResponseRedirect("/healthcenter/student") # compounder view ends @@ -632,4 +771,37 @@ def medical_profile(request): return render(request, 'health_center/medical_profile.html', {"user_designation":user_info.user_type, 'medical_profile':medical_profile, "request_to":requests_received - }) \ No newline at end of file + }) + +@login_required +def compounder_view_prescription(request,prescription_id): + prescription = All_Prescription.objects.get(id=prescription_id) + pre_medicine = All_Prescribed_medicine.objects.filter(prescription_id=prescription) + doctors=Doctor.objects.filter(active=True).order_by('id') + follow_presc =Prescription_followup.objects.filter(prescription_id=prescription).order_by('-id') + if request.method == "POST": + print("post") + return render(request, 'phcModule/phc_compounder_view_prescription.html',{'prescription':prescription, + 'pre_medicine':pre_medicine,'doctors':doctors, + "follow_presc":follow_presc}) + +@login_required +def view_file(request,file_id): + file_id_int = int(file_id) + if(file_id_int == -2): + return FileResponse(open('static/health_center/add_stock_example.xlsx', 'rb'), as_attachment=True, filename="example_add_stock.xlsx") + if(file_id_int == -1): + return FileResponse(open('static/health_center/add_medicine_example.xlsx', 'rb'), as_attachment=True, filename="example_add_medicine.xlsx") + filepath = "applications/health_center/static/health_center/generated.pdf" + + file=files.objects.get(id=file_id) + f=file.file_data + + with open("applications/health_center/static/health_center/generated.pdf", 'wb+') as destination: + destination.write(f) + + pdf = open(filepath, 'rb') + response = FileResponse(pdf, content_type="application/pdf") + response['Content-Disposition'] = 'inline; filename="generated.pdf"' + + return response diff --git a/FusionIIIT/templates/phcModule/manage_stock.html b/FusionIIIT/templates/phcModule/manage_stock.html index 5d9bfbe22..23cb89dd1 100644 --- a/FusionIIIT/templates/phcModule/manage_stock.html +++ b/FusionIIIT/templates/phcModule/manage_stock.html @@ -1,339 +1,637 @@ {% load static %} - + -{% block stock %} - {% comment %}the main tab starts here {% endcomment %} - - - {% comment %}the add stock tab starts here{% endcomment %} -
-

-
-
{% csrf_token %} -
- - -
-
- -
- -
-
-
- -
- -
-
-
-

-
- -
-
-
- -
- -
-
-
- - -
- -
- -
-
- -
-
+{% block stock %} {% comment %}the main tab starts here {% endcomment %} + + +{% comment %}the add stock tab starts here{% endcomment %} +
+

+
+
+ {% csrf_token %} +
+ +
+ + +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
-
-
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+

OR

+
+

Insert Data using excel file

- {% comment %}the add stock tab ends here {% endcomment %} - - - {% comment %}the add medicine tab starts here {% endcomment %} -
-

-
-
{% csrf_token %} -
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- - -
- -
- -
-
- -
-
+
+ {% csrf_token %} +
+ +
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+{% comment %}the add stock tab ends here {% endcomment %} +{% comment %}the addmedicine tab starts here {% endcomment %} +
+

+
+
+ {% csrf_token %} +
+ +
+ +
+
+
+ +
+
-
-
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+

OR

+
+

Insert Data using excel file

- {% comment %}the add medicine tab ends here {% endcomment %} - - - {% comment %}the view stock tab starts here {% endcomment %} -
-
- - - +
+
+
+
+
+
+{% comment %}the add medicine tab ends here {% endcomment %} +{% comment %}the view stock tab starts here {% endcomment %} + +
+
+
+
+ +
+
+
+
+ + + - + + + + -
Medicine
- - - + - + - + + + - + + {% for view in live_meds.page_stock_view.object_list %} + - - - - - {% for view in live_meds %} - - - + - + - +
- Medicine - Supplier - Supplier - Expiry Date - Expiry Date - Quantity
- Quantity -
- {{view.medicine_id}} - + {{view.medicine_id}} + - {{view.supplier}} - {{view.supplier}} - {{view.expiry_date}} - {{view.Expiry_date}} {{view.quantity}} @@ -343,73 +641,114 @@ {% endfor %}
+ +
+ +
+ Page of {{ live_meds.count_stock_view }} +
+ +
{% comment %}the view stock tab ends here {% endcomment %} {% comment %}the view stock tab starts here {% endcomment %}
+
+
+
+ +
+
+
+ + + - - - - +
- Medicine -
+ + + - + - + - + + + - + + {% for view in expired.page_stock_expired.object_list %} + - - + - - {% for view in expired %} - + - + - + - + + {% endfor %} - + - {% if view.returned == False %} - - {% endif %} - - {% endfor %} - - -
+ Medicine + - Quantity - Quantity - Expiry Date - Expiry Date - Supplier - Supplier
- Return -
+ {{view.medicine_id}} +
{{view.quantity}} - {{view.medicine_id}} - {{view.Expiry_date}} - {{view.quantity}} - + {{view.supplier}} + - {{view.expiry_date}} -
- {{view.supplier}} -
- - -
+ +
+ +
+ Page of {{ expired.count_stock_expired }} +
+ +
- - - - - - - - - - - - - - {% for stock in stocks %} - {% if stock.quantity < stock.threshold %} - - - - - - - - {% endif %} - {% endfor %} - -
- Medicine - - Available - - Minimum -
- {{stock.medicine_name}} - - {{stock.quantity}} - - {{stock.threshold}} -
-
+ + + + + + + + + + + + {% for stock in stocks.page_stock_required.object_list %} {% if stock.quantity < stock.threshold %} + + + + + + + {% endif %} {% endfor %} + +
MedicineAvailableMinimum
{{stock.medicine_id.brand_name}}{{stock.quantity}}{{stock.threshold}}
+ +
+ +
+ Page of {{ stocks.count_stock_required }} +
+ +
+ +
+
+{% comment %}the view inventory tab ends here {% endcomment %} +{% comment %}the edit threshold tab starts here{% endcomment %} +
+

+
+
+ {% csrf_token %} +
+ +
+ +
- {% comment %}the view inventory tab ends here {% endcomment %} - -{% endblock %} + +
+
+ +

+
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+{% comment %}the edit threshold tab ends here {% endcomment %} {% endblock %} diff --git a/FusionIIIT/templates/phcModule/patientlog.html b/FusionIIIT/templates/phcModule/patientlog.html index 30143d425..5b1f4b9d2 100644 --- a/FusionIIIT/templates/phcModule/patientlog.html +++ b/FusionIIIT/templates/phcModule/patientlog.html @@ -3,7 +3,7 @@ {% block comapproval %}
+
+ + + + +
+
+
+ + +
+
+ + +
+
+ +
- +
-
+
- - - + +
+ + +
+ +
-
- -
- - -
-
+
- -
- - -
+ +
+ +
- -
- + +
+ +
+
+
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
-
+
+
+ + +
+
+
+ + +
+
+ + +
+
- - +
- +
+ + @@ -106,6 +164,7 @@
@@ -99,6 +151,12 @@ Times + Stock +
+
@@ -126,13 +185,129 @@
@@ -170,6 +363,20 @@ var user = document.getElementById('patient_b').value; var details = document.getElementById('details_b').value; var tbl = document.getElementById('sched_b'); + var medicine=[] + + for(var i=0,row;row=tbl.rows[i];i++){ + var obj= new Object(); + obj.brand_name=row.cells[0].innerText; + obj.quantity=row.cells[1].innerText; + obj.Days=row.cells[2].innerText; + obj.Times=row.cells[3].innerText; + obj.stock=row.cells[4].innerText+","+row.cells[5].innerText; + medicine[i]=obj; + console.log(obj) + } + + console.log(medicine) // Get the file input element var fileInput = document.getElementById('file'); @@ -178,16 +385,16 @@ var file = fileInput.files[0]; // Create a new FormData object - var formData = new FormData(); if(tbl.rows.length==0){ - $('#usr_b').html("Please prescribe some medicine!"); - return false; - } + $('#usr_b').html("Please prescribe some medicine!"); + return false; + } if(user=="" || details=="") { - $('#usr_b').html("Please enter all the details!"); - return false; + $('#usr_b').html("Please enter all the details!"); + return false; } + var formData = new FormData(); formData.append('csrfmiddlewaretoken', '{{ csrf_token }}') formData.append('file', file); formData.append('user', $("#patient_b").val()); @@ -195,6 +402,17 @@ formData.append('details', $("#details_b").val()); formData.append('tests', $("#tests_b").val()); formData.append('prescribe_b', $("#prescribe_b").val()); + formData.append('is_dependent',$('input[name="is_dependent"]:checked').val()); + if($('input[name="is_dependent"]:checked').val()=="dependent"){ + var dep_name = document.getElementById('dep_name').value + if($('input[name="is_dependent"]:checked').val()=="dependent" && dep_name == "No Dependent"){ + alert("dependent not valid") + return false; + } + formData.append('dependent_name',$("#dep_name").val().split(',')[0]); + formData.append('dependent_relation',$("#dep_rel").val()); + } + formData.append('pre_medicine',JSON.stringify(medicine)); $.ajax({ type:'post', url:'/healthcenter/compounder/', @@ -210,7 +428,9 @@ $('#sched_b').empty(); window.location.reload(); } - + else if(data.status == -1){ + aleart("enter valid patient id") + } else { if(data.status == 0) alert("Prescription failed!, not enough medicine available in stock"); @@ -225,8 +445,16 @@
- + +
+
+ +
+
+ +
+
- - - - - - - - {% for pre in presc_hist %} + + {% for pre in presc_hist.page.object_list %} @@ -289,38 +505,58 @@

{{pre.details}}

- - - - {% endfor %} -
@@ -244,25 +472,13 @@ Details - Test - - Report - - - -
MedicineDT
+ View
@@ -276,7 +492,7 @@

- {{pre.doctor_id}} + {{pre.doctor_id}}
- {{pre.test}} - - {% if pre.file %} - - - - {% endif %} + - - {% for medicine in medicines_presc %} - {% if medicine.prescription_id.id == pre.id %} - - {% endif %} - {% endfor%} -
{{medicine.medicine_id}}{{medicine.days}}{{medicine.times}}
-
+
+
+ + + + + + +
diff --git a/FusionIIIT/templates/phcModule/phc_compounder.html b/FusionIIIT/templates/phcModule/phc_compounder.html index 5acfb337a..575a3ce65 100644 --- a/FusionIIIT/templates/phcModule/phc_compounder.html +++ b/FusionIIIT/templates/phcModule/phc_compounder.html @@ -82,7 +82,7 @@ {% comment %}The left-rail segment ends here!{% endcomment %} {% comment %}The central-rail segment starts here!{% endcomment %} -
+
{% comment %}The complaint/feedback starts here!{% endcomment %}
{% block feedback %} @@ -94,7 +94,7 @@ {% comment %}The ap `pointment approval tab starts here!{% endcomment %}
{% block patientlog %} - {% include 'phcModule/patientlog.html' with all_hospitals=all_hospitals all_ambulances=all_ambulances appointments_today=appointments_today appointments_approve=appointments_approve %} + {% include 'phcModule/patientlog.html' with live_meds=live_meds %} {% endblock %}
{% comment %}The appointment approval tab ends here!{% endcomment %} @@ -109,9 +109,9 @@ {% comment %}The Manage Stocks Form starts here!{% endcomment %} -
+
{% block stock %} - {% include 'phcModule/manage_stock.html' with stocks=stocks inventories=inventories %} + {% include 'phcModule/manage_stock.html' with medicine=medicine stocks=stocks inventories=inventories %} {% endblock %}
{% comment %}The Manage Stocks Form ends here!{% endcomment %} diff --git a/FusionIIIT/templates/phcModule/phc_compounder_view_prescription.html b/FusionIIIT/templates/phcModule/phc_compounder_view_prescription.html new file mode 100644 index 000000000..0b77908ad --- /dev/null +++ b/FusionIIIT/templates/phcModule/phc_compounder_view_prescription.html @@ -0,0 +1,970 @@ +{% extends 'globals/base.html' %} +{% load static %} + +{% block title %} + Home +{% endblock %} + +{% block body %} + + + {% block navBar %} + {% include 'dashboard/navbar.html' %} + {% endblock %} + + {% comment %}The grid starts here!{% endcomment %} +
+ + {% comment %}The left-margin segment!{% endcomment %} +
+ + {% comment %}The left-rail segment starts here!{% endcomment %} +
+ {% comment %}The left-rail segment ends here!{% endcomment %} + + {% comment %}The central-rail segment starts here!{% endcomment %} +
+ + {% comment %}The ap `pointment approval tab starts here!{% endcomment %} +
+ + {% block patientlog %} +
+
+

{{prescription.user_id}}'s Prescription History

+
+
+
+
+ +
+
+ + +
+
+
+
{% csrf_token %} +

+
+ + +
+ +
+ + +
+ + + + + + + + + + + + + + + + + + {% for med in pre_medicine %} + {% if med.revoked == False %} + + + + + + + + + + {% endif %} + {% endfor %} + +
+ Medicine id + + Medicine + + Quantity + + Days + + Times + + Expiry Date + + revoke +
+ {{med.id}} + + {{med.medicine_id.brand_name}} + + {{med.quantity}} + + {{med.days}} + + {{med.times}} + + {{med.stock}} + + +
+ +
+
+ +
+ + +
+ + +
+ +
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + + + + + + + + + + + + + + + + +
+ + +
+
+ +
+ +
+
+
+ + +
+
+
+
+
+
+ + + + {% for f_pres in follow_presc %} + + {% endfor %} + +
+
+ +
+ + + + {% endblock %} +
+
+ + {% comment %}The central-rail segment ends here!{% endcomment %} + + {% comment %}The right-rail segment starts here!{% endcomment %} +
+ {% comment %}
+ {% block sidepanel %} {% include 'notifications/sidepanel.html' with notifications=notifications %} + {% endblock %} +
{% endcomment %} +
+ {% comment %}The right-rail segment ends here!{% endcomment %} + +
+
+ {% comment %}The right-margin segment!{% endcomment %} +
+ +
+ {% comment %}The grid ends here!{% endcomment %} + + + + +{% endblock %} + +{% block javascript %} + + + + + + + +{% endblock %} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 9cf0fb09a..4b97f144f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -52,7 +52,7 @@ PyJWT==2.6.0 PyPDF2==1.26.0 pyrsistent==0.17.3 python-bidi==0.4.2 -python-dateutil==2.8.1 +python-dateutil==2.9.0 python3-openid==3.2.0 pytz==2020.5 reportlab==3.5.59 @@ -73,3 +73,4 @@ XlsxWriter==1.3.7 xlwt==1.3.0 django-crontab==0.7.1 zipfile2==0.0.12 +pandas==2.0.3