@@ -500,6 +500,7 @@ def test_create_document_reference_with_author(mock_service, mocker):
500500 doc_type = doc_type ,
501501 fhir_doc = fhir_doc ,
502502 current_gp_ods = "C13579" ,
503+ raw_fhir_doc = json .dumps ({"foo" : "bar" }),
503504 )
504505
505506 assert result .nhs_number == "9000000009"
@@ -539,6 +540,7 @@ def test_create_document_reference_without_custodian(mock_service, mocker):
539540 doc_type = doc_type ,
540541 fhir_doc = fhir_doc ,
541542 current_gp_ods = current_gp_ods ,
543+ raw_fhir_doc = json .dumps ({"foo" : "bar" }),
542544 )
543545
544546 assert result .custodian == current_gp_ods
@@ -825,6 +827,7 @@ def test_s3_file_key_for_pdm(mock_service, mocker):
825827 doc_type = doc_type ,
826828 fhir_doc = fhir_doc ,
827829 current_gp_ods = current_gp_ods ,
830+ raw_fhir_doc = json .dumps ({"foo" : "bar" }),
828831 )
829832
830833 assert (
@@ -864,7 +867,96 @@ def test_s3_file_key_for_lg(mock_service, mocker):
864867 doc_type = doc_type ,
865868 fhir_doc = fhir_doc ,
866869 current_gp_ods = current_gp_ods ,
870+ raw_fhir_doc = json .dumps ({"foo" : "bar" }),
867871 )
868872
869873 assert "user_upload/9000000009" in result .s3_file_key
870874 assert result .sub_folder == "user_upload"
875+
876+
877+ def test_create_pdm_document_reference_with_raw_request (mock_service , mocker ):
878+ """Test _create_document_reference method with raw_request included (pdm)."""
879+
880+ fhir_doc = mocker .MagicMock (spec = FhirDocumentReference )
881+ fhir_doc .content = [
882+ DocumentReferenceContent (
883+ attachment = Attachment (
884+ contentType = "application/pdf" ,
885+ title = "test-file.pdf" ,
886+ creation = "2023-01-01T12:00:00Z" ,
887+ )
888+ )
889+ ]
890+ fhir_doc .custodian = Reference (
891+ identifier = Identifier (
892+ system = "https://fhir.nhs.uk/Id/ods-organization-code" , value = "A12345"
893+ )
894+ )
895+ fhir_doc .author = [
896+ Reference (
897+ identifier = Identifier (
898+ system = "https://fhir.nhs.uk/Id/ods-organization-code" , value = "B67890"
899+ )
900+ )
901+ ]
902+
903+ doc_type = SnomedCodes .PATIENT_DATA .value
904+
905+ result = mock_service ._create_document_reference (
906+ nhs_number = "9000000009" ,
907+ doc_type = doc_type ,
908+ fhir_doc = fhir_doc ,
909+ current_gp_ods = "C13579" ,
910+ raw_fhir_doc = json .dumps ({"foo" : "bar" }),
911+ )
912+
913+ assert result .raw_request == json .dumps ({"foo" : "bar" })
914+ assert result .nhs_number == "9000000009"
915+ assert result .document_snomed_code_type == SnomedCodes .PATIENT_DATA .value .code
916+ assert result .custodian == "A12345"
917+ assert result .current_gp_ods == "C13579"
918+ assert result .author == "B67890" # Verify author is set
919+
920+
921+ def test_create_lg_document_reference_with_raw_request (mock_service , mocker ):
922+ """Test _create_document_reference method with raw_request included (LG, should be empty)."""
923+
924+ fhir_doc = mocker .MagicMock (spec = FhirDocumentReference )
925+ fhir_doc .content = [
926+ DocumentReferenceContent (
927+ attachment = Attachment (
928+ contentType = "application/pdf" ,
929+ title = "test-file.pdf" ,
930+ creation = "2023-01-01T12:00:00Z" ,
931+ )
932+ )
933+ ]
934+ fhir_doc .custodian = Reference (
935+ identifier = Identifier (
936+ system = "https://fhir.nhs.uk/Id/ods-organization-code" , value = "A12345"
937+ )
938+ )
939+ fhir_doc .author = [
940+ Reference (
941+ identifier = Identifier (
942+ system = "https://fhir.nhs.uk/Id/ods-organization-code" , value = "B67890"
943+ )
944+ )
945+ ]
946+
947+ doc_type = SnomedCodes .LLOYD_GEORGE .value
948+
949+ result = mock_service ._create_document_reference (
950+ nhs_number = "9000000009" ,
951+ doc_type = doc_type ,
952+ fhir_doc = fhir_doc ,
953+ current_gp_ods = "C13579" ,
954+ raw_fhir_doc = json .dumps ({"foo" : "bar" }),
955+ )
956+
957+ assert result .raw_request is None
958+ assert result .nhs_number == "9000000009"
959+ assert result .document_snomed_code_type == SnomedCodes .LLOYD_GEORGE .value .code
960+ assert result .custodian == "A12345"
961+ assert result .current_gp_ods == "C13579"
962+ assert result .author == "B67890" # Verify author is set
0 commit comments