+
Send Referral Request
{% include 'theme/general/components/navigation/breadcrumbs.html' %}
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 %}
-
-
- {% for error in form.non_field_errors %}
- {{ error }}
- {% endfor %}
-
-
-{% endif %}
-
-
-
- Gender
- {{ form.gender }}
-
-
- Height
- {{ form.height }}
-
-
-
-
-
- Weight
- {{ form.weight }}
-
-
- Blood Type
- {{ form.blood_type }}
-
-
-
-
- Mobile
- {{ form.mobile }}
-
-
-
- Birth Date
- {{ form.birth_date }}
-
-
-
-
- Save
-
-
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 }}