diff --git a/healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.html b/healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.html new file mode 100644 index 0000000000..63a9f5af4e --- /dev/null +++ b/healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.html @@ -0,0 +1,411 @@ + + + +{% set dob = frappe.db.get_value("Patient", doc.patient, "dob") %} +{% set years = 0 %} +{% set months = 0 %} +{% set days = 0 %} +{% if dob %} + {% set now = frappe.utils.nowdate() %} + {% if doc.ref_doctype=="Sales Invoice" and doc.docname %} + {% set now = frappe.db.get_value("Sales Invoice", doc.docname, "posting_date") %} + {% endif %} + {% set diff = frappe.utils.date_diff(now, dob) %} + {% set years = diff//365 %} + {% set months = (diff - (years * 365))//30 %} + {% set days = ( (diff - (years * 365)) - (months * 30) ) %} +{% endif %} + +{% set sex = frappe.db.get_value("Patient", doc.patient, "sex") %} + +{% set salutation = "Ms" %} + +{%- if years <= 1 -%} + {% set salutation = "Baby" %} +{% elif sex == "Male" and years <= 13%} + {% set salutation = "Master" %} +{% elif sex == "Female" and years <= 18 %} + {% set salutation = "Miss" %} +{% elif sex == "Male" %} + {% set salutation = "Mr" %} +{% endif %} +

DEPARTMENT OF LABORATORY MEDICINE

+
+
+
+
Patient name:
+
{{ salutation }} {{ doc.patient_name.upper() }}
+
+
+
Patient:
+
{{ doc.patient }}
+
+
+
Age/Gender:
+
{{ years }}Y {{ months }}M {{ days }}D / {{ sex }}
+
+
+
+
+
Referred By:
+ {%- if doc.practitioner_name -%} +
{{ doc.practitioner_name.upper() }}
+ {% else %} +
Self
+ {% endif %} +
+
+
Invoice No.:
+
{{ doc.docname }}
+
+
+
Invoiced On:
+
{{ frappe.utils.format_date(now) }}
+
+ +
+
+
+
+
+ + SAMPLE + +
+
+ Collected on +
+
+
+
+ + INVESTIGATION + +
+
+ Method +
+
+
+
+ + RESULT + +
+
+ Reported on +
+
+
+
+ + UNIT + +
+
+
+
+ + REFERENCE INTERVAL + +
+
+
+ +{% if doc.get("docname") %} + {% if doc.get("docname") %} + {% set full_data = diagnostic_report_print(doc.name) %} +
+ {% for data in full_data[0] %} + {% if not data.get("has_component") %} + {% if data.get("observation").get("preferred_display_name") %} + {% set observation_name = data.get("observation").get("preferred_display_name") %} + {% else %} + {% set observation_name = data.get("observation").get("observation_template") %} + {% endif %} + + {% if data.get("observation") or data.get("observation") %} + {% if data.get("observation").get("status")=="Approved" and (data.get("observation").get("result_data") or data.get("observation").get("result_text") or data.get("observation").get("result_select") not in [None, "", "Null"]) %} +
+
+ + {{observation_name}} + +
+
+
+
+ {% if data.get("observation").get("sample") %} +
+ {{data.get("observation").get("sample")}} +
+ {% else %} +
+ {{ frappe.db.get_value("Observation Template", data.get("observation").get("observation_template"), "sample") or "" }} +
+ {% endif %} + {% if data.get("observation").get("received_time") %} +
+ {{frappe.utils.format_datetime(data.get("observation").get("received_time"))[:-3]}} +
+ {% endif %} +
+
+
+ {{observation_name}} +
+ {% if data.get("observation").get("method") %} +
+ {{data.get("observation").get("method")}} +
+ {% endif %} +
+
+
+ {% if data.get("observation").get("result_data") or data.get("observation").get("result_select") %} + {{data.get("observation").get("result_data") + or data.get("observation").get("result_select")}} + {% elif data.get("observation").get("result_text") %} + {% if '
' in data.get("observation").get("result_text") %} + {% if data.get("observation").get("result_text")|length <= 60 %} + {{data.get("observation").get("result_text")}} + {% endif %} + {% elif data.get("observation").get("result_text")|length <= 24 %} + {{data.get("observation").get("result_text")}} + {% endif %} + {% endif %} +
+ {% if data.get("observation").get("time_of_result") %} +
+ {{frappe.utils.format_datetime(data.get("observation").get("time_of_result"))[:-3]}} +
+ {% endif %} +
+
+ {% if data.get("observation").get("permitted_unit") %} + {{data.get("observation").get("permitted_unit")}} + {% endif %} +
+
+ {% if data.get("observation").get("reference") %} + {{data.get("observation").get("reference")}} + {% endif %} +
+
+ {% if data.get("observation").get("result_text") %} + {% if '
' in data.get("observation").get("result_text") %} + {% if data.get("observation").get("result_text")|length > 60 %} +
+ {{data.get("observation").get("result_text")}} +
+ {% endif %} + {% elif data.get("observation").get("result_text")|length > 24 %} +
+ {{data.get("observation").get("result_text")}} +
+ {% endif %} + {% endif %} + {% if data.get("observation").get("result_interpretation") %} +
+ {{data.get("observation").get("result_interpretation")}} +
+ {% endif %} + {% if data.get("observation").get("note") %} +
+ {{data.get("observation").get("note")}} +
+ {% endif %} + {% if data.get("observation").get("description") %} +
+ {{data.get("observation").get("description")}} +
+ {% endif %} +
+ + {% endif %} + {% endif %} + {% else %} + {% if data["obs_approved"] and data[data.get("observation")] and data["has_result"] %} +
+
+
+
+
+ + {{data.get("display_name")}} + +
+ {% for comps in data[data.get("observation")] %} + {% if comps.get("observation").get("preferred_display_name") %} + {% set observation_name = comps.get("observation").get("preferred_display_name") %} + {% else %} + {% set observation_name = comps.get("observation").get("observation_template") %} + {% endif %} + {% if comps.get("observation").get("status")=="Approved" and comps.get("observation") %} + {% if comps.get("observation").get("result_data") or comps.get("observation").get("result_text") or comps.get("observation").get("result_select") not in [None, "", "Null"] %} +
+
+
+
+ {% if comps.get("observation").get("sample") %} +
+ {{comps.get("observation").get("sample")}} +
+ {% else %} +
+ {{ frappe.db.get_value("Observation Template", comps.get("observation").get("observation_template"), "sample") or ""}} +
+ {% endif %} + {% if comps.get("observation").get("received_time") %} +
+ {{frappe.utils.format_datetime(comps.get("observation").get("received_time"))[:-3]}} +
+ {% endif %} +
+
+
+ {{observation_name}} +
+ {% if comps.get("observation").get("method") %} +
+ {{comps.get("observation").get("method")}} +
+ {% endif %} +
+
+
+ {% if comps.get("observation").get("result_data") or comps.get("observation").get("result_select") %} + {{comps.get("observation").get("result_data") + or comps.get("observation").get("result_select")}} + {% elif comps.get("observation").get("result_text") %} + {% if '
' in comps.get("observation").get("result_text") %} + {% if comps.get("observation").get("result_text")|length <= 60 %} + {{comps.get("observation").get("result_text")}} + {% endif %} + {% elif comps.get("observation").get("result_text")|length <= 24 %} + {{comps.get("observation").get("result_text")}} + {% endif %} + {% endif %} +
+ {% if comps.get("observation").get("time_of_result") %} +
+ {{frappe.utils.format_datetime(comps.get("observation").get("time_of_result"))[:-3]}} +
+ {% endif %} +
+
+ {% if comps.get("observation").get("permitted_unit") %} + {{comps.get("observation").get("permitted_unit")}} + {% endif %} +
+
+ {% if comps.get("observation").get("reference") %} + {{comps.get("observation").get("reference")}} + {% endif %} +
+
+ {% if comps.get("observation").get("result_text") %} + {% if '
' in comps.get("observation").get("result_text") %} + {% if comps.get("observation").get("result_text")|length > 60 %} +
+ {{comps.get("observation").get("result_text")}} +
+ {% endif %} + {% elif comps.get("observation").get("result_text")|length > 24 %} +
+ {{comps.get("observation").get("result_text")}} +
+ {% endif %} + {% endif %} + {% if comps.get("observation").get("result_interpretation") %} +
+ {{comps.get("observation").get("result_interpretation")}} +
+ {% endif %} + {% if comps.get("observation").get("note") %} +
+ {{comps.get("observation").get("note")}} +
+ {% endif %} + {% if comps.get("observation").get("description") and not data.get("description") %} +
+ {{comps.get("observation").get("description")}} +
+ {% endif %} +
+
+ {% endif %} + {% endif %} + {% endfor %} +
+ {{data.get("description") or ""}} +
+
+
+ + + {% endif %} + {% endif %} + {% endfor %} + {% if full_data[0]|length > 0 %} +
* End of Report *
+ {% endif %} + + {% endif %} +{% endif %} \ No newline at end of file diff --git a/healthcare/healthcare/doctype/patient_history_settings/patient_history_settings.py b/healthcare/healthcare/doctype/patient_history_settings/patient_history_settings.py index 61b5fd9f6b..79ee6b41aa 100644 --- a/healthcare/healthcare/doctype/patient_history_settings/patient_history_settings.py +++ b/healthcare/healthcare/doctype/patient_history_settings/patient_history_settings.py @@ -11,7 +11,6 @@ from frappe.utils import cint, cstr from frappe.utils.formatters import format_value -from healthcare.healthcare.doctype.observation.observation import get_observation_details from healthcare.healthcare.page.patient_history.patient_history import get_patient_history_doctypes @@ -143,7 +142,10 @@ def set_subject_field(doc, reference=None): patient_history_fields = get_patient_history_fields(doc) if doc.doctype == "Observation": if doc.reference_docname or doc.sales_invoice: - subject = get_observation_subject_and_ref(patient_history_fields, reference, meta) + doc = frappe.get_doc("Diagnostic Report", reference) + subject = frappe.render_template( + "healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.html", dict(doc=doc) + ) else: return else: @@ -233,74 +235,3 @@ def get_module(doc): module = frappe.db.get_value("DocType", doc.doctype, "module") return module - - -def get_observation_subject_and_ref(patient_history_fields, reference, meta): - if not reference: - return - - obs_data = get_observation_details(reference) - - subject = "" - for entry in obs_data[0]: - parent_obs = entry.get("observation") - - if entry.get("has_component"): - formatted_value = get_formatted_value_for_observations( - entry.get(parent_obs), patient_history_fields, meta - ) - subject += f"Observation: {parent_obs}
{cstr(formatted_value)}
" - else: - formatted_value = get_formatted_value_for_observations([entry], patient_history_fields, meta) - subject += f"Observation: {parent_obs.get('name')}
{cstr(formatted_value)}
" - - return subject - - -def get_formatted_value_for_observations(items, patient_history_fields, meta): - result_fields = [ - "result_boolean", - "result_data", - "result_text", - "result_float", - "result_select", - ] - table_head = "" - table_row = "" - html = "" - create_head = True - for item in items: - obs_details = item.get("observation") - table_row += "" - for key in patient_history_fields: - label, fieldname = key.get("label"), key.get("fieldname") - if create_head: - table_head += f"{label} " - if obs_details.get(fieldname): - if key.get("fieldtype") == "Datetime": - formatted_value = format_value(obs_details.get(fieldname), meta.get_field(fieldname)) - table_row += f"{str(formatted_value)}" - else: - table_row += f"{str(obs_details.get(fieldname))}" - else: - table_row += "" - - result = None - for field in result_fields: - if obs_details.get(field): - result = obs_details.get(field) - break - if create_head: - table_head += "Result" - if result: - table_row += f"{str(result)}" - - create_head = False - table_row += "" - - html += f""" - - {table_head} {table_row} -
""" - - return html diff --git a/healthcare/patches.txt b/healthcare/patches.txt index 6a21502838..a90e136498 100644 --- a/healthcare/patches.txt +++ b/healthcare/patches.txt @@ -9,6 +9,7 @@ healthcare.patches.v15_0.rename_medical_code_standard_and_medical_code healthcare.patches.v15_0.setup_service_request healthcare.patches.v15_0.create_custom_field_in_payment_entry healthcare.patches.v15_0.add_observation_to_patient_history +healthcare.patches.v15_0.create_patient_medical_records_for_observations [post_model_sync] healthcare.patches.v15_0.rename_field_medical_department_in_appoitment_type_service_item diff --git a/healthcare/patches/v15_0/create_patient_medical_records_for_observations.py b/healthcare/patches/v15_0/create_patient_medical_records_for_observations.py new file mode 100644 index 0000000000..e5691d40c0 --- /dev/null +++ b/healthcare/patches/v15_0/create_patient_medical_records_for_observations.py @@ -0,0 +1,21 @@ +import frappe + + +def execute(): + diagnostic_report = frappe.db.get_all("Diagnostic Report", pluck="name") + + for diag in diagnostic_report: + diag_doc = frappe.get_doc("Diagnostic Report", diag) + + subject = frappe.render_template( + "healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.html", dict(doc=diag_doc) + ) + medical_record = frappe.new_doc("Patient Medical Record") + medical_record.patient = diag_doc.patient + medical_record.subject = subject + medical_record.status = "Open" + medical_record.communication_date = diag_doc.reference_posting_date + medical_record.reference_doctype = "Diagnostic Report" + medical_record.reference_name = diag_doc.name + medical_record.reference_owner = diag_doc.owner + medical_record.save(ignore_permissions=True)