|
1 | 1 | import datetime |
2 | 2 | import logging |
3 | 3 | import os |
| 4 | +import urllib.parse |
4 | 5 | import uuid |
5 | 6 | from typing import Optional, Union, cast |
6 | 7 | from uuid import uuid4 |
@@ -241,18 +242,23 @@ def process_patient_for_bundle(patient: dict): |
241 | 242 | @staticmethod |
242 | 243 | def create_url_for_bundle_link(params, vaccine_types): |
243 | 244 | """ |
244 | | - Updates the immunization.target parameter to include the given vaccine types and returns the url for the search |
245 | | - bundle. |
| 245 | + Updates the -immunization.target parameter to include the given vaccine types |
| 246 | + and returns the url for the search bundle. |
246 | 247 | """ |
247 | | - base_url = f"{get_service_url()}/Immunization" |
248 | | - |
249 | | - # Update the immunization.target parameter |
250 | | - new_immunization_target_param = f"immunization.target={','.join(vaccine_types)}" |
251 | | - parameters = "&".join( |
252 | | - [(new_immunization_target_param if x.startswith("-immunization.target=") else x) for x in params.split("&")] |
253 | | - ) |
254 | | - |
255 | | - return f"{base_url}?{parameters}" |
| 248 | + parsed_params = urllib.parse.parse_qsl(params) |
| 249 | + |
| 250 | + updated_params = [] |
| 251 | + for k, v in parsed_params: |
| 252 | + if k == parameter_parser.immunization_target_key: |
| 253 | + updated_v = ",".join(vaccine_types) |
| 254 | + updated_params.append((k, updated_v)) |
| 255 | + # TODO - temporarily maintaining this for backwards compatibility, but we should remove it |
| 256 | + updated_params.append(("immunization.target", updated_v)) |
| 257 | + else: |
| 258 | + updated_params.append((k, v)) |
| 259 | + |
| 260 | + query = urllib.parse.urlencode(updated_params) |
| 261 | + return f"{get_service_url()}/Immunization?{query}" |
256 | 262 |
|
257 | 263 | def search_immunizations( |
258 | 264 | self, |
|
0 commit comments