|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "24ac830c", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "## Initialize" |
| 9 | + ] |
| 10 | + }, |
| 11 | + { |
| 12 | + "cell_type": "code", |
| 13 | + "execution_count": null, |
| 14 | + "id": "841c00cd", |
| 15 | + "metadata": { |
| 16 | + "vscode": { |
| 17 | + "languageId": "plaintext" |
| 18 | + } |
| 19 | + }, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "from rayyan import StatelessRayyan as client\n", |
| 23 | + "from rayyan.review import Review\n", |
| 24 | + "from rayyan.mylib import MyLib\n", |
| 25 | + "\n", |
| 26 | + "access_token = \"\"\n", |
| 27 | + "_client = client(access_token, url=\"https://rayyan.ai\")\n", |
| 28 | + "mylib_client = client(access_token, url=\"https://mylib.rayyan.ai\")\n", |
| 29 | + "\n", |
| 30 | + "_review = Review(_client)\n", |
| 31 | + "my_lib = MyLib(mylib_client)" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "code", |
| 36 | + "execution_count": null, |
| 37 | + "id": "d8675105", |
| 38 | + "metadata": { |
| 39 | + "vscode": { |
| 40 | + "languageId": "plaintext" |
| 41 | + } |
| 42 | + }, |
| 43 | + "outputs": [], |
| 44 | + "source": [ |
| 45 | + "# List articles in my library\n", |
| 46 | + "print(\"Listing a directory in my library\")\n", |
| 47 | + "resp = my_lib.list_directory(\"/\")\n", |
| 48 | + "print(resp)\n" |
| 49 | + ] |
| 50 | + }, |
| 51 | + { |
| 52 | + "cell_type": "code", |
| 53 | + "execution_count": null, |
| 54 | + "id": "8f18454f", |
| 55 | + "metadata": { |
| 56 | + "vscode": { |
| 57 | + "languageId": "plaintext" |
| 58 | + } |
| 59 | + }, |
| 60 | + "outputs": [], |
| 61 | + "source": [ |
| 62 | + "# Variables reused across tests\n", |
| 63 | + "review_id = 1646756\n", |
| 64 | + "stage_id = 177729 # Data Extraction\n", |
| 65 | + "sample_id = \"27989\"\n", |
| 66 | + "question_id = 20170\n", |
| 67 | + "criterion_id = 490407" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "code", |
| 72 | + "execution_count": null, |
| 73 | + "id": "e3e31a28", |
| 74 | + "metadata": { |
| 75 | + "vscode": { |
| 76 | + "languageId": "plaintext" |
| 77 | + } |
| 78 | + }, |
| 79 | + "outputs": [], |
| 80 | + "source": [ |
| 81 | + "# Import aricle from mylib\n", |
| 82 | + "file = {\n", |
| 83 | + " \"key\": \"pubmed-covid-set-22.txt\",\n", |
| 84 | + " \"size\": 40667022,\n", |
| 85 | + " \"metadata\": {\n", |
| 86 | + " \"metadata_signature\": \"dada04d571e3c2f3c3237c01a2e2de90c2b1068d83d4f95ec9eaf2e70707a81f\",\n", |
| 87 | + " \"total_articles\": \"10000\",\n", |
| 88 | + " \"type\": \"ref\"\n", |
| 89 | + " }\n", |
| 90 | + " }\n", |
| 91 | + "\n", |
| 92 | + "file = resp['items'][8]\n", |
| 93 | + "file_parsed = {\n", |
| 94 | + " \"key\": file[\"key\"],\n", |
| 95 | + " \"size\": file[\"file_size\"],\n", |
| 96 | + " \"metadata\": {\n", |
| 97 | + " \"metadata_signature\": file[\"metadata\"][\"metadata_signature\"],\n", |
| 98 | + " \"total_articles\": file[\"metadata\"][\"total_articles\"],\n", |
| 99 | + " \"type\": file[\"metadata\"][\"type\"]\n", |
| 100 | + " }\n", |
| 101 | + "}\n", |
| 102 | + "resp = _review.import_from_mylibrary_to_review(review_id=review_id, file=file_parsed)" |
| 103 | + ] |
| 104 | + }, |
| 105 | + { |
| 106 | + "cell_type": "code", |
| 107 | + "execution_count": null, |
| 108 | + "id": "cb0c1556", |
| 109 | + "metadata": { |
| 110 | + "vscode": { |
| 111 | + "languageId": "plaintext" |
| 112 | + } |
| 113 | + }, |
| 114 | + "outputs": [], |
| 115 | + "source": [ |
| 116 | + "# Full text\n", |
| 117 | + "print(\"Listing articles with full text\")\n", |
| 118 | + "resp = _review.list_articles_with_fulltext(review_id=review_id)\n", |
| 119 | + "print(resp)\n", |
| 120 | + "\n", |
| 121 | + "full_text_id = resp['data'][0]['fulltexts'][0]['id']\n", |
| 122 | + "resp = _review.get_fulltext_link(full_text_id)\n", |
| 123 | + "print(resp['url'])" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "markdown", |
| 128 | + "id": "c01a34b4", |
| 129 | + "metadata": {}, |
| 130 | + "source": [ |
| 131 | + "## Testing Questions, Criteria, MyLibrary Import and AI Screener endpoints" |
| 132 | + ] |
| 133 | + }, |
| 134 | + { |
| 135 | + "cell_type": "code", |
| 136 | + "execution_count": null, |
| 137 | + "id": "70fe0b60", |
| 138 | + "metadata": { |
| 139 | + "vscode": { |
| 140 | + "languageId": "plaintext" |
| 141 | + } |
| 142 | + }, |
| 143 | + "outputs": [], |
| 144 | + "source": [ |
| 145 | + "# --- Samples ---\n", |
| 146 | + "print(\"Creating sample...\")\n", |
| 147 | + "resp = _review.create_sample(\n", |
| 148 | + " review_id=review_id,\n", |
| 149 | + " samples=[{\"name\": \"created_by_python_sdk\", \"total\": 10}]\n", |
| 150 | + ")\n", |
| 151 | + "print(resp)\n", |
| 152 | + "\n", |
| 153 | + "print(\"Listing samples...\")\n", |
| 154 | + "resp = _review.list_samples(review_id=review_id)\n", |
| 155 | + "print(resp)\n", |
| 156 | + "\n", |
| 157 | + "resp = _review.list_stages(review_id=review_id)\n", |
| 158 | + "print(resp)\n", |
| 159 | + "\n", |
| 160 | + "print(\"Updating sample...\")\n", |
| 161 | + "resp = _review.update_sample(\n", |
| 162 | + " review_id=review_id,\n", |
| 163 | + " sample_id=sample_id,\n", |
| 164 | + " sample={\"name\": \"Name Changed by python sdk\"}\n", |
| 165 | + ")\n", |
| 166 | + "print(resp)\n", |
| 167 | + "\n", |
| 168 | + "print(\"Deleting sample...\")\n", |
| 169 | + "resp = _review.delete_sample(\n", |
| 170 | + " review_id=review_id,\n", |
| 171 | + " sample_id=sample_id\n", |
| 172 | + ")\n", |
| 173 | + "print(resp)\n", |
| 174 | + "\n" |
| 175 | + ] |
| 176 | + }, |
| 177 | + { |
| 178 | + "cell_type": "markdown", |
| 179 | + "id": "b039c4ad", |
| 180 | + "metadata": {}, |
| 181 | + "source": [ |
| 182 | + "# --- Questions ---\n", |
| 183 | + "print(\"Creating question...\")\n", |
| 184 | + "resp = _review.create_question(\n", |
| 185 | + " review_id=review_id,\n", |
| 186 | + " stage_id=stage_id,\n", |
| 187 | + " question={\n", |
| 188 | + " \"type\": \"string\",\n", |
| 189 | + " \"title\": \"Added via Python SDK\",\n", |
| 190 | + " \"section_name\": \"Methods\",\n", |
| 191 | + " \"required\": True,\n", |
| 192 | + " \"body\": \"Describe your inclusion criteria\"\n", |
| 193 | + " }\n", |
| 194 | + ")\n", |
| 195 | + "print(resp)\n", |
| 196 | + "\n", |
| 197 | + "print(\"Listing questions...\")\n", |
| 198 | + "resp = _review.list_questions(review_id=review_id, stage_id=stage_id)\n", |
| 199 | + "print(resp)\n", |
| 200 | + "\n", |
| 201 | + "print(\"Getting a specific question...\")\n", |
| 202 | + "resp = _review.get_question(review_id=review_id, stage_id=stage_id, question_id=question_id)\n", |
| 203 | + "print(resp)\n", |
| 204 | + "\n", |
| 205 | + "print(\"Updating question...\")\n", |
| 206 | + "resp = _review.update_question(\n", |
| 207 | + " review_id=review_id,\n", |
| 208 | + " stage_id=stage_id,\n", |
| 209 | + " question_id=question_id,\n", |
| 210 | + " question={\n", |
| 211 | + " \"type\": \"string\",\n", |
| 212 | + " \"title\": \"Updated Title by SDK\",\n", |
| 213 | + " \"section_name\": \"Results\",\n", |
| 214 | + " \"required\": False,\n", |
| 215 | + " \"body\": \"Updated body content\"\n", |
| 216 | + " }\n", |
| 217 | + ")\n", |
| 218 | + "print(resp)\n", |
| 219 | + "\n", |
| 220 | + "print(\"Deleting question...\")\n", |
| 221 | + "resp = _review.delete_question(review_id=review_id, stage_id=stage_id, question_id=question_id)\n", |
| 222 | + "print(resp)\n" |
| 223 | + ] |
| 224 | + }, |
| 225 | + { |
| 226 | + "cell_type": "code", |
| 227 | + "execution_count": null, |
| 228 | + "id": "3e6407b4", |
| 229 | + "metadata": { |
| 230 | + "vscode": { |
| 231 | + "languageId": "plaintext" |
| 232 | + } |
| 233 | + }, |
| 234 | + "outputs": [], |
| 235 | + "source": [ |
| 236 | + "\n", |
| 237 | + "# --- Criteria ---\n", |
| 238 | + "print(\"Creating criterion...\")\n", |
| 239 | + "resp = _review.create_criterion(\n", |
| 240 | + " review_id=review_id,\n", |
| 241 | + " criterion={\"kind\": \"inclusion\", \"text\": \"Must include RCTs\"}\n", |
| 242 | + ")\n", |
| 243 | + "print(resp)\n", |
| 244 | + "\n", |
| 245 | + "print(\"Listing criteria...\")\n", |
| 246 | + "resp = _review.list_criteria(review_id=review_id)\n", |
| 247 | + "print(resp)\n", |
| 248 | + "\n", |
| 249 | + "print(\"Updating criterion...\")\n", |
| 250 | + "resp = _review.update_criterion(\n", |
| 251 | + " review_id=review_id,\n", |
| 252 | + " criterion_id=criterion_id,\n", |
| 253 | + " criterion={\"kind\": \"exclusion\", \"text\": \"Exclude case reports\"}\n", |
| 254 | + ")\n", |
| 255 | + "print(resp)\n", |
| 256 | + "\n", |
| 257 | + "print(\"Deleting criterion...\")\n", |
| 258 | + "resp = _review.delete_criterion(review_id=review_id, criterion_id=criterion_id)\n", |
| 259 | + "print(resp)\n" |
| 260 | + ] |
| 261 | + }, |
| 262 | + { |
| 263 | + "cell_type": "code", |
| 264 | + "execution_count": null, |
| 265 | + "id": "8ef8a2c5", |
| 266 | + "metadata": { |
| 267 | + "vscode": { |
| 268 | + "languageId": "plaintext" |
| 269 | + } |
| 270 | + }, |
| 271 | + "outputs": [], |
| 272 | + "source": [ |
| 273 | + "# --- MyLibrary Import ---\n", |
| 274 | + "print(\"Importing file to library...\")\n", |
| 275 | + "resp = _review.import_to_library(\n", |
| 276 | + " review_id=review_id,\n", |
| 277 | + " file={\n", |
| 278 | + " \"key\": \"/mnt/c/Users/amamd/Downloads/pubmed-covid-set-19.txt\",\n", |
| 279 | + " \"size\": 717,\n", |
| 280 | + " \"metadata\": {\n", |
| 281 | + " \"metadata_signature\": \"bea0cb4574d0a131bd0***\",\n", |
| 282 | + " \"total_articles\": \"3\",\n", |
| 283 | + " \"type\": \"ref\"\n", |
| 284 | + " }\n", |
| 285 | + " }\n", |
| 286 | + ")\n", |
| 287 | + "print(resp)\n" |
| 288 | + ] |
| 289 | + }, |
| 290 | + { |
| 291 | + "cell_type": "code", |
| 292 | + "execution_count": null, |
| 293 | + "id": "3d21fa3b", |
| 294 | + "metadata": { |
| 295 | + "vscode": { |
| 296 | + "languageId": "plaintext" |
| 297 | + } |
| 298 | + }, |
| 299 | + "outputs": [], |
| 300 | + "source": [ |
| 301 | + "# --- AI Screener ---\n", |
| 302 | + "print(\"Creating AI screener...\")\n", |
| 303 | + "resp = _review.create_ai_screener(\n", |
| 304 | + " review_id=review_id,\n", |
| 305 | + " extra={\n", |
| 306 | + " }\n", |
| 307 | + ")\n", |
| 308 | + "print(resp)" |
| 309 | + ] |
| 310 | + } |
| 311 | + ], |
| 312 | + "metadata": { |
| 313 | + "kernelspec": { |
| 314 | + "display_name": ".venv", |
| 315 | + "language": "python", |
| 316 | + "name": "python3" |
| 317 | + }, |
| 318 | + "language_info": { |
| 319 | + "name": "python", |
| 320 | + "version": "3.12.3" |
| 321 | + } |
| 322 | + }, |
| 323 | + "nbformat": 4, |
| 324 | + "nbformat_minor": 5 |
| 325 | +} |
0 commit comments