It’s all about using the appropriate cookie (so, request headers). I will give you a set of steps that works to access a report, I leave it to you to automatise them for your needs.
Let’s take as an example:
- Report: Visit Reports
- Start date: 2015-01-01
- End date: 2018-08-30
- Format: CSV
This guy is here:
/bahmnireports/report?name=Visit%20Report&startDate=2015-01-01&endDate=2018-08-30&responseType=text/csv&paperSize=A3&appName=reports
(The URL is already encoded.)
Step 1. - Get the cookies for your user, eg. ‘superman’:
curl -u 'superman:Admin123' -c headers \
'https://demo.mybahmni.org/openmrs/ws/rest/v1/session?v=custom:(uuid)'
The file ‘headers’ will look like this:
demo.mybahmni.org FALSE /openmrs/ FALSE 0 JSESSIONID 279D6DF291B8B56BFF2258474D24D752
Step 2. - Extract the value of JSESSIONID
. In our example it would be: 279D6DF291B8B56BFF2258474D24D752
.
Step 3. - Use this as the value for reporting_session
:
curl -b 'reporting_session=279D6DF291B8B56BFF2258474D24D752' \
'https://demo.mybahmni.org/bahmnireports/report?name=Visit%20Report&startDate=2015-01-01&endDate=2018-08-30&responseType=text/csv&paperSize=A3&appName=reports'
And this last request will print the response, so the report CSV content:
Visit Report,,,,,,,,,,,,,,,,,,,,,,
From 2015-01-01 to 2018-08-30,,,,,,,,,,,,,,,,,,,,,,
Report Generated On: 2018-08-31 05:05:51,,,,,,,,,,,,,,,,,,,,,,
Patient Identifier,Patient Name,Age,Birthdate,Gender,Patient Created Date,Visit Type,Date started,Date stopped,Date Of Admission,Date Of Discharge,New patient visit,caste,class,education,occupation,primaryContact,address1,city_village,Visit Status,Admission Status,Patient Id,Visit Id
GAN203006,Test Hyperthyroidism,35,05-May-1982,M,05-May-2017,OPD,05-May-2017,05-May-2017,,,Yes,,General,,,,,AAGDIH,OPD,,74,1
GAN203007,Test Diabetes,56,05-May-1961,M,05-May-2017,OPD,05-May-2017,18-May-2017,,,Yes,,General,,,,,AAMAGOHAN,OPD,,75,2
GAN203008,Test TB,54,05-May-1963,M,05-May-2017,OPD,05-May-2017,18-May-2017,,,Yes,,General,,,,,AARASMETA,OPD,,76,3
GAN203009,Test Hypertension,45,05-May-1972,F,05-May-2017,OPD,05-May-2017,18-May-2017,,,Yes,,General,,,,,AAMGAON,OPD,,77,4
GAN203010,Test Radiology,30,07-Jun-1987,F,07-Jun-2017,OPD,07-Jun-2017,07-Jun-2017,,,Yes,,General,,,,,,OPD,,78,5
GAN203011,Test Con,22,06-Jun-1995,M,07-Jun-2017,OPD,06-Jun-2017,06-Jun-2017,,,No,,General,,,,,,OPD,,79,6
SEM203001,MARIAM MSAFIRI,32,07-Jun-1985,M,07-Jun-2017,OPD,07-Jun-2017,07-Jun-2017,,,Yes,,General,,,,232,KIHESA,OPD,,80,7
GAN203006,Test Hyperthyroidism,35,05-May-1982,M,05-May-2017,OPD,07-Jun-2017,07-Jun-2017,,,No,,General,,,,,AAGDIH,,,74,8
GAN203007,Test Diabetes,56,05-May-1961,M,05-May-2017,OPD,07-Jun-2017,07-Jun-2017,,,No,,General,,,,,AAMAGOHAN,,,75,9
GAN203008,Test TB,54,05-May-1963,M,05-May-2017,OPD,07-Jun-2017,07-Jun-2017,,,No,,General,,,,,AARASMETA,,,76,10
GAN203009,Test Hypertension,45,05-May-1972,F,05-May-2017,OPD,07-Jun-2017,07-Jun-2017,,,No,,General,,,,,AAMGAON,,,77,11```