Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Automatically pass a token to and execute a Python script

  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 9 months ago #155737 by horseshrink
Have developed / operationalized a clinical interview and use Python / RC2 to extract the results and post-process them into a plain text format that I then copy / paste into an electronic health record. Works reasonably well. Useful.

Is there a way to automatically execute my Python post-processing script when the patient completes the survey? The patient's token number would have to be passed to the script.
The topic has been locked.
More
6 years 9 months ago #155747 by Ben_V
Hi David,

What about the built-in "endurl" function to trigger a redirection to your python script (or any intermediate php script if necessary)?

manual.limesurvey.org/URL_fields#End_URL_field

Note that you can dynamically access {SAVEDID} & {TOKEN} values in the completed message/page , so you can use several other redirect methods like AJAX calls or meta refresh redirection:
Code:
<meta http-equiv="refresh" content="0;url=http://example.org/myscript.php?savedid{SAVEDID}&amp;token={TOKEN}">

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The following user(s) said Thank You: horseshrink
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 9 months ago #155766 by horseshrink
Will let you know how it works.
The topic has been locked.
  • horseshrink
  • horseshrink's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 7 months ago #157128 by horseshrink
Am a fair novice still with website design / management (knowledge has exploded much faster over the decades than I can learn it as a clinical professional), but got the "End URL" Python script to work via CGI.

"http://localhost:8080/cgi-bin/Psychiatric%20Diagnostic%20Interview%20Print.py?urltoken={TOKEN}"

Had to read up on how to configure the Python scripts to run via CGI (URLs below.) I now know there are options other than CGI, and I don't know all the security ramifications, but this will all be run only within the walls of a LAN. No WAN use. Am just trying to make it work.

I set the following:
  • Survey properties -> Edit survey text elements and settings -> Presentation & navigation -> Automatically load URL when survey complete = "On"

Links helpful to me for this:
The following user(s) said Thank You: DenisChenu, Ben_V
The topic has been locked.
More
6 years 7 months ago #157139 by Ben_V
Hi David,

thank you for your feedback & links. I'm glad to see that you get all your system working now.

Really nice and useful LS use case!

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 7 months ago - 6 years 7 months ago #157237 by DenisChenu
Hi David,

Did you know if PHP have another way to 'knock' a python script ? PHP exec is always disable for security purpose but maybe another solution.

Else : you can call the same line directly in PHP using manual.limesurvey.org/AfterSurveyComplete and curl.

Some example of php script : framagit.org/SondagePro-LimeSurvey-plugi...enByResponse.php#L58
You just need the public function afterSurveyComplete()
and put a curl

Quickly done (not tested)
Code:
public function afterSurveyComplete() {
  $surveyId =$this->getEvent()->get('surveyId');
  $token = isset($_SESSION['survey_'.$surveyId]['token'] ? $_SESSION['survey_'.$surveyId]['token'] : null;
  if($token) {
    // There are surely another way to call a py script ???
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://localhost:8080/cgi-bin/Psychiatric%20Diagnostic%20Interview%20Print.py?surveyid=".$surveyId."&amp;urltoken=".$token);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
  }
}

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 6 years 7 months ago by DenisChenu.
The following user(s) said Thank You: Ben_V, horseshrink
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose