Viewing 1 post (of 1 total)
  • Author
    Posts
  • #31264
    Support
    Keymaster

    This real-life example illustrates the power of the Scripting Module. A customer gave us the following specification :-

    ========================================
    We have added two CUSTOM fields on the patient editor called :-
    – “Certificate Sent” – a yes/no field called ‘cert_sent’ in the database
    – “Patient Unique Number” – a numeric field called ‘patient_unique_number’ in the database

    When the “Certificate Sent” checkbox is ticked and the record is saved, we want the Patient to be allocated a unique number starting at 15006.
    ========================================

    For the customer in question – please follow these instructions :-
    ( ❗ Please note that if you’re reading this post as a matter of interest, the script won’t work in your database unless you have added the same 2 custom patient fields as described as above.)

    [1] Click TOOLS | SCRIPT EDITOR to show the Script Editor screen
    [2] Locate “frmEditorPatient” and the “OnAfterSaveRecord” event
    [3] Copy & Paste the following script into the Script Editor :-

    frmEditorBaseRec Editor = (Params[0] as frmEditorBaseRec);
    cPer per = (Editor.Record as cPer);
    cDBBaseRec custom_patient_fields = Editor.CustomRec;

    bool cert_sent = PSLib.cDBFuncs.ToBool(custom_patient_fields.Row["cert_sent"]);
    int num = PSLib.cDBFuncs.ToInt(custom_patient_fields.Row["patient_unique_number"]);

    if (cert_sent && num == 0)
    {
    int biggest_num = cGlobals.DB.GetQuickDBIntValue("select max(patient_unique_number) from custom_patient_fields");
    biggest_num++;
    biggest_num = Math.Max(biggest_num, 15006);

    string sql = "update custom_patient_fields set patient_unique_number=" + biggest_num.ToString() +
    " where id=" + custom_patient_fields.id.ToString();
    cGlobals.DB.ExecSQL(sql);
    PSDevEx.cMessages.InformationBox("This patient has been allocated a Unique Number of: " + biggest_num.ToString());
    }

    [4] Click OK

    To test this out, go in to a patient record, tick the “Certificate Sent” box and then click SAVE AND CLOSE. A message will popup telling you what number has been assigned. If you go back in to the record you will see the unique number is in the editor.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.