Announcement

Collapse
No announcement yet.

Create a Button that copies values from one field to another record

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create a Button that copies values from one field to another record

    Hi, I'm new to this forum and I would need the help of someone who is more experienced than me in Scriptcase. My problem is as follows:

    I have a database with two tables: PATIENTS and VISITS. A patient can undergo multiple visits (each of which represents a record). There are some fields of the visit table that must be copied in the insertion of the new visit, I give an example:

    I insert the Patient in the VISITS table:
    Rossi Mario - IdPatient 1

    FIELD RECORD

    IdVisita 1
    IdPatient 1 (connected to the PATIENTS table)
    DataVisit 10/10/2018
    Height 175
    Weight 80
    Cholesterol 190
    Triglycerides 150
    Blood glucose 18

    Then I insert other patients .....
    When the patient Rossi (IdPaziente1) comes back to visit, I would need to copy (with the push of a button) some fields of the record inserted last, related to the patient Rossi

    Example of the patient Rossi Mario who comes back to visit

    FIELD RECORD

    IdVisita 5
    IdPatient 1 (connected to the PATIENTS table)
    DataVisita 09/11/2018
    Height 175(field to be copied with the data of the last insertion relative to the patient Rossi IdPaziente 1)

    Weight 80 (field to be copied with the data of the last insertion relative to the patient Rossi IdPaziente 1)

    Cholesterol 190(field to be copied with the data of the last insertion relative to the patient Rossi IdPaziente 1)

    Triglycerides 150(field to be copied with the data of the last insertion relative to the patient Rossi IdPaziente 1)

    Blood glucose 18(field to be copied with the data of the last insertion relative to the patient Rossi IdPaziente 1)
    -------------------------------------------
    The query to be applied should be this:
    ----------------
    INSERT INTO visits (Height, Weight, Cholesterol, Triglycerides, Blood Sugar) SELECT Height, Weight, Cholesterol, Triglycerides, Blood Sugar FROM visits WHERE IdPatient = 1;
    ----------------
    The action should be as follows:
    In the new entry after entering the IdPatient, DataVisita, at the "DATA COPY" button and when the key is pressed, the above query is performed, which must go to take the Patient present in the Archive with the IdPatient = a ....
    I hope I have been clear in the exhibition and thank you in advance for the help you will be able to give me.

  • #2
    use some macro's of SC

    first select the last entered values. Example below. to get last entered IDvisiita use
    ORDER BY idvisita DESC LIMIT 1 // Check for record
    $check_sql = "SELECT weight, cholesterol"
    . " FROM visita"
    . " WHERE idpatiente = '" . {idpatiente} . "'"
    . " ORDER BY idvisita DESC"
    . "LIMIT 1";
    sc_lookup(rs, $check_sql);

    if (isset({rs[0][0]})) // Row found
    {
    $weight = {rs[0][0]};
    $cholesterol = {rs[0][1]};
    }
    else // No row found
    {
    }



    Then use variables $weight, $cholesterol in the next macro

    /**
    * Insert a record on another table
    */

    // SQL statement parameters
    $insert_table = 'visits'; // Table name
    $insert_fields = array( // Field list, add as many as needed
    'weight' => "'$weight'",
    'cholesterol' => "'$cholesterol'",
    );

    // Insert record
    $insert_sql = 'INSERT INTO ' . $insert_table
    . ' (' . implode(', ', array_keys($insert_fields)) . ')'
    . ' VALUES (' . implode(', ', array_values($insert_fields)) . ')';

    sc_exec_sql($insert_sql);



    do a refresh of the form afterwards

    Hope thats helps to start to solve the prob


    Comment


    • #3
      Another way is to use the lookup settings in combination with the ajax processing. So write your query to lookup field by field of patients weight, cholesterol,.. based on idpatient and ORDER BY idvisita DESC LIMIT 1 to get latest info.

      start AJAX refresh for all fields you need to lookup

      should work too

      Comment

      Working...
      X