Skip to content

Commit

Permalink
added support for mode on CAR
Browse files Browse the repository at this point in the history
added support for `unicode` on CAR
  • Loading branch information
glow-mdsol committed Nov 14, 2023
1 parent af01d6f commit 8367acd
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
23 changes: 21 additions & 2 deletions rwslib/rws_requests/odm_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,44 @@
http://rws-webhelp.s3.amazonaws.com/WebHelp_ENG/solutions/clinical_data_audits/index.html#odm-adapter
"""
from typing import Optional

from . import RWSAuthorizedGetRequest, QueryOptionGetRequest


class AuditRecordsRequest(QueryOptionGetRequest):
"""Clinical Audit Records Dataset"""

KNOWN_QUERY_OPTIONS = ["studyoid", "startid", "per_page"]
KNOWN_QUERY_OPTIONS = ["studyoid", "startid", "per_page", "mode", "unicode"]
# Permissible values for mode
ALLOWABLE_MODES = ("default", "all", "enhanced")

def __init__(self, project_name, environment_name, startid=1, per_page=100):
def __init__(self, project_name: str,
environment_name: str,
startid: Optional[int] = 1,
per_page: Optional[int] = 100,
mode: Optional[str] = None,
unicode: Optional[bool] = False):
"""
:param str project_name: Project Name
:param str environment_name: Environment Name
:param int startid: Starting Audit
:param int per_page: Page Size
:param str mode: extract more Audit Subcategories (allowed values: default, all, enhanced)
:param bool unicode: specify Unicode characters are required in the response.
"""
self.project_name = project_name
self.environment_name = environment_name
self.startid = startid
self.per_page = per_page
if mode and mode not in self.ALLOWABLE_MODES:
raise ValueError("mode must be one of %s" % ", ".join(self.ALLOWABLE_MODES))
self.mode = mode
self._unicode = unicode

@property
def unicode(self) -> str:
return 'true' if self._unicode else None

@property
def studyoid(self):
Expand Down
46 changes: 46 additions & 0 deletions rwslib/tests/test_odm_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
__author__ = 'glow'

import unittest

import pytest
from six.moves.urllib_parse import quote
from rwslib.rws_requests.odm_adapter import SignatureDefinitionsRequest, UsersRequest, \
SitesMetadataRequest, VersionFoldersRequest, AuditRecordsRequest
Expand Down Expand Up @@ -117,5 +119,49 @@ def test_create_audit_records_request(self):
self.assertTrue('startid=2569' in t.url_path())
self.assertTrue('per_page=50' in t.url_path())


def test_clinical_audit_request_mode_allowed():
"""We can create an AuditRecordsRequest"""
for allowed_mode in ("default", "all", "enhanced"):
t = AuditRecordsRequest(project_name="Mediflex",
environment_name="Dev",
startid=1,
per_page=100,
mode=allowed_mode)
assert 'datasets/ClinicalAuditRecords.odm' in t.url_path()
assert f'mode={allowed_mode}' in t.url_path()


def test_clinical_audit_request_mode_not_allowed():
"""We can create an AuditRecordsRequest"""
for not_allowed_mode in ("potato", "pear", "guava"):
with pytest.raises(ValueError):
t = AuditRecordsRequest(project_name="Mediflex",
environment_name="Dev",
startid=1,
per_page=100,
mode=not_allowed_mode)


def test_clinical_audit_request_unicode():
"""We can create an AuditRecordsRequest"""
t = AuditRecordsRequest(project_name="Mediflex",
environment_name="Dev",
startid=1,
per_page=100,
unicode=True)
assert 'datasets/ClinicalAuditRecords.odm' in t.url_path()
assert f'unicode=true' in t.url_path()

def test_clinical_audit_request_unicode_default():
"""We can create an AuditRecordsRequest"""
t = AuditRecordsRequest(project_name="Mediflex",
environment_name="Dev",
startid=1,
per_page=100)
assert 'datasets/ClinicalAuditRecords.odm' in t.url_path()
assert f'unicode' not in t.url_path()


if __name__ == '__main__':
unittest.main()

0 comments on commit 8367acd

Please sign in to comment.