- Posts: 11
- Thank you received: 4
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
- Topic Author
- Offline
- New Member
Less
More
6 years 9 months ago #155737
by horseshrink
Automatically pass a token to and execute a Python script was created 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.
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.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
6 years 9 months ago #155747
by Ben_V
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)
Replied by Ben_V on topic Automatically pass a token to and execute a Python script
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:
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}&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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 4
6 years 9 months ago #155766
by horseshrink
Replied by horseshrink on topic Automatically pass a token to and execute a Python script
Will let you know how it works.
The topic has been locked.
- horseshrink
- Topic Author
- Offline
- New Member
Less
More
- Posts: 11
- Thank you received: 4
6 years 7 months ago #157128
by horseshrink
Replied by horseshrink on topic Automatically pass a token to and execute a Python script
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:
Links helpful to me for this:
"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.
- Ben_V
- Offline
- Platinum Member
Less
More
- Posts: 1223
- Thank you received: 351
6 years 7 months ago #157139
by Ben_V
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)
Replied by Ben_V on topic Automatically pass a token to and execute a Python script
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!
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13910
- Thank you received: 2548
6 years 7 months ago - 6 years 7 months ago #157237
by DenisChenu
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.
Replied by DenisChenu on topic Automatically pass a token to and execute a Python script
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)
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."&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.