@@ -140,29 +140,29 @@ def create_diagnostics_error(value):
140140 exp_error = {"diagnostics" : diagnostics }
141141 return exp_error
142142
143- def empty_bundle (self_url : str ) -> Dict [str , Any ]:
143+ def make_empty_bundle (self_url : str ) -> Dict [str , Any ]:
144144 return {
145145 "resourceType" : "Bundle" ,
146146 "type" : "searchset" ,
147147 "link" : [{"relation" : "self" , "url" : self_url }],
148- "total" : 0 ,
149148 "entry" : [],
149+ "total" : 0 ,
150150 }
151151
152152def form_json (response , _elements , identifier , baseurl ):
153153 self_url = f"{ baseurl } ?identifier={ identifier } " + (f"&_elements={ _elements } " if _elements else "" )
154154
155155 if not response :
156- return empty_bundle (self_url )
156+ return make_empty_bundle (self_url )
157157
158158 meta = {"versionId" : response ["version" ]} if "version" in response else {}
159159
160160 # Full Immunization payload to be returned if only the identifier parameter was provided and truncated when _elements is used
161161 if _elements :
162- element = {e .strip ().lower () for e in _elements .split ("," ) if e .strip ()}
162+ elements = {e .strip ().lower () for e in _elements .split ("," ) if e .strip ()}
163163 resource = {"resourceType" : "Immunization" }
164- if "id" in element : resource ["id" ] = response ["id" ]
165- if "meta" in element and meta : resource ["meta" ] = meta
164+ if "id" in elements : resource ["id" ] = response ["id" ]
165+ if "meta" in elements and meta : resource ["meta" ] = meta
166166
167167 else :
168168 resource = response ["resource" ]
@@ -179,7 +179,7 @@ def form_json(response, _elements, identifier, baseurl):
179179 entry = [entry ],
180180 total = 1 )
181181
182-
182+ # Reassigned total to ensure it appears last in the response to match expected output
183183 data = json .loads (fhir_bundle .json (by_alias = True ))
184184 data ["total" ] = data .pop ("total" )
185185 return data
0 commit comments