Skip to content

Clinical Procedure Template not loading + fix suggestion #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
johnwslongland opened this issue Mar 26, 2025 · 0 comments
Open
1 task done

Clinical Procedure Template not loading + fix suggestion #620

johnwslongland opened this issue Mar 26, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@johnwslongland
Copy link
Contributor

johnwslongland commented Mar 26, 2025

Information about bug

When creating a Clinical Procedure from Service Request, Clinical Procedure Template does not load.

Steps taken...

  1. Create Patient
  2. Create Patient Appointment
  3. From Patient Appointment, create Patient Encounter
  4. Select : Medical codes, Medication, Clinical Procedure, Therapy Type
  5. Submit Patient Encounter
  6. View Service Requests : they were created.
  7. Select Service request for CLinical Procedure.
  8. Goto > Create > Clinical Procedure
  9. Goto created Clinical Procedure and view
  10. Observation : Patient detail is fetched
  11. Observation : procedure_template field contains data but details from template is not loaded into Clinical Procedure
  12. When re-selecting procedure_template, then the template detail is loaded into the Clinical Procedure.

Desired outcome ; When Clinical Procedure is created from within Service Request, the all detail must be fetched from Clinical Procedure Template.

Fix suggestion:

Here is a snip of the code from "Service Request". first a snip of the JS where "make_clinical_procedure" is called, followed by "make_clinical_procedure" in the PY file.

It seems the template field is populated and yet the data is not fetched from the template. I suspect that this is due to the way the JS triggers work. When the template field is selected by hand, then the trigger fires correctly. When the field is populated by backend-server code, like in this case, it does not fire.

I fixed it by installing this little client script:

frappe.ui.form.on('Clinical Procedure', {
onload(frm) {
frappe.show_alert("Onload triggered");
if (frm.doc.procedure_template) {
frappe.show_alert("Triggering procedure_template fetch");
setTimeout(() => {
frm.trigger('procedure_template');
}, 500);
}
}
});

Code snip from Clinical Procedure JS and PY....

=========================================================================================
setup_create_buttons: function(frm) {
if (frm.doc.docstatus !== 1 || frm.doc.status === 'Completed') return;

            if (frm.doc.template_dt === 'Clinical Procedure Template') {

                    frm.add_custom_button(__('Clinical Procedure'), function() {
                            frappe.db.get_value("Clinical Procedure", {"service_request": frm.doc.name, "docstatus":["!=", 2]}, "name")
                            .then(r => {
                                    if (Object.keys(r.message).length == 0) {
                                            frm.trigger('make_clinical_procedure');
                                    } else {
                                            if (r.message && r.message.name) {
                                                    frappe.set_route("Form", "Clinical Procedure", r.message.name);
                                                    frappe.show_alert({
                                                            message: __(`Clinical Procedure is already created`),
                                                            indicator: "info",
                                                    });
                                            }
                                    }
                            })
                    }, __('Create'));
                    
                    
                    
def make_clinical_procedure(service_request):
    if isinstance(service_request, string_types):
            service_request = json.loads(service_request)
            service_request = frappe._dict(service_request)

    if (
            frappe.db.get_single_value("Healthcare Settings", "process_service_request_only_if_paid")
            and service_request.billing_status != "Invoiced"
    ):
            frappe.throw(
                    _("Service Request need to be invoiced before proceeding"),
                    title=_("Payment Required"),
            )

    doc = frappe.new_doc("Clinical Procedure")
    doc.procedure_template = service_request.template_dn
    doc.service_request = service_request.name
    doc.company = service_request.company
    doc.patient = service_request.patient
    doc.patient_name = service_request.patient_name
    doc.patient_sex = service_request.patient_gender
    doc.patient_age = service_request.patient_age_data
    doc.inpatient_record = service_request.inpatient_record
    doc.practitioner = service_request.practitioner
    doc.start_date = service_request.occurrence_date
    doc.start_time = service_request.occurrence_time
    doc.medical_department = service_request.medical_department

    return doc

==================================================================

Module

Outpatient Module

Version

ERPNext: v15.40.0 (version-15)

Frappe Framework: v15.46.0 (version-15)

Marley Health: v16.0.0-dev (develop)

Payments: v0.0.1 (develop)

Installation method

None

Relevant log output / Stack trace / Full Error Message.

None

Code of Conduct

  • I agree to follow this project's Code of Conduct
@johnwslongland johnwslongland added the bug Something isn't working label Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant