@@ -130,7 +130,6 @@ def create_diagnostics():
130130 exp_error = {"diagnostics" : diagnostics }
131131 return exp_error
132132
133-
134133def create_diagnostics_error (value ):
135134 if value == "Both" :
136135 diagnostics = (
@@ -150,17 +149,17 @@ def empty_bundle(self_url: str) -> Dict[str, Any]:
150149 "entry" : [],
151150 }
152151
153- def form_json (response , _element , identifier , baseurl ):
154- self_url = f"{ baseurl } ?identifier={ identifier } " + (f"&_elements={ _element } " if _element else "" )
152+ def form_json (response , _elements , identifier , baseurl ):
153+ self_url = f"{ baseurl } ?identifier={ identifier } " + (f"&_elements={ _elements } " if _elements else "" )
155154
156155 if not response :
157156 return empty_bundle (self_url )
158-
157+
159158 meta = {"versionId" : response ["version" ]} if "version" in response else {}
160159
161- # Full Immunization payload to be returned if only the identifier parameter was provided
162- if _element :
163- element = {e .strip ().lower () for e in _element .split ("," ) if e .strip ()}
160+ # Full Immunization payload to be returned if only the identifier parameter was provided and truncated when _elements is used
161+ if _elements :
162+ element = {e .strip ().lower () for e in _elements .split ("," ) if e .strip ()}
164163 resource = {"resourceType" : "Immunization" }
165164 if "id" in element : resource ["id" ] = response ["id" ]
166165 if "meta" in element and meta : resource ["meta" ] = meta
@@ -171,16 +170,18 @@ def form_json(response, _element, identifier, baseurl):
171170
172171 entry = BundleEntry (fullUrl = f"{ baseurl } /{ response ['id' ]} " ,
173172 resource = Immunization .construct (** resource ),
174- search = BundleEntrySearch .construct (mode = "match" ) if not _element else None ,
173+ search = BundleEntrySearch .construct (mode = "match" ) if not _elements else None ,
175174 )
176-
175+
177176 fhir_bundle = FhirBundle (
178177 resourceType = "Bundle" , type = "searchset" ,
179178 link = [BundleLink (relation = "self" , url = self_url )],
180- entry = [entry ], total = 1 )
181-
182- return fhir_bundle .dict (by_alias = True )
179+ entry = [entry ],
180+ total = 1 )
183181
182+ data = fhir_bundle .dict (by_alias = True )
183+ data ["total" ] = data .pop ("total" )
184+ return data
184185
185186def check_keys_in_sources (event , not_required_keys ):
186187 # Decode and parse the body, assuming it is JSON and base64-encoded
0 commit comments