mdsol / rwslib

Provide a (programmer) friendly client library to Rave Web Services (RWS).
MIT License
31 stars 13 forks source link

How to get startid from AuditRecordsRequest response #121

Closed vagarwal77 closed 2 years ago

vagarwal77 commented 3 years ago

https://rwslib.readthedocs.io/en/latest/odm_adapter.html#auditrecordsrequest-project-name-environment-name

audits = r.send_request(AuditRecordsRequest('MEDIFLEX','DEV'))

I don't see a way to get startid which can be used with subsequent AuditRecordsRequest calls. Please suggest how to get startid value which is (startid=1 | The audit ID to start on. Defaults to 1. The first Audit ID)

Sample response of audits -

2020-09-24T16:19:49 6781448 2020-09-24T16:19:49 6781449
isparks commented 3 years ago

This is actually in the example but could be pointed out better maybe. You're looking for the "Link" in the last_request.headers:

>>> audits = r.send_request(AuditRecordsRequest('MEDIFLEX','DEV'))
>>> r.last_request.headers["Link]
https://innovate.mdsol.com/RaveWebServices/datasets/ClinicalAuditRecords.odm?studyoid=MEDIFLEX%28DEV%29&startid=3842&per_page=1000>; rel="next"'

The startid is in that response (3842). You have to parse it yourself to get that value. There is some code in audit event which you could steal for this:

from urllib.parse import urlparse, parse_qs
result = rws.send_request(AuditRecordsRequest('TG_TEST','Dev'))

link = rws.last_result.links.get("next", None)
if link:
    link = link['url']
    p = urlparse(link)
    start_id = int(parse_qs(p.query)['startid'][0])
    print(start_id)
glow-mdsol commented 2 years ago

This seems ok to close