Skip to content

Commit 822c6d3

Browse files
committed
VED-908: Update immunisation target parameter in Bundle.link URL.
1 parent 8d33649 commit 822c6d3

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

backend/src/service/fhir_service.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import logging
33
import os
4+
import urllib.parse
45
import uuid
56
from typing import Optional, Union, cast
67
from uuid import uuid4
@@ -241,18 +242,23 @@ def process_patient_for_bundle(patient: dict):
241242
@staticmethod
242243
def create_url_for_bundle_link(params, vaccine_types):
243244
"""
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.
246247
"""
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}"
256262

257263
def search_immunizations(
258264
self,

0 commit comments

Comments
 (0)