Skip to content

Commit

Permalink
OS-2: Week 11: Fixed Hospital System and Medicine System (#1253)
Browse files Browse the repository at this point in the history
  • Loading branch information
divyanshkhetan authored Apr 17, 2023
1 parent 657eff9 commit c5a3ff7
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.1.5 on 2023-04-16 17:55

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('health_center', '0004_auto_20230411_1342'),
]

operations = [
migrations.RemoveField(
model_name='doctor',
name='contact_no',
),
migrations.AlterField(
model_name='doctor',
name='doctor_phone',
field=models.CharField(default='0000000000', max_length=10, validators=[django.core.validators.MinLengthValidator(10)]),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.1.5 on 2023-04-16 18:22

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('health_center', '0005_auto_20230416_1755'),
]

operations = [
migrations.RemoveField(
model_name='hospital',
name='phone',
),
migrations.AddField(
model_name='hospital',
name='hospital_address',
field=models.CharField(default='', max_length=255),
),
migrations.AddField(
model_name='hospital',
name='hospital_phone',
field=models.CharField(default='0000000000', max_length=10, validators=[django.core.validators.MinLengthValidator(10)]),
),
]
8 changes: 4 additions & 4 deletions FusionIIIT/applications/health_center/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ class Constants:
class Doctor(models.Model):
# doctor_name = models.IntegerField(choices=Constants.NAME_OF_DOCTOR)
doctor_name = models.CharField(max_length=200)
doctor_phone = models.CharField(max_length=10)
doctor_phone = models.CharField(max_length=10, validators=[MinLengthValidator(10)], default="0000000000")
specialization = models.CharField(max_length=100)
active = models.BooleanField(default=True)
contact_no = models.CharField(max_length=10, validators=[MinLengthValidator(10)], default="0000000000")

def __str__(self):
return self.doctor_name
Expand Down Expand Up @@ -60,11 +59,12 @@ class Medicine(models.Model):
times = models.IntegerField(default=0)

def __str__(self):
return self.medicine_id
return self.medicine_id.medicine_name

class Hospital(models.Model):
hospital_name=models.CharField(max_length=100)
phone=models.CharField(max_length=10)
hospital_address=models.CharField(max_length=255, default="")
hospital_phone=models.CharField(max_length=10, validators=[MinLengthValidator(10)], default="0000000000")
def __str__(self):
return self.hospital_name

Expand Down
20 changes: 18 additions & 2 deletions FusionIIIT/applications/health_center/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def compounder_view_handler(request):
test=tests,
appointment=appointment
)
query = Medicine.objects.select_related('patient','patient__user','patient__department').objects.filter(patient=user)
prescribe = Prescription.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','appointment','appointment__user_id','appointment__user_id__user','appointment__user_id__department','appointment__doctor_id','appointment__schedule','appointment__schedule__doctor_id').objects.all().last()
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','appointment','appointment__user_id','appointment__user_id__user','appointment__user_id__department','appointment__doctor_id','appointment__schedule','appointment__schedule__doctor_id').all().last()
for medicine in query:
medicine_id = medicine.medicine_id
quantity = medicine.quantity
Expand Down Expand Up @@ -296,6 +296,7 @@ def compounder_view_handler(request):
healthcare_center_notif(request.user, user.user, 'presc')
data = {'status': status, 'stock': stock}
return JsonResponse(data)

elif 'prescribe_b' in request.POST:
user_id = request.POST.get('user')
user = ExtraInfo.objects.select_related('user','department').get(id=user_id)
Expand Down Expand Up @@ -363,16 +364,31 @@ def compounder_view_handler(request):
healthcare_center_notif(request.user, user.user, 'presc')
data = {'status': status}
return JsonResponse(data)

elif 'cancel_presc' in request.POST:
presc_id = request.POST.get('cancel_presc')
Prescription.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','appointment','appointment__user_id','appointment__user_id__user','appointment__user_id__department','appointment__doctor_id','appointment__schedule','appointment__schedule__doctor_id').filter(pk=presc_id).delete()
data = {'status': 1}
return JsonResponse(data)

elif 'medicine' in request.POST:
med_id = request.POST.get('medicine')
thresh = Stock.objects.get(id=med_id).threshold
data = {'thresh': thresh}
return JsonResponse(data)

elif 'add_hospital' in request.POST:
hospital_name=request.POST.get('hospital_name')
hospital_address=request.POST.get('hospital_address')
hospital_phone=request.POST.get('hospital_phone')
print(hospital_name,hospital_address,hospital_phone)
Hospital.objects.create(
hospital_name=hospital_name,
hospital_address=hospital_address,
hospital_phone=hospital_phone,
)
data={'status':1, 'hospital_name':hospital_name, 'hospital_address':hospital_address, 'hospital_phone':hospital_phone}
return JsonResponse(data)

def student_view_handler(request):
if 'amb_submit' in request.POST:
Expand Down
12 changes: 3 additions & 9 deletions FusionIIIT/applications/health_center/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def compounder_view(request):
stocks = Stock.objects.all()
days = Constants.DAYS_OF_WEEK
schedule=Schedule.objects.select_related('doctor_id').all().order_by('doctor_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')
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(expiry_date__gte=datetime.now(), returned=False).order_by('quantity')
count=Counter.objects.all()
presc_hist=Prescription.objects.select_related('user_id','user_id__user','user_id__department','doctor_id','appointment','appointment__user_id','appointment__user_id__user','appointment__user_id__department','appointment__doctor_id','appointment__schedule','appointment__schedule__doctor_id').all().order_by('-date')
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','prescription_id__appointment','prescription_id__appointment__user_id','prescription_id__appointment__user_id__user','prescription_id__appointment__user_id__department','prescription_id__appointment__doctor_id','prescription_id__appointment__schedule','prescription_id__appointment__schedule__doctor_id','medicine_id').all()
Expand All @@ -95,6 +95,7 @@ def compounder_view(request):

# doct= ["Dr. G S Sandhu", "Dr. Jyoti Garg", "Dr. Arvind Nath Gupta"]

print(live_meds.values())

return render(request, 'phcModule/phc_compounder.html',
{'days': days, 'users': users, 'count': count,'expired':expired,
Expand Down Expand Up @@ -145,13 +146,6 @@ def student_view(request):
doctors=Doctor.objects.filter(active=True)
count=Counter.objects.all()

# Snippet to add prescription for an appointment
for pres in prescription:
for appointment in appointments:
if pres.appointment.pk == appointment.pk:
appointment['prescription_on_appointment'] = pres
break

if count:
Counter.objects.all().delete()
Counter.objects.create(count=0,fine=0)
Expand Down
128 changes: 115 additions & 13 deletions FusionIIIT/templates/phcModule/comp_prescription.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
{% comment %}the compounder prescription tab starts here {% endcomment %}
<div class="ui pointing secondary menu">
<a class="active item" data-tab="prescribe_app">
Prescribe with Appointment
Prescribe with Appointment
</a>
<a class="item" data-tab="prescribe">
Prescribe without Appointment
Prescribe without Appointment
</a>
<a class="item" data-tab="hospitaladmit">
Hospital Admission
Hospital Admission
</a>
<a class="item" data-tab="addhospital">
Add Hospital
</a>
</div>
{% comment %}the prescribe tab starts here {% endcomment %}
Expand All @@ -22,17 +25,27 @@
<form class="ui form" method="POST">{% csrf_token %}
<p id="usr"></p>

<div class="two fields">
<div class="field">
<label>Patient</label>
<select class="ui search fluid" id="user" name="user" required="true">
<select class="ui search fluid dropdown" id="user" name="user" required="true">
<option value="" disabled selected>--SELECT--</option>
{% for a in appointments_today %}
<option value="{{a.id}}">{{a.user_id.id}}-{{a.user_id.user}}</option>
{% endfor %}
</select>
</div>

</div>

<div class="field">
<label>Doctor</label>
<select class="ui search fluid dropdown" name="doctor" id="doctor" required="true">
<option value="" disabled selected>--SELECT--</option>
{% for doctor in doctors %}
<option value="{{doctor.id}}">{{doctor.doctor_name}}</option>
{% endfor %}
</select>
</div>
</div>

<div class="field">
<label>Detail of Disease</label>
Expand Down Expand Up @@ -120,6 +133,7 @@
$('#medicine').click(function(e){
$("#sched tr").remove();
var user = document.getElementById('user').value;
var doctor = document.getElementById('doctor').value;
var quantity = document.getElementById('quantity').value;
var medicine = document.getElementById('medicine_id').value;
var days = document.getElementById('days').value;
Expand All @@ -135,14 +149,15 @@
data: {
csrfmiddlewaretoken: '{{ csrf_token }}',
user:$("#user").val(),
doctor:$("#doctor").val(),
quantity:$("#quantity").val(),
medicine_name:$("#medicine_id").val(),
days:$("#days").val(),
times:$("#times").val()
},
success: function(data){

alert("added medicine");
alert("Added Medicine!");
document.getElementById("quantity").value="";
document.getElementById("medicine_id").value="";
document.getElementById("days").value="";
Expand Down Expand Up @@ -185,7 +200,7 @@
},
success: function(data){
if (data.status == 1 ){
alert("prescribed medicine");
alert("Prescription Added!");
document.getElementById("details").value="";
document.getElementById("tests").value="";
$('#sched').empty();
Expand All @@ -210,13 +225,14 @@
style="padding-left: 3.5%;
padding-right: 3.5%;">

<form class="ui form" method="POST">{% csrf_token %}
<form class="ui form" method="POST">
{% csrf_token %}
<p id="usr_b"></p>
<div class="two fields">
<div class="field">
<label>Patient</label>
<div class="ui fluid large input">
<input placeholder="Patient Id" id="patient_b" name="patient_b" type="number">
<input placeholder="Patient Id" id="patient_b" name="patient_b" type="text">
</div>
</div>

Expand Down Expand Up @@ -338,7 +354,7 @@
times:$("#times_b").val()
},
success: function(data){
alert("added medicine");
alert("Added Medicine!");
document.getElementById("quantity_b").value="";
document.getElementById("medicine_id_b").value="";
document.getElementById("days_b").value="";
Expand Down Expand Up @@ -381,7 +397,7 @@
},
success: function(data){
if (data.status == 1){
alert("prescribed medicine");
alert("Prescription Added!");
document.getElementById("doctor_b").value="";
document.getElementById("details_b").value="";
document.getElementById("tests_b").value="";
Expand Down Expand Up @@ -524,11 +540,97 @@ <h4>*Admission details for outside hospitals</h4>
});
});

</script>
</script>
<br>
<br>
</div>
</div>

{% comment %}the add hospital tab starts here {% endcomment %}
<div class="ui tab" data-tab="addhospital">
<p id="hosp_add" style="width: 100%; text-align: center;"></p>
<div class="ui vertical segment">
<form class="ui form" method="POST" style="padding: 8px; padding-left: 24px; padding-right: 24px;">
{% csrf_token %}

<div class="field">
<label>Hospital Name</label>
<div class="ui fluid large input">
<input placeholder="Hospital Name" id="new_hospital_name" name="new_hospital_name" type="text">
</div>
</div>

<div class="field">
<label>Address</label>
<div class="ui fluid large input">
<input placeholder="Hospital Address" id="hospital_address" name="hospital_address" type="text">
</div>
</div>

<div class="field">
<label>Phone Number</label>
<div class="ui fluid large input">
<input placeholder="Phone Number" id="hospital_phone" name="hospital_phone" type="number">
</div>
</div>

<div class="field">
<label><br></label>
<div >
<input type="button" id="add_hospital" name="add_hospital" value="Submit" class="ui large right floated primary button" />
</div>
</div>
</form>
<script type="text/javascript">
$('#add_hospital').click(function (e) {
$('#hosp_add').html('');
console.log(document.querySelector('#new_hospital_name'))
var new_hospital_name = document.getElementById('new_hospital_name').value;
var hospital_address = document.getElementById('hospital_address').value;
var hospital_phone = document.getElementById('hospital_phone').value;
if (new_hospital_name == "" || hospital_address == "") {
$('#hosp_add').html('Enter valid details');
console.log("Hospital Name: ", hospital_name, "Length: ", hospital_name.length);
console.log("Hospital Address: ", hospital_address, "Length: ", hospital_address.length);
return false;
}
if (hospital_phone.toString().length != 10) {
$('#hosp_add').html('Enter valid phone number');
return false;
}
if (hospital_address.length > 255) {
$('hosp_add').html('Enter a shorter address!');
return false;
}

$.ajax({
type: 'POST',
url: '/healthcenter/compounder/',
data: {
csrfmiddlewaretoken: '{{ csrf_token }}',
hospital_name: $("#new_hospital_name").val(),
hospital_address: $("#hospital_address").val(),
hospital_phone: $("#hospital_phone").val(),
add_hospital: $('#add_hospital').val()
},
success: function (data) {
alert("Added Hospital!");

document.getElementById("new_hospital_name").value = "";
document.getElementById("hospital_address").value = "";
document.getElementById("hospital_phone").value = "";
window.location.reload();
}
});
});

</script>
<br>
<br>
</div>
</div>
{% comment %}the add doctor tab ends here {% endcomment %}

<br>
<div class="extra segment"></div>

Expand Down
Loading

0 comments on commit c5a3ff7

Please sign in to comment.