@@ -136,30 +136,25 @@ def create_diagnostics_error(value):
136136
137137
138138def form_json (response , _element , identifier , baseurl ):
139- self_url = f"{ baseurl } ?identifier={ identifier } "
140- if _element :
141- self_url += f"&_elements={ _element } "
142-
143- if not response :
144- json = {
139+ self_url = f"{ baseurl } ?identifier={ identifier } " + (f"&_elements={ _element } " if _element else "" )
140+ json = {
145141 "resourceType" : "Bundle" ,
146142 "type" : "searchset" ,
147143 "link" : [
148- {"relation" : "self" , "url" : f"{ baseurl } ?identifier={ identifier } " }
149- ],
150- "entry" : [],
151- "total" : 0 ,
152- }
144+ {"relation" : "self" , "url" : self_url }
145+ ]
146+ }
147+ if not response :
148+ json ["entry" ] = []
149+ json ["total" ] = 0
153150 return json
154151
155152 # Full Immunization payload to be returned if only the identifier parameter was provided
156153 if identifier and not _element :
157154 resource = response ["resource" ]
158155
159156 elif identifier and _element :
160- __elements = _element .lower ()
161- element = __elements .split ("," )
162-
157+ element = {e .strip ().lower () for e in _element .split ("," ) if e .strip ()}
163158 resource = {"resourceType" : "Immunization" }
164159
165160 # Add 'id' if specified
@@ -171,19 +166,13 @@ def form_json(response, _element, identifier, baseurl):
171166 resource ["id" ] = response ["id" ]
172167 resource ["meta" ] = {"versionId" : response ["version" ]}
173168
174- json = {
175- "resourceType" : "Bundle" ,
176- "type" : "searchset" ,
177- "link" : [{"relation" : "self" , "url" : f"{ baseurl } ?identifier={ identifier } &_elements={ _element } " }],
178- "entry" : [
179- {
180- "fullUrl" : f"https://api.service.nhs.uk/immunisation-fhir-api/Immunization/{ response ['id' ]} " ,
181- "resource" : resource ,
169+
170+ json ["entry" ] = [{
171+ "fullUrl" : f"https://api.service.nhs.uk/immunisation-fhir-api/Immunization/{ response ['id' ]} " ,
172+ "resource" : resource ,
182173 }
183- ],
184- "total" : 1 ,
185- }
186-
174+ ]
175+ json ["total" ] = 1
187176 return json
188177
189178
0 commit comments