From 6dfd86b68fabd3c9da033f44a1c8de639658fe6d Mon Sep 17 00:00:00 2001 From: Kyle Aquino Date: Sun, 7 Apr 2024 21:41:27 +0800 Subject: [PATCH 1/3] Fix doctor and patuent forms --- doctor/forms.py | 23 +++-- .../doctor/components/base/header.html | 13 +++ .../doctor/components/base/navbar.html | 35 +++++++ .../doctor/components/base/sidebar.html | 47 +++++++++ doctor/templates/doctor/index.html | 40 ++------ doctor/templates/doctor/pages/dashboard.html | 43 +++------ doctor/templates/doctor/pages/facilities.html | 22 ----- doctor/templates/doctor/pages/patients.html | 22 ----- doctor/templates/doctor/pages/referrals.html | 22 ----- doctor/templates/doctor/partials/header.html | 21 ---- doctor/templates/doctor/partials/sidebar.html | 95 ------------------- facility/forms/doctor_forms.py | 3 +- .../facility/pages/doctors/doctor-create.html | 6 ++ .../pages/doctors/doctor-details.html | 47 ++++++++- facility/views/doctor_views.py | 6 +- patient/forms.py | 13 ++- .../templates/patient/forms/patient-form.html | 47 --------- user/forms.py | 48 +++++++++- user/templates/account/form.html | 10 -- .../account/pages/auth/account-selection.html | 2 +- .../setup-account/doctor-registration.html | 7 +- .../setup-account/patient-registration.html | 64 +++---------- user/views.py | 26 ++--- 23 files changed, 267 insertions(+), 395 deletions(-) create mode 100644 doctor/templates/doctor/components/base/header.html create mode 100644 doctor/templates/doctor/components/base/navbar.html create mode 100644 doctor/templates/doctor/components/base/sidebar.html delete mode 100644 doctor/templates/doctor/pages/facilities.html delete mode 100644 doctor/templates/doctor/pages/patients.html delete mode 100644 doctor/templates/doctor/pages/referrals.html delete mode 100644 doctor/templates/doctor/partials/header.html delete mode 100644 doctor/templates/doctor/partials/sidebar.html delete mode 100644 patient/templates/patient/forms/patient-form.html delete mode 100644 user/templates/account/form.html diff --git a/doctor/forms.py b/doctor/forms.py index aefe962..f257474 100644 --- a/doctor/forms.py +++ b/doctor/forms.py @@ -4,11 +4,6 @@ from doctor.models import Doctor from user.models import User -# Note: -# - Utilize Manager Object for doctor creation -# - Mixins for forms -# - Create a process for existing doctors, invite link or direct invite - class BaseDoctorForm(forms.ModelForm): GENDER_TYPES = [ @@ -23,8 +18,18 @@ class BaseDoctorForm(forms.ModelForm): registration_number = forms.CharField(label="PRC License No.", max_length=55) specialization = forms.CharField(max_length=55) + def __init__(self, *args, **kwargs): + instance = kwargs.get("instance") + if instance: + self.base_fields["email"].required = False + + super().__init__(*args, **kwargs) + def clean_mobile(self): mobile = str(self.cleaned_data.get("mobile")).strip() + if self.instance.pk: + return mobile + pattern = r"^((\+?63)|0|9)(9\d{9})$" if not re.match(pattern, mobile): self.add_error(field="mobile", error="Use a Philippine Mobile Number ex. (09123456789 or +639123456789)") @@ -34,10 +39,10 @@ def clean_mobile(self): def save(self, commit=True): user: User = super().save() doctor = Doctor.objects.get_or_create(user=user)[0] - doctor.gender = self.cleaned_data["gender"] - doctor.registration_number = self.cleaned_data["registration_number"] - doctor.experience_years = self.cleaned_data["experience_years"] - doctor.specialization = self.cleaned_data["specialization"] + doctor.gender = self.cleaned_data.get("gender") + doctor.registration_number = self.cleaned_data.get("registration_number") + doctor.experience_years = self.cleaned_data.get("experience_years") + doctor.specialization = self.cleaned_data.get("specialization") doctor.save() return doctor diff --git a/doctor/templates/doctor/components/base/header.html b/doctor/templates/doctor/components/base/header.html new file mode 100644 index 0000000..4195c8c --- /dev/null +++ b/doctor/templates/doctor/components/base/header.html @@ -0,0 +1,13 @@ +
+
+
+ + {% include 'patient/components/base/navbar.html'%} +
+
+
diff --git a/doctor/templates/doctor/components/base/navbar.html b/doctor/templates/doctor/components/base/navbar.html new file mode 100644 index 0000000..e3cdb7d --- /dev/null +++ b/doctor/templates/doctor/components/base/navbar.html @@ -0,0 +1,35 @@ +
+
+
+ + + Welcome, {{ user.first_name }}! + + + +
+ +
+
diff --git a/doctor/templates/doctor/components/base/sidebar.html b/doctor/templates/doctor/components/base/sidebar.html new file mode 100644 index 0000000..6c60e01 --- /dev/null +++ b/doctor/templates/doctor/components/base/sidebar.html @@ -0,0 +1,47 @@ + diff --git a/doctor/templates/doctor/index.html b/doctor/templates/doctor/index.html index 6bd8eaf..79918c2 100644 --- a/doctor/templates/doctor/index.html +++ b/doctor/templates/doctor/index.html @@ -1,36 +1,8 @@ -{% extends 'layout/master.html' %} +{% extends 'theme/base.html' %} -{% block layout %} - -
- -
- {% include 'doctor/partials/header.html' %} - -
- {% include 'doctor/partials/sidebar.html' %} - -
- -
- -
- -
- {% block content %} {% endblock content %} -
- -
- -
- -
- -
- -
- +{% block content %} +
+ {% include 'doctor/components/base/sidebar.html' %} + {% block main %} {% endblock %}
- - -{% endblock layout %} +{% endblock %} diff --git a/doctor/templates/doctor/pages/dashboard.html b/doctor/templates/doctor/pages/dashboard.html index 1a04dd9..6d969cf 100644 --- a/doctor/templates/doctor/pages/dashboard.html +++ b/doctor/templates/doctor/pages/dashboard.html @@ -1,33 +1,18 @@ -{% extends 'doctor/index.html' %} +{% extends "doctor/index.html" %} -{% block content %} -
-
-
-

Doctor Dashboard

- -
-
-
-
-
-
-
-

- Welcome {{ user.get_full_name }} and you're currently signed in - under the email {{ user.email }}.
- Navigate through the Apollo system using the bar on the left-hand side of the browser. -

-
-
+{% load static %} + +{% block main %} +
+
+

+
Welcome back, {{ user.first_name }}
+
Medsync Doctor Account
+

+ + + Send a referral +
{% endblock %} diff --git a/doctor/templates/doctor/pages/facilities.html b/doctor/templates/doctor/pages/facilities.html deleted file mode 100644 index 5cee99d..0000000 --- a/doctor/templates/doctor/pages/facilities.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends 'doctor/index.html' %} - -{% block content %} -
-
-
-

- Facilities -

- -
-
-
-{% endblock %} diff --git a/doctor/templates/doctor/pages/patients.html b/doctor/templates/doctor/pages/patients.html deleted file mode 100644 index ea78b04..0000000 --- a/doctor/templates/doctor/pages/patients.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends 'doctor/index.html' %} - -{% block content %} -
-
-
-

- Patients -

- -
-
-
-{% endblock %} diff --git a/doctor/templates/doctor/pages/referrals.html b/doctor/templates/doctor/pages/referrals.html deleted file mode 100644 index 4ae6317..0000000 --- a/doctor/templates/doctor/pages/referrals.html +++ /dev/null @@ -1,22 +0,0 @@ -{% extends 'doctor/index.html' %} - -{% block content %} -
-
-
-

- Referrals -

- -
-
-
-{% endblock %} diff --git a/doctor/templates/doctor/partials/header.html b/doctor/templates/doctor/partials/header.html deleted file mode 100644 index fa7cc34..0000000 --- a/doctor/templates/doctor/partials/header.html +++ /dev/null @@ -1,21 +0,0 @@ -{% load static %} -
-
-
-
- -
-
-
- - Logo - -
-
-
- {% include 'partials/header-user-menu-toggle.html'%} -
-
-
-
diff --git a/doctor/templates/doctor/partials/sidebar.html b/doctor/templates/doctor/partials/sidebar.html deleted file mode 100644 index a908f06..0000000 --- a/doctor/templates/doctor/partials/sidebar.html +++ /dev/null @@ -1,95 +0,0 @@ -{% load static %} - - - - - diff --git a/facility/forms/doctor_forms.py b/facility/forms/doctor_forms.py index 1f5e886..7cefd38 100644 --- a/facility/forms/doctor_forms.py +++ b/facility/forms/doctor_forms.py @@ -20,6 +20,7 @@ def setup_form_layout(self): "registration_number", "experience_years", "specialization", + "email", "mobile", "birth_date", "gender", @@ -29,5 +30,5 @@ def setup_form_layout(self): def save(self, commit=True): doctor: Doctor = super().save() - self.facility.patients.add(doctor) + self.facility.doctors.add(doctor) return doctor diff --git a/facility/templates/facility/pages/doctors/doctor-create.html b/facility/templates/facility/pages/doctors/doctor-create.html index 1b79754..69f87dd 100644 --- a/facility/templates/facility/pages/doctors/doctor-create.html +++ b/facility/templates/facility/pages/doctors/doctor-create.html @@ -17,3 +17,9 @@

Add Doctor

{% endblock %} + +{% block postscripts %} + +{% endblock %} diff --git a/facility/templates/facility/pages/doctors/doctor-details.html b/facility/templates/facility/pages/doctors/doctor-details.html index 723494f..3acd656 100644 --- a/facility/templates/facility/pages/doctors/doctor-details.html +++ b/facility/templates/facility/pages/doctors/doctor-details.html @@ -1,12 +1,51 @@ {% extends "facility/index.html" %} -{% load static %} +{% load static crispy_forms_tags %} {% block main %}
-

{{ page_title }}

-
- No Data to Display +
+
+ +

Doctor Details

+ {% include 'theme/general/components/navigation/breadcrumbs.html' %} +
+
+
+
+

Doctor Information

+
+
+

Doctor Code

+

{{ doctor.doctor_code }}

+
+
+

Registration Number

+

{{ doctor.registration_number }}

+
+
+

Specialization

+

{{ doctor.specialization }}

+
+
+

Years of Experience

+

{{ doctor.experience_years }}

+
+
+

Created At

+

{{ doctor.created_at }}

+
+
+

Updated At

+

{{ doctor.updated_at }}

+
+
+
+
{% endblock %} diff --git a/facility/views/doctor_views.py b/facility/views/doctor_views.py index e9fbd61..d7a032f 100644 --- a/facility/views/doctor_views.py +++ b/facility/views/doctor_views.py @@ -37,14 +37,10 @@ def get_success_url(self): "facility:doctors:details", args=[ self.facility.facility_code, - self.object.patient_code, + self.object.doctor_code, ], ) - def form_valid(self, form): - form.instance.sender_facility = self.request.user.facility - return super().form_valid(form) - def form_invalid(self, form): messages.error(self.request, "Create Doctor Failed. Please check your input") return self.render_to_response(self.get_context_data(form=form)) diff --git a/patient/forms.py b/patient/forms.py index efe6342..4469ee1 100644 --- a/patient/forms.py +++ b/patient/forms.py @@ -31,15 +31,18 @@ class BasePatientForm(forms.ModelForm): height = forms.FloatField(label="Height (cm)", required=True) weight = forms.FloatField(label="Weight (kg)", required=True) - def clean_email(self): - email = str(self.cleaned_data.get("email")).strip() - if User.objects.filter(email=email).exists(): - raise forms.ValidationError("This email is already registered. Send an invite instead.") + def __init__(self, *args, **kwargs): + instance = kwargs.get("instance") + if instance: + self.base_fields["email"].required = False - return email + super().__init__(*args, **kwargs) def clean_mobile(self): mobile = str(self.cleaned_data.get("mobile")).strip() + if self.instance.pk: + return mobile + pattern = r"^((\+?63)|0|9)(9\d{9})$" if not re.match(pattern, mobile): self.add_error(field="mobile", error="Use a Philippine Mobile Number ex. (09123456789 or +639123456789)") diff --git a/patient/templates/patient/forms/patient-form.html b/patient/templates/patient/forms/patient-form.html deleted file mode 100644 index aadbc55..0000000 --- a/patient/templates/patient/forms/patient-form.html +++ /dev/null @@ -1,47 +0,0 @@ -{% if form.non_field_errors %} -
- -
-{% endif %} - -
-
- - {{ form.gender }} -
-
- - {{ form.height }} -
-
- -
-
- - {{ form.weight }} -
-
- - {{ form.blood_type }} -
-
- -
- - {{ form.mobile }} -
- -
- - {{ form.birth_date }} -
- -
- -
diff --git a/user/forms.py b/user/forms.py index 32d6606..4682996 100644 --- a/user/forms.py +++ b/user/forms.py @@ -1,4 +1,9 @@ -from allauth.account.forms import LoginForm, SignupForm +from allauth.account.forms import LoginForm +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Fieldset, Layout, Submit + +from doctor.forms import BaseDoctorForm +from patient.forms import BasePatientForm class CustomLoginForm(LoginForm): @@ -6,6 +11,41 @@ def login(self, *args, **kwargs): return super().login(*args, **kwargs) -class CustomRegisterForm(SignupForm): - def save(self, request): - return super().save(request) +class DoctorRegistrationForm(BaseDoctorForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.setup_form_layout() + + def setup_form_layout(self): + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset( + "Doctor Information", + "registration_number", + "experience_years", + "specialization", + "gender", + ), + Submit("submit", "Save Doctor Information", css_class="btn btn-primary"), + ) + + +class PatientRegistrationForm(BasePatientForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.setup_form_layout() + + def setup_form_layout(self): + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset( + "Patient Information", + "birth_date", + "blood_type", + "gender", + "height", + "weight", + css_class="mt-5", + ), + Submit("submit", "Save Patient Information", css_class="btn btn-primary"), + ) diff --git a/user/templates/account/form.html b/user/templates/account/form.html deleted file mode 100644 index 81477d7..0000000 --- a/user/templates/account/form.html +++ /dev/null @@ -1,10 +0,0 @@ -{% extends 'theme/base.html' %} - -{% block content %} -
- {% include 'account/components/header.html' %} -
- {% block main %}{% endblock main %} -
-
-{% endblock content %} diff --git a/user/templates/account/pages/auth/account-selection.html b/user/templates/account/pages/auth/account-selection.html index 2a590db..b1ce637 100644 --- a/user/templates/account/pages/auth/account-selection.html +++ b/user/templates/account/pages/auth/account-selection.html @@ -41,7 +41,7 @@

Choose an account

diff --git a/user/templates/account/pages/setup-account/doctor-registration.html b/user/templates/account/pages/setup-account/doctor-registration.html index 636a898..b1c83b1 100644 --- a/user/templates/account/pages/setup-account/doctor-registration.html +++ b/user/templates/account/pages/setup-account/doctor-registration.html @@ -15,7 +15,8 @@
{% endblock %} -{% block javascript %} -{{ block.super }} - +{% block postscripts %} + {% endblock %} diff --git a/user/templates/account/pages/setup-account/patient-registration.html b/user/templates/account/pages/setup-account/patient-registration.html index 3468b99..74b3cbe 100644 --- a/user/templates/account/pages/setup-account/patient-registration.html +++ b/user/templates/account/pages/setup-account/patient-registration.html @@ -1,59 +1,23 @@ -{% extends "account/form.html" %} +{% extends "account/index.html" %} +{% load i18n crispy_forms_tags %} {% block title %}Setup a Personal Account{% endblock %} {% block main %} -
- - -

Account selection

+
+ + Account selection -
-

Setup Patient Account

- {% csrf_token %} -
-
- - -
-
- -
- {{ form.weight }} -

kg

-
-
-
- -
- {{ form.height }} -

cm

-
-
-
- - {{ form.birth_date }} -
-
- - {{ form.gender }} -
-
- - {{ form.blood_type }} -
-
- - {{ form.mobile }} -
-
- -
+
+ {% crispy form %} +
-{% endblock main %} +{% endblock %} + -{% block javascript %} -{{ block.super }} - +{% block postscripts %} + {% endblock %} diff --git a/user/views.py b/user/views.py index 010bb8f..483a620 100644 --- a/user/views.py +++ b/user/views.py @@ -6,8 +6,7 @@ from django.utils.decorators import method_decorator from django.views.generic import TemplateView -from doctor.forms import BaseDoctorForm -from patient.forms import BasePatientForm +from user.forms import DoctorRegistrationForm, PatientRegistrationForm from facility.models import FacilityStaff @@ -28,7 +27,10 @@ class AccountSelectionView(TemplateView): template_name = "account/pages/auth/account-selection.html" def get(self, request, *args, **kwargs): - context = {"page_title": "Account Selection", "user_facilities": FacilityStaff.objects.filter(user=request.user)} + context = { + "page_title": "Account Selection", + "user_facilities": FacilityStaff.objects.filter(user=request.user), + } return render(request, self.template_name, context) @@ -37,18 +39,18 @@ class SetupPatientView(TemplateView): template_name = "account/pages/setup-account/patient-registration.html" def get(self, request, *args, **kwargs): - patient_form = BasePatientForm(instance=request.user) + patient_form = PatientRegistrationForm(instance=request.user) context = {"page_title": "Setup Patient Account", "form": patient_form} return render(request, self.template_name, context) def post(self, request, *args, **kwargs): - patient_form = BasePatientForm(request.POST, instance=request.user) + patient_form = PatientRegistrationForm(request.POST, instance=request.user) context = {"page_title": "Setup Patient Account", "form": patient_form} if patient_form.is_valid(): - user = patient_form.save() + patient = patient_form.save() messages.success(request, "Personal account has been created. Welcome to your dashboard.") - return redirect("patient:index", patient_code=user.patient.patient_code) + return redirect("patient:index", patient_code=patient.patient_code) messages.error(request, "Please fill up the form correctly.") return self._render(request, context) @@ -59,18 +61,20 @@ class SetupDoctorView(TemplateView): template_name = "account/pages/setup-account/doctor-registration.html" def get(self, request, *args, **kwargs): - doctor_form = BaseDoctorForm(request.user) + doctor_form = DoctorRegistrationForm(instance=request.user) context = {"page_title": "Setup Doctor Account", "form": doctor_form} return render(request, self.template_name, context) def post(self, request, *args, **kwargs): - doctor_form = BaseDoctorForm(request.user, request.POST) + doctor_form = DoctorRegistrationForm(request.POST, instance=request.user) context = {"page_title": "Setup Doctor Account", "form": doctor_form} if doctor_form.is_valid(): - user = doctor_form.save() + doctor = doctor_form.save() messages.success(request, "Doctor account has been created. Welcome to your dashboard.") - return redirect("doctor:index", doctor_code=user.doctor.doctor_code) + return redirect("doctor:index", doctor_code=doctor.doctor_code) + + print(doctor_form.errors) messages.error(request, "Please fill up the form correctly.") return render(request, self.template_name, context) From 14cd4904a2ba2d745aff87222901d8e1712abe08 Mon Sep 17 00:00:00 2001 From: Kyle Aquino Date: Wed, 10 Apr 2024 00:02:26 +0800 Subject: [PATCH 2/3] Update Referrals --- doctor/models.py | 3 + facility/forms/referral_forms.py | 34 +++++------- facility/models.py | 6 ++ .../pages/referrals/referral-request.html | 5 +- referrals/forms.py | 8 ++- .../migrations/0008_referral_patient_email.py | 17 ++++++ ...ral_destination_physician_name_and_more.py | 36 ++++++++++++ ...010_alter_referral_destination_and_more.py | 50 +++++++++++++++++ referrals/models.py | 9 +-- .../referrals/emails/referral-request.html | 55 +++++++++++++++---- registry/forms.py | 42 +++++++------- .../registry/pages/listing-details.html | 6 ++ registry/views.py | 2 +- theme/crispy_forms/layout.py | 31 +++++++++++ theme/templates/theme/layout/fieldset.html | 3 + 15 files changed, 245 insertions(+), 62 deletions(-) create mode 100644 referrals/migrations/0008_referral_patient_email.py create mode 100644 referrals/migrations/0009_referral_destination_physician_name_and_more.py create mode 100644 referrals/migrations/0010_alter_referral_destination_and_more.py create mode 100644 theme/crispy_forms/layout.py diff --git a/doctor/models.py b/doctor/models.py index 8bd41fe..5954431 100644 --- a/doctor/models.py +++ b/doctor/models.py @@ -21,6 +21,9 @@ def generate_doctor_code(): user = models.OneToOneField("user.user", related_name="doctor", on_delete=models.CASCADE) + def __str__(self): + return f"Doctor [{self.user.get_full_name()}]" + class Meta: ordering = ["-pk"] verbose_name = "Doctor" diff --git a/facility/forms/referral_forms.py b/facility/forms/referral_forms.py index 59d9210..361d5df 100644 --- a/facility/forms/referral_forms.py +++ b/facility/forms/referral_forms.py @@ -1,13 +1,12 @@ from autocomplete import widgets from crispy_forms.helper import FormHelper -from crispy_forms.layout import Fieldset, Layout, Div, Row, Column, Submit +from crispy_forms.layout import Layout, Div, Row, Column, Submit -from facility.models import Facility, FacilityDoctor, FacilityPatient +from theme.crispy_forms.layout import Fieldset +from facility.models import Facility from referrals.forms import BaseReferralForm -Fieldset.template = "theme/layout/fieldset.html" - -# Note: Add Environment Variable to enable/disable email sending for test environment +# TODO: Add Environment Variable to enable/disable email sending for test environment class FacilityReferralForm(BaseReferralForm): @@ -20,14 +19,20 @@ def setup_form_layout(self): self.helper = FormHelper() self.helper.layout = Layout( Fieldset( - "General Referral Details", + "Referring Health Care Institution", "origin_physician", + "description", + description="Your Facility information for the referral", + ), + Fieldset( + "Patient Information", "patient", "diagnosis", - "description", + description="The patient that will be reffered to this facility", + css_class="mt-5", ), Fieldset( - "Destination Information", + "Referral Health Care Institution", "destination", "destination_physician", Row( @@ -36,6 +41,7 @@ def setup_form_layout(self): css_class="grid grid-cols-2 gap-4", ), css_class="mt-5", + description="The receiving facility for the referral", ), Div( Submit("submit", "Send Referral Request", css_class="btn btn-primary mt-5 "), @@ -43,11 +49,9 @@ def setup_form_layout(self): ), ) - def setup_field_widgets(self): - self.fields["diagnosis"].widget.attrs["rows"] = 2 - class Meta(BaseReferralForm.Meta): add_exclude_fields = [ + "status", "is_urgent", "origin", "origin_email", @@ -62,12 +66,4 @@ class Meta(BaseReferralForm.Meta): name="destination", options={"item_label": "facility_name", "model": Facility}, ), - "patient": widgets.Autocomplete( - name="patient", - options={"model": FacilityPatient}, - ), - "origin_physician": widgets.Autocomplete( - name="origin_physician", - options={"model": FacilityDoctor}, - ), } diff --git a/facility/models.py b/facility/models.py index 721de16..2148063 100644 --- a/facility/models.py +++ b/facility/models.py @@ -84,6 +84,9 @@ class FacilityDoctor(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) + def __str__(self): + return f"Doctor [{self.doctor.user.get_full_name()}]" + class FacilityPatient(models.Model): facility = models.ForeignKey("facility.facility", on_delete=models.CASCADE) @@ -91,6 +94,9 @@ class FacilityPatient(models.Model): created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) + def __str__(self): + return f"Patient [{self.patient.user.get_full_name()}]" + class FacilityStaff(AbstractAddress, AbstractContact, AbstractGender): class StaffType(models.TextChoices): diff --git a/facility/templates/facility/pages/referrals/referral-request.html b/facility/templates/facility/pages/referrals/referral-request.html index e01fa9c..a857053 100644 --- a/facility/templates/facility/pages/referrals/referral-request.html +++ b/facility/templates/facility/pages/referrals/referral-request.html @@ -12,10 +12,7 @@

Send Referral Request

-
- {% csrf_token %} - {% crispy referral_form %} -
+ {% crispy form %}
diff --git a/referrals/forms.py b/referrals/forms.py index 6c79d37..f75703e 100644 --- a/referrals/forms.py +++ b/referrals/forms.py @@ -10,12 +10,18 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + def setup_field_widgets(self): + self.fields["diagnosis"].widget.attrs["rows"] = 2 + def save(self, commit=True): + data = self.cleaned_data instance: Referral = super().save(commit=False) - instance.send_email_request() + instance.destination = data.get("destination") or self.destination + instance.origin = data.get("origin") or self.origin if commit: instance.save() + instance.send_email_request() return instance diff --git a/referrals/migrations/0008_referral_patient_email.py b/referrals/migrations/0008_referral_patient_email.py new file mode 100644 index 0000000..ca67914 --- /dev/null +++ b/referrals/migrations/0008_referral_patient_email.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.9 on 2024-04-09 13:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("referrals", "0007_referral_origin_physician_name_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="referral", + name="patient_email", + field=models.EmailField(blank=True, max_length=100, null=True), + ), + ] diff --git a/referrals/migrations/0009_referral_destination_physician_name_and_more.py b/referrals/migrations/0009_referral_destination_physician_name_and_more.py new file mode 100644 index 0000000..e07abc7 --- /dev/null +++ b/referrals/migrations/0009_referral_destination_physician_name_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.2.9 on 2024-04-09 15:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("facility", "0001_initial"), + ("referrals", "0008_referral_patient_email"), + ] + + operations = [ + migrations.AddField( + model_name="referral", + name="destination_physician_name", + field=models.CharField( + blank=True, + max_length=55, + null=True, + verbose_name="Receiving Facility Physician Name", + ), + ), + migrations.AlterField( + model_name="referral", + name="destination_physician", + field=models.OneToOneField( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="received_referrals", + to="facility.facilitydoctor", + verbose_name="Referring Physician", + ), + ), + ] diff --git a/referrals/migrations/0010_alter_referral_destination_and_more.py b/referrals/migrations/0010_alter_referral_destination_and_more.py new file mode 100644 index 0000000..25d0882 --- /dev/null +++ b/referrals/migrations/0010_alter_referral_destination_and_more.py @@ -0,0 +1,50 @@ +# Generated by Django 4.2.9 on 2024-04-09 15:29 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("facility", "0001_initial"), + ("referrals", "0009_referral_destination_physician_name_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="referral", + name="destination", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="received_referrals", + to="facility.facility", + verbose_name="Receiving Facility", + ), + ), + migrations.AlterField( + model_name="referral", + name="destination_physician", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="received_referrals", + to="facility.facilitydoctor", + verbose_name="Referring Physician", + ), + ), + migrations.AlterField( + model_name="referral", + name="origin_physician", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="sent_referrals", + to="facility.facilitydoctor", + verbose_name="Referring Physician", + ), + ), + ] diff --git a/referrals/models.py b/referrals/models.py index 7940f2b..7fca724 100644 --- a/referrals/models.py +++ b/referrals/models.py @@ -33,6 +33,7 @@ def generate_referral_code(): patient = models.ForeignKey("facility.facilitypatient", on_delete=models.SET_NULL, null=True, blank=True) patient_name = models.CharField("Patient Full Name", max_length=55, null=True, blank=True) + patient_email = models.EmailField(max_length=100, blank=True, null=True) date_of_birth = models.DateField("Patient Date of Birth", blank=True, null=True) diagnosis = models.TextField("Patient Diagnosis", blank=True, null=True) @@ -44,7 +45,7 @@ def generate_referral_code(): blank=True, null=True, ) - origin_physician = models.OneToOneField( + origin_physician = models.ForeignKey( "facility.facilitydoctor", verbose_name="Referring Physician", related_name="sent_referrals", @@ -56,7 +57,7 @@ def generate_referral_code(): origin_mobile = models.CharField("Referring Facility Mobile", max_length=55, blank=True, null=True) origin_physician_name = models.CharField("Referring Physician Name", max_length=55, null=True, blank=True) - destination = models.OneToOneField( + destination = models.ForeignKey( "facility.facility", verbose_name="Receiving Facility", related_name="received_referrals", @@ -64,7 +65,7 @@ def generate_referral_code(): blank=True, null=True, ) - destination_physician = models.OneToOneField( + destination_physician = models.ForeignKey( "facility.facilitydoctor", verbose_name="Referring Physician", related_name="received_referrals", @@ -74,7 +75,7 @@ def generate_referral_code(): ) destination_email = models.EmailField("Receiving Facility Email", max_length=100, blank=True, null=True) destination_mobile = models.CharField("Receiving Facility Mobile", max_length=55, blank=True, null=True) - destination_physician = models.CharField("Receiving Facility Physician Name", max_length=55, null=True, blank=True) + destination_physician_name = models.CharField("Receiving Facility Physician Name", max_length=55, null=True, blank=True) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/referrals/templates/referrals/emails/referral-request.html b/referrals/templates/referrals/emails/referral-request.html index f08278d..e0e5303 100644 --- a/referrals/templates/referrals/emails/referral-request.html +++ b/referrals/templates/referrals/emails/referral-request.html @@ -1,21 +1,56 @@ {% extends 'emails/base-email.html' %} {% block content %} -

Medsync Referral Notification

+ -
-

Patient Name: {{ referral.patient_name }}

-

Date of Birth: {{ referral.date_of_birth }}

-
+

Medsync Referral Notification

+ +

Hello,

+ +

You've received a referral request from {{ referral.facility.facility_name }}:

-

Referring Doctor: {{ referral.referring_doctor }}

+

Referring Health Care Institution

+

Date and Time of the Referral: {{ referral.created_at|date:"DATETIME_FORMAT" }}

+

Name of Healthcare Institution: {{ referral.origin.facility_name }}

+

Institution Address: {{ referral.origin.address }}

+

Name of Attending/Referring Physician: + {% if referral.destination_physician %} + {{ referral.destination_physician.user.get_full_name }} + {% else %} + {{ referral.destination_physician_name }} + {% endif %} +

+
+ +
+ +
+

Patient Information

+

Patient Name: + {% if referral.patient %} + {{ referral.patient.user.get_full_name }} + {% else %} + {{ referral.patient_name }} + {% endif %} +

+

Date of Birth: {{ referral.date_of_birth }}

Diagnosis: {{ referral.diagnosis }}

+

Reasons for referral/transfer: {{ referral.description }}

-

This was sent using Medsync. We will be in touch with you to assist with the referral

+

This referral was sent using Medsync. We will be in touch with you to assist with the process.

+

If you have any questions, please don't hesitate to contact us at referrals@medsync.ph.

+ {% endblock %} diff --git a/registry/forms.py b/registry/forms.py index 813aea6..5648bc5 100644 --- a/registry/forms.py +++ b/registry/forms.py @@ -2,13 +2,12 @@ from django.urls import reverse from crispy_forms.helper import FormHelper -from crispy_forms.layout import Fieldset, Layout, Submit +from crispy_forms.layout import Layout, Submit +from theme.crispy_forms.layout import Fieldset from facility.models import Facility from referrals.forms import BaseReferralForm -Fieldset.template = "theme/layout/fieldset.html" - class RegistryReferralForm(BaseReferralForm): def __init__(self, *args, **kwargs): @@ -24,39 +23,36 @@ def setup_form_layout(self): self.helper = FormHelper() self.helper.layout = Layout( Fieldset( - "General Referral Details", - "status", + "Referring Health Care Institution", + "origin", + "origin_physician_name", + "origin_email", + "origin_mobile", "description", - "is_urgent", + description="Your facility where the referral originates", ), Fieldset( "Patient Information", - "patient", "patient_name", "date_of_birth", "diagnosis", - css_class="mt-5", - ), - Fieldset( - "Origin Information", - "origin", - "origin_email", - "origin_mobile", - "origin_physician", - css_class="mt-5", - ), - Fieldset( - "Destination Information", - "destination_email", - "destination_mobile", - "destination_physician", + description="The patient that will be reffered to this facility", css_class="mt-5", ), Submit("submit", "Send Referral Request", css_class="btn btn-primary"), ) class Meta(BaseReferralForm.Meta): - exclude = BaseReferralForm.Meta.exclude + ["destination"] + exclude = BaseReferralForm.Meta.exclude + [ + "destination", + "status", + "patient", + "origin_physician", + "destination_email", + "destination_mobile", + "destination_physician", + "is_urgent", + ] widgets = { "origin": widgets.Autocomplete( name="origin", diff --git a/registry/templates/registry/pages/listing-details.html b/registry/templates/registry/pages/listing-details.html index 9d1cc9a..baebfbf 100644 --- a/registry/templates/registry/pages/listing-details.html +++ b/registry/templates/registry/pages/listing-details.html @@ -58,3 +58,9 @@

{{ facility.facility_name }}

{% endblock %} + +{% block postscripts %} + +{% endblock %} diff --git a/registry/views.py b/registry/views.py index b2d889a..91c463b 100644 --- a/registry/views.py +++ b/registry/views.py @@ -54,7 +54,7 @@ def get_object(self, queryset=None): return get_object_or_404(Facility, facility_code=facility_code) def post(self, request, *args, **kwargs): - referral_form = RegistryReferralForm(self.get_object(), request.POST) + referral_form = RegistryReferralForm(request.POST, destination=self.get_object()) if referral_form.is_valid(): referral = referral_form.save() return redirect("referral:receipt", referral_code=referral.referral_code) diff --git a/theme/crispy_forms/layout.py b/theme/crispy_forms/layout.py new file mode 100644 index 0000000..5c54b3f --- /dev/null +++ b/theme/crispy_forms/layout.py @@ -0,0 +1,31 @@ +from crispy_forms import layout +from crispy_forms.utils import TEMPLATE_PACK +from django.template.loader import render_to_string +from django.utils.safestring import SafeString + + +class Fieldset(layout.Fieldset): + template = "theme/layout/fieldset.html" + + def __init__(self, *args, **kwargs): + self.description = kwargs.pop("description", "") + super().__init__(*args, **kwargs) + + def render(self, form, context, template_pack=TEMPLATE_PACK, **kwargs): + fields = self.get_rendered_fields(form, context, template_pack, **kwargs) + + if self.legend: + legend = layout.Template(str(self.legend)).render(context) + else: + legend = SafeString("") + + template = self.get_template_name(template_pack) + return render_to_string( + template, + { + "fieldset": self, + "legend": legend, + "description": self.description, + "fields": fields, + }, + ) diff --git a/theme/templates/theme/layout/fieldset.html b/theme/templates/theme/layout/fieldset.html index 88b07bc..657365e 100644 --- a/theme/templates/theme/layout/fieldset.html +++ b/theme/templates/theme/layout/fieldset.html @@ -2,6 +2,9 @@ {{ fieldset.flat_attrs|safe }}> {% if legend %} {{ legend|safe }} + {% if description %} + {{ description|safe }} + {%endif%}
{% endif %} {{ fields|safe }} From 0f60869c67bd41e339a8fea67adabeb4341a7335 Mon Sep 17 00:00:00 2001 From: ivanalfonso97 Date: Sun, 21 Apr 2024 22:18:31 +0800 Subject: [PATCH 3/3] create responsive facility dashboard --- .../facility/components/base/navbar.html | 16 ++++++++++++++++ .../facility/components/base/sidebar.html | 12 +++++++++++- .../facility/components/tables/doctor-table.html | 8 ++++---- .../components/tables/patient-table.html | 8 ++++---- .../components/tables/referral-table.html | 8 ++++---- facility/templates/facility/index.html | 3 ++- .../facility/pages/doctors/doctor-create.html | 6 +++--- .../facility/pages/doctors/doctor-list.html | 16 ++++++++-------- .../facility/pages/patients/patient-intake.html | 6 +++--- .../facility/pages/patients/patient-list.html | 16 ++++++++-------- .../facility/pages/referrals/referral-list.html | 16 ++++++++-------- .../pages/referrals/referral-request.html | 6 +++--- theme/static_src/src/config/themeConfig.js | 2 +- user/templates/account/index.html | 6 +++--- user/templates/account/pages/auth/login.html | 2 +- 15 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 facility/templates/facility/components/base/navbar.html diff --git a/facility/templates/facility/components/base/navbar.html b/facility/templates/facility/components/base/navbar.html new file mode 100644 index 0000000..48d5234 --- /dev/null +++ b/facility/templates/facility/components/base/navbar.html @@ -0,0 +1,16 @@ +
+ Medsync Logo +
+ +
+
+ + diff --git a/facility/templates/facility/components/base/sidebar.html b/facility/templates/facility/components/base/sidebar.html index fd77d0a..9a4285d 100644 --- a/facility/templates/facility/components/base/sidebar.html +++ b/facility/templates/facility/components/base/sidebar.html @@ -1,6 +1,9 @@ -