@@ -301,6 +301,114 @@ def test_search_document_reference_happy_path_with_category_and_type(
301301 }
302302
303303
304+ @mock_aws
305+ @mock_repository
306+ def test_search_document_reference_happy_path_with_category_and_type_no_results (
307+ repository : DocumentPointerRepository ,
308+ ):
309+ doc_ref = load_document_reference ("Y05868-736253002-Valid" )
310+ doc_pointer = DocumentPointer .from_document_reference (doc_ref )
311+ repository .create (doc_pointer )
312+
313+ # Second pointer different category
314+ doc_ref2 = load_document_reference ("Y05868-736253002-Valid" )
315+ doc_ref2 .id = "Y05868-736253002-Valid2"
316+ doc_ref2 .type .coding [0 ].code = PointerTypes .NEWS2_CHART .coding_value ()
317+ doc_ref2 .type .coding [0 ].display = TYPE_ATTRIBUTES .get (
318+ PointerTypes .NEWS2_CHART .value
319+ ).get ("display" )
320+ doc_ref2 .category [0 ].coding [0 ].code = Categories .OBSERVATIONS .coding_value ()
321+ doc_ref2 .category [0 ].coding [0 ].display = CATEGORY_ATTRIBUTES .get (
322+ Categories .OBSERVATIONS .value
323+ ).get ("display" )
324+ repository .create (DocumentPointer .from_document_reference (doc_ref2 ))
325+
326+ event = create_test_api_gateway_event (
327+ headers = create_headers (),
328+ query_string_parameters = {
329+ "subject:identifier" : "https://fhir.nhs.uk/Id/nhs-number|6700028191" ,
330+ "category" : "http://snomed.info/sct|1102421000000108" ,
331+ "type" : "http://snomed.info/sct|736253002" ,
332+ },
333+ )
334+
335+ result = handler (event , create_mock_context ())
336+ body = result .pop ("body" )
337+
338+ assert result == {
339+ "statusCode" : "200" ,
340+ "headers" : default_response_headers (),
341+ "isBase64Encoded" : False ,
342+ }
343+ parsed_body = json .loads (body )
344+ assert parsed_body == {
345+ "resourceType" : "Bundle" ,
346+ "type" : "searchset" ,
347+ "link" : [
348+ {
349+ "relation" : "self" ,
350+ "url" : "https://pytest.api.service.nhs.uk/record-locator/consumer/FHIR/R4/DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|6700028191&type=http://snomed.info/sct|736253002&category=http://snomed.info/sct|1102421000000108" ,
351+ }
352+ ],
353+ "total" : 0 ,
354+ "entry" : [],
355+ }
356+
357+
358+ @mock_aws
359+ @mock_repository
360+ def test_search_document_reference_happy_path_with_multiple_categories_and_type (
361+ repository : DocumentPointerRepository ,
362+ ):
363+ doc_ref = load_document_reference ("Y05868-736253002-Valid" )
364+ doc_pointer = DocumentPointer .from_document_reference (doc_ref )
365+ repository .create (doc_pointer )
366+
367+ # Second pointer different category
368+ doc_ref2 = load_document_reference ("Y05868-736253002-Valid" )
369+ doc_ref2 .id = "Y05868-736253002-Valid2"
370+ doc_ref2 .type .coding [0 ].code = PointerTypes .NEWS2_CHART .coding_value ()
371+ doc_ref2 .type .coding [0 ].display = TYPE_ATTRIBUTES .get (
372+ PointerTypes .NEWS2_CHART .value
373+ ).get ("display" )
374+ doc_ref2 .category [0 ].coding [0 ].code = Categories .OBSERVATIONS .coding_value ()
375+ doc_ref2 .category [0 ].coding [0 ].display = CATEGORY_ATTRIBUTES .get (
376+ Categories .OBSERVATIONS .value
377+ ).get ("display" )
378+ repository .create (DocumentPointer .from_document_reference (doc_ref2 ))
379+
380+ event = create_test_api_gateway_event (
381+ headers = create_headers (),
382+ query_string_parameters = {
383+ "subject:identifier" : "https://fhir.nhs.uk/Id/nhs-number|6700028191" ,
384+ "category" : "http://snomed.info/sct|734163000,http://snomed.info/sct|1102421000000108" ,
385+ "type" : "http://snomed.info/sct|736253002" ,
386+ },
387+ )
388+
389+ result = handler (event , create_mock_context ())
390+ body = result .pop ("body" )
391+
392+ assert result == {
393+ "statusCode" : "200" ,
394+ "headers" : default_response_headers (),
395+ "isBase64Encoded" : False ,
396+ }
397+ parsed_body = json .loads (body )
398+ assert parsed_body == {
399+ "resourceType" : "Bundle" ,
400+ "type" : "searchset" ,
401+ "link" : [
402+ {
403+ "relation" : "self" ,
404+ "url" : "https://pytest.api.service.nhs.uk/record-locator/consumer/FHIR/R4/DocumentReference?subject:identifier=https://fhir.nhs.uk/Id/nhs-number|6700028191&type=http://snomed.info/sct|736253002&category=http://snomed.info/sct|734163000,http://snomed.info/sct|1102421000000108" ,
405+ }
406+ ],
407+ "total" : 1 ,
408+ "entry" : [{"resource" : doc_ref .model_dump (exclude_none = True )}],
409+ }
410+
411+
304412@mock_aws
305413@mock_repository
306414def test_search_document_reference_happy_path_with_multiple_categories (
0 commit comments