Dynamic content import.

tirsoflores

New Member
I am implementing a system for a clinical analysis laboratory.

In this laboratory, it is necessary to establish panels or profiles of laboratory tests, which are intended to meet a specific diagnostic need. Some panels are made up of 2 or 3 laboratory tests (image 1) and others have more than 30. (Image 2)

In the system that I am creating, there is a table with the catalog of panels whose main form contains the fields with the alias, name, type of panel and other relevant information, but also includes in a repeated form each of the tests that are part of said panel. The repeated form, in addition to the id and parent_id fields, contains the following fields: Exam, Units, Reference Values.

Subsequently, in another table, the results of the panels requested by the patients are recorded, in whose form the identification data of the request, the patient data and the results of the examinations performed on the patients are included.

When the panel contains only 3 exams (image 3), it is easy to obtain the names, units and reference data of each exam that are registered in the catalog of panels using the Fabrik plugin "autofill" for each of the exams, row per row (this is currently the case); but if the panel contains 32 exams (image 4) as is the case with a Complete Blood Count, this method is very slow and leads to errors.

What I need is a function in javascript or php that is executed in the results form, preferably when pressing a button, and executes a query to extract from the catalog of panels, all the names, units and reference values of the specific panel that the results form is being registered and transfers them to the respective columns of the current results form (image 5), so that the user is limited to writing in the results column the values obtained in each of the exams that are part of that panel.

It would be like an autofill plugin but instead of getting and copying the values of the fields of a single record, it extracts all the values of the fields of all the records that match a reference value, in this case, the alias or id of the panel and copy them into the repeated form of the current results form.

Someone who can guide me on how to solve this.

I appreciate your comments and help in advance.
 

Attachments

  • image 1.png
    image 1.png
    281 KB · Views: 85
  • image 2.png
    image 2.png
    282.9 KB · Views: 87
  • image 3.png
    image 3.png
    337.5 KB · Views: 86
  • image 4.png
    image 4.png
    343.9 KB · Views: 85
  • imagen 5.jpg
    imagen 5.jpg
    435 KB · Views: 67
If I understand correctly in from (image 3) you create a new record where you add existing records from the laboratory test table to the patient?
You can do it with .js and ajax or with form plugins like autofill or form php. Depending on how is your database set up and what the relationships are between the tables.
How do you identify which lab test belong to particular patient? What is you work flow?

I would personally do it with .js and ajax to get data from the test table. Some hints you can find in this post https://fabrikar.com/forums/index.php?threads/automagically-delete-repeat-group-js.51780/
 
As I understand, you need to get the tests in "Panel catalog" table's repeat group rows copied to "Capture Results" table repeatable group where there's a match e.g. in Patients id or similar?

Do you have already the same amount of repeat rows ready in Capture Results form as there is in Panel catalog form? Or how do you add the repeat" Testing" rows to Capture Results form?

Like @deant said, it's a bit difficult to advise without knowing the exact workflow like:

1) doctor adds patient's data to List A and "tests to be executed" to a List A-s repeat group.
2) when patients arrives, nurse opens patient's record in List A and checks "tests to be made".
3) etc...
 
Thank you for your answers.

Background:

A laboratory test panel or profile is a set of tests that are performed to help a doctor make a diagnosis.

Some panels are made up of 3 exams, others 5, others 10, etc, and others more than 30 exams.

The laboratory offers more than 350 laboratory test panels for various diagnoses, each with its respective tests that comprise it.

The workflow is as follows:

a) In the panel catalog, the design of each laboratory test panel is configured, including each of the names of the exams, the units of measurement and the reference parameters.
For example, in image 1 the PAQ1 panel is shown, it is formed by the measurement of 3 laboratory tests: Glucose, Cholesterol and Triglycerides.

b) When a patient arrives at the laboratory, he requests a test panel that can be any of the more than 350 that the laboratory offers. This request gives rise to a work order for laboratory technicians who, after performing the tests, have to record the results. The results are recorded in the form in image 3.

The form shows the request data, the patient information and the test panel data including the Alias, the description and the method used to obtain it.
Now, the subject of the consultation for which I require your valuable help comes next.
In the repeating form you see 4 columns, containing the exam name, the result, the units and the reference values.

To fill in each row referring to each exam, the technician has to add it and then select the name of the exam.
The name of the exam is a dropdown field that uses an auto fill plugin to obtain the data of units and reference values from the panel catalog, except for the results column, which is filled in by the laboratory technician who prepares these exams.

Sometimes, the technician has to modify the reference values to adjust them to certain conditions of the patient, so the auto fill plugin copies the data into a field that can be modified, although this happens very infrequently.

When a panel only has three exams, there is not much trouble with using the auto fill plugin to fill in the columns of the exams, their units and reference values; But when the panel has 30 or 40 exams, a lot of time is wasted doing this, in addition to the fact that the laboratory technicians may omit some of the records or arrange them in the wrong order.

What I am looking for is a function, script or plugin that allows, by clicking on a button, to obtain in a single step all the exams that are part of the panel, without having to fill it row by row. including an empty column to write the results and that allows, if necessary, to modify any of the reference values.

Something like copy and paste.

As a reference, I share the structure of the fields of the main form of the test panel (image e 1-1), of the repeated form that contains the panel exams (image 1-2)
Also the structure of the fields of the first group of the main form for the capture of results (image e 2-1), and of the second group that is related to the data of the test panel (image e 2-2) and finally, the repeated form where the data of the exams are replicated and the corresponding results are filled out. (image e 2-3)



Thanks again for your help.
 

Attachments

  • image e 1-1.png
    image e 1-1.png
    295 KB · Views: 55
  • image e 1-2.png
    image e 1-2.png
    420.4 KB · Views: 53
  • image e 2-1.png
    image e 2-1.png
    386.8 KB · Views: 55
  • image e 2-2.png
    image e 2-2.png
    476.4 KB · Views: 54
  • image e 2-3.png
    image e 2-3.png
    383.1 KB · Views: 48
Last edited:
OK, now it is more clear what you need.

I would do something like this:
add db join element to panel catalog table ( id_panel, panel_name)to work order. This element is not in repeat group. It will serve to get id from panel table. So, when technician select panel e.g. PAQ1 all the items will be added to repeat group.
Ah yes. set your repeat group for panel items with dbjoin element and join to exam name table. Of course add other fields you need (result, units, reference values...).

Create form_xx.js file, create new function something like addPanelItems(), grab value of id_panel and then use user_ajax with some querry to get all exam name for selected panel from db table "panels" and "copy" items to your repeat group. It is not to hard to do it.
Question: is allways one panel or can be more then one for one pacient? If is only one test panel you can trigger your addPanelItems function onChange to db join element otherwise you will have to add a button to trigger function.

The essential part of the code is programmatically adding item in repeat groupe:

JavaScript:
var add_btn = el.form.form.getElement('#group_XX .addGroup');
                            var add_e = new Event.Mock(add_btn, 'click');
                            el.form.duplicateGroup(add_e, false);

Here is an example how to programmatically add items in repeat group, user_ajax function is missing but I thing it is not a problem.

JavaScript:
// adding ites to group 23
    if (id_itemA != '') {
        if (id_item_old == '') {
            update: document.id('tableA_22_repeat___id_item_old_' + repeat).value = id_itemA;
        }
        //  user_ajax to get related ids of itemB
        var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax";
        new Request({
            url: url,
            data: {
                method: 'get_ids_itemB',
                'ids_itemA': ids_itemA
            },
            onComplete: function(response) {
                // decode response and convert it to JS array
                json = JSON.decode(response);
                var ids_itemB = [];
                var ids_itemB = JSON.parse(response);
                //    console.log(ids_itemB.length);
                if (!Array.isArray(id_itemB) || !id_itemB.length) {
                    // console.log('No related data.');
                } else {
                    alert('We will add: ' + id_itemB.length + ' itemB');
                    // loop over array and add repeats in group 23
                    for (var i = 0; i < ids_itemB.length; i++) {
                        // check if first repeat item in group 23 have valaue.
                        var id_itemB = el.form.formElements.get('tableB_23_repeat___id_itemB_0').getValue();
                        // lets see how many items already have in group 23; c is our "repeat" counter for group 23
                        var c = $('group23').getElements('.fabrikSubGroup').length;
                        // if first item in repeat group not have value we put first id_itemB from array otherwise it will be skipped
                        if (id_itemB == '') {
                            // set values into elments
                            update: document.id('tableB_23_repeat___id_itemB_0').value = Object.values(id_itemB[i]);
                            update: document.id('tableB_23_repeat___id_itemA_chk_' + c).value = id_itemA;       // to know which itemB is related with itemA
                            update: document.id('tableA_22_repeat___id_item_old_' + repeat).value = id_itemA;   // to store id_itemA. if we change selection id_itemA we need previus value to know which id_itemB we need to delete
                        }
                        else {
                            var add_btn = el.form.form.getElement('#group23 .addGroup');
                            var add_e = new Event.Mock(add_btn, 'click');
                            el.form.duplicateGroup(add_e, false);
                            update: document.id('tableB_23_repeat___id_itemB_' + c).value = Object.values(id_itemBl[i]);
                            update: document.id('tableB_23_repeat___id_itemA_chk_' + c).value = id_itemA;       // to know which itemB is related with itemA
                            update: document.id('tableA_22_repeat___id_item_old_' + repeat).value = id_itemA;   // to store id_itemA. if we change selection id_itemA we need previus value to know which id_itemB we need to delete
                        }
                    }
                }
            }
        }).send();
        update: document.id('tableA_22_repeat___id_item_old_' + repeat).value = id_itemA;
    }
};

Also consider the possibility of deleting items in case the technician makes a mistake.
 
Last edited:
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top