Skip to content

Commit 2f8768b

Browse files
authored
Merge pull request #3 from Samcoodess/dev
Schedule appointment step 1 takes location using OpenCage
2 parents 0c4bb3f + 06c5db0 commit 2f8768b

27 files changed

+430
-228
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,4 @@ cython_debug/
163163

164164
# Folders
165165
backup/
166+
appointments/templates/appointments/schedule_step1.html

heal-diapp/appointments/forms.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
# appointments/forms.py
2+
23
from django import forms
34
from .models import Appointment
45

56
class Step1Form(forms.ModelForm):
67
class Meta:
78
model = Appointment
8-
fields = ['name', 'age', 'location', 'note']
9+
fields = ['location']
910

1011
class Step2Form(forms.ModelForm):
1112
class Meta:
1213
model = Appointment
13-
fields = ['date_time']
14-
widgets = {
15-
'date_time': forms.DateInput(attrs={'type': 'datetime-local'}),
16-
# Add any additional widgets for other fields
17-
}
18-
class Step3Form(forms.Form):
19-
confirmation_message = forms.CharField(
20-
label='Confirmation Message',
21-
widget=forms.Textarea(attrs={'rows': 4})
22-
)
14+
fields = ['name', 'address']

heal-diapp/appointments/migrations/0001_initial.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

heal-diapp/appointments/migrations/0002_appointment_notes.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

heal-diapp/appointments/migrations/0003_rename_healthcare_provider_appointment_location_and_more.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

heal-diapp/appointments/migrations/0004_alter_appointment_date_time.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

heal-diapp/appointments/migrations/__init__.py

Whitespace-only changes.

heal-diapp/appointments/models.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1+
# appointments/models.py
2+
13
from django.db import models
2-
from django.contrib.auth import get_user_model
3-
from django.utils import timezone
4+
from accounts.models import User
45

56
class Appointment(models.Model):
6-
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name='appointments_as_user')
7-
name = models.CharField(max_length=255, blank=True)
8-
age = models.PositiveIntegerField(default=0) # Set a suitable default value
9-
location = models.CharField(max_length=255)
10-
note = models.TextField(default= 'I will call')
11-
date_time = models.DateTimeField(default=timezone.now) # Set a default value
12-
confirmation_message = models.TextField(default='Your appointment is confirmed') # Set a suitable default value
13-
14-
def save(self, *args, **kwargs):
15-
# Set the default value for the 'name' field to the user's first name
16-
if not self.name and self.user:
17-
self.name = self.user.first_name
18-
19-
super().save(*args, **kwargs)
20-
7+
doctor = models.ForeignKey(User, on_delete=models.CASCADE, related_name='doctor_appointments', default=None)
8+
patient = models.ForeignKey(User, on_delete=models.CASCADE, related_name='patient_appointments', default=None)
9+
location = models.CharField(max_length=255, default=None)
10+
name = models.CharField(max_length=255, default=None)
11+
address = models.TextField(default='opt out')
2112

2213
def __str__(self):
23-
return f"{self.user.username} - {self.name} - {self.date_time}"
14+
return f"{self.doctor.email} - {self.patient.email}"
15+

heal-diapp/appointments/templates/appointments/appointment_wizard.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ <h2>Schedule an Appointment - Step {{ wizard.steps.step1 }} of {{ wizard.steps.c
2424
{% endif %}
2525
</form>
2626

27-
<h3>Debug Information:</h3>
27+
<!-- <h3>Debug Information:</h3>
2828
<p>Current Step: {{ wizard.steps.current }}</p>
2929
<p>Available Forms: {{ wizard.form.forms|default:'No forms' }}</p>
30-
<p>Current Step Forms: {{ wizard.form[wizard.steps.current].forms|default:'No forms' }}</p>
30+
<p>Current Step Forms: {{ wizard.form[wizard.steps.current].forms|default:'No forms' }}</p> -->
3131
{% endblock %}
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
{% extends 'base.html' %}
2+
3+
{% block title %}Schedule Appointment - Step 1{% endblock %}
4+
5+
6+
{% block content %}
7+
<style>
8+
.appointment-form {
9+
position: relative;
10+
z-index: 1;
11+
}
12+
13+
.form-control {
14+
width: 100%;
15+
height: 50px;
16+
background-color: rgba(0, 0, 0, 0.3);
17+
border-radius: 2px;
18+
border: none;
19+
color: #fff;
20+
font-size: 12px;
21+
padding: 0 30px;
22+
font-style: italic;
23+
}
24+
25+
.form-control:focus {
26+
box-shadow: none;
27+
}
28+
29+
select {
30+
appearance: none;
31+
-moz-appearance: none;
32+
}
33+
34+
select option {
35+
width: 100%;
36+
height: 40px;
37+
background-color: #fff;
38+
color: #000; /* Replace with your desired color */
39+
}
40+
41+
textarea.form-control {
42+
padding: 30px;
43+
height: 120px;
44+
}
45+
46+
#location-prompt,
47+
#location-confirm {
48+
max-width: 400px;
49+
margin: 0 auto;
50+
text-align: center;
51+
padding: 20px;
52+
background-color: #fff;
53+
border-radius: 8px;
54+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
55+
margin-top: 20px;
56+
}
57+
58+
#location-prompt p,
59+
#location-confirm p {
60+
font-size: 16px;
61+
margin-bottom: 15px;
62+
}
63+
64+
#location-prompt button,
65+
#location-confirm button {
66+
background-color: #007bff;
67+
color: #fff;
68+
border: none;
69+
padding: 10px 20px;
70+
font-size: 14px;
71+
cursor: pointer;
72+
border-radius: 4px;
73+
margin-top: 10px;
74+
}
75+
76+
#location-prompt button:hover,
77+
#location-confirm button:hover {
78+
background-color: #0056b3;
79+
}
80+
</style>
81+
82+
<h2>Schedule Appointment - Step 1</h2>
83+
84+
<div id="location-prompt" style="display: none;">
85+
<p>Healdi is requesting your location. Click the button below to share your location.</p>
86+
<button onclick="requestLocation()">Share Location</button>
87+
</div>
88+
89+
<div id="location-confirm" style="display: none;">
90+
<p>Is this your correct location?</p>
91+
<p id="location-display"></p>
92+
<button onclick="submitForm()">Yes, Confirm</button>
93+
<button onclick="showLocationPrompt()">No, Retry</button>
94+
</div>
95+
96+
<form method="post" action="{% url 'schedule_step2' %}" class="appointment-form" id="appointment-form">
97+
{% csrf_token %}
98+
<!-- Other form fields go here -->
99+
100+
<input type="hidden" name="latitude" id="latitude" value="">
101+
<input type="hidden" name="longitude" id="longitude" value="">
102+
<input type="hidden" name="city" id="city" value="">
103+
<input type="hidden" name="state" id="state" value="">
104+
<input type="hidden" name="country" id="country" value="">
105+
<input type="hidden" name="zip_code" id="zip_code" value="">
106+
107+
<input type="submit" value="Next" style="display: none;">
108+
</form>
109+
110+
111+
112+
<script>
113+
function requestLocation() {
114+
if (navigator.geolocation) {
115+
navigator.geolocation.getCurrentPosition(
116+
function(position) {
117+
// Update hidden form fields with latitude and longitude
118+
document.getElementById('latitude').value = position.coords.latitude;
119+
document.getElementById('longitude').value = position.coords.longitude;
120+
121+
// Reverse geocode the location
122+
reverseGeocode(position.coords.latitude, position.coords.longitude);
123+
},
124+
function(error) {
125+
console.error("Error getting user's location: " + error.message);
126+
// Handle error, show a message, or provide an alternative
127+
}
128+
);
129+
} else {
130+
console.log("Geolocation is not supported by this browser.");
131+
// Handle the case where geolocation is not supported
132+
}
133+
}
134+
135+
function reverseGeocode(latitude, longitude) {
136+
var apiKey = 'API';
137+
var apiUrl = `https://api.opencagedata.com/geocode/v1/json?key=${apiKey}&q=${latitude}+${longitude}&pretty=1`;
138+
139+
fetch(apiUrl)
140+
.then(response => response.json())
141+
.then(data => {
142+
// Display location details for confirmation
143+
var locationDetails = `City: ${data.results[0].components.city},
144+
State: ${data.results[0].components.state},
145+
Country: ${data.results[0].components.country},
146+
Zip Code: ${data.results[0].components.postcode}`;
147+
148+
document.getElementById('location-display').innerText = locationDetails;
149+
150+
// Update hidden form fields with location details
151+
document.getElementById('city').value = data.results[0].components.city;
152+
document.getElementById('state').value = data.results[0].components.state;
153+
document.getElementById('country').value = data.results[0].components.country;
154+
document.getElementById('zip_code').value = data.results[0].components.postcode;
155+
156+
// Show confirmation prompt
157+
showLocationConfirm();
158+
})
159+
.catch(error => {
160+
console.error("Error in reverse geocoding: " + error.message);
161+
// Handle error, show a message, or provide an alternative
162+
});
163+
}
164+
165+
function showLocationConfirm() {
166+
document.getElementById('location-prompt').style.display = 'none';
167+
document.getElementById('location-confirm').style.display = 'block';
168+
}
169+
170+
function showLocationPrompt() {
171+
document.getElementById('location-prompt').style.display = 'block';
172+
document.getElementById('location-confirm').style.display = 'none';
173+
}
174+
175+
function submitForm() {
176+
// Optionally, you can add more logic here before submitting the form
177+
document.getElementById('appointment-form').submit();
178+
}
179+
180+
document.addEventListener('DOMContentLoaded', function() {
181+
// Display the location prompt when the page loads
182+
document.getElementById('location-prompt').style.display = 'block';
183+
});
184+
</script>
185+
{% endblock %}

0 commit comments

Comments
 (0)