Skip to content

Commit

Permalink
prmp-1287 add fhir response
Browse files Browse the repository at this point in the history
  • Loading branch information
NogaNHS committed Dec 10, 2024
1 parent 71164b9 commit 7935104
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lambdas/models/nrl_fhir_document_reference.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional

from enums.snomed_codes import SnomedCodesCategory, SnomedCodesType
from fhir.resources.R4B.documentreference import DocumentReference
from models.nrl_sqs_message import NrlAttachment
from pydantic import BaseModel, ConfigDict
Expand All @@ -10,8 +11,8 @@ class FhirDocumentReference(BaseModel):
model_config = ConfigDict(alias_generator=to_camel)
nhs_number: str
custodian: str
snomed_code_doc_type: str = "None"
snomed_code_category: str = "None"
snomed_code_doc_type: str = SnomedCodesType.LLOYD_GEORGE
snomed_code_category: str = SnomedCodesCategory.CARE_PLAN
snomed_code_category_display: str = "Care plan"
attachment: Optional[NrlAttachment] = NrlAttachment()

Expand Down Expand Up @@ -59,6 +60,7 @@ def build_fhir_dict(self):
}
}
],
"authenticator": {"identifier": {"value": self.custodian}},
"content": [
{
"attachment": self.attachment.model_dump(
Expand Down
4 changes: 4 additions & 0 deletions lambdas/models/nrl_sqs_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@


class NrlAttachment(BaseModel):
model_config = ConfigDict(
alias_generator=AliasGenerator(serialization_alias=to_camel)
)

content_type: str = "application/pdf"
language: str = "en-UK"
url: str = ""
Expand Down
21 changes: 21 additions & 0 deletions lambdas/services/nrl_get_document_reference_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import requests
from enums.patient_ods_inactive_status import PatientOdsInactiveStatus
from fhir.resources.R4B.documentreference import (
DocumentReference as R4FhirDocumentReference,
)
from models.document_reference import DocumentReference
from models.nrl_fhir_document_reference import FhirDocumentReference
from models.nrl_sqs_message import NrlAttachment
from services.base.s3_service import S3Service
from services.base.ssm_service import SSMService
from services.document_service import DocumentService
Expand Down Expand Up @@ -39,6 +44,22 @@ def handle_get_document_reference_request(self, document_id, bearer_token):
presign_url = self.create_document_presigned_url(document_reference)
return presign_url

def create_document_reference_fhir_response(
self, document_reference: DocumentReference, presign_url: str
) -> R4FhirDocumentReference:
document_details = NrlAttachment(
url=presign_url,
title=document_reference.file_name,
creation=document_reference.created,
)
fhir_document_reference: R4FhirDocumentReference = FhirDocumentReference(
nhsNumber=document_reference.nhs_number,
custodian=document_reference.current_gp_ods,
attachment=document_details,
).build_fhir_dict()
# fhir_document_reference.authenticator.(document_reference.current_gp_ods)
return fhir_document_reference

def is_user_allowed_to_see_file(self, user_details, document_reference):
user_ods_codes_and_roles = self.get_user_roles_and_ods_codes(user_details)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from services.nrl_get_document_reference_service import NRLGetDocumentReferenceService
from tests.unit.conftest import TEST_CURRENT_GP_ODS, TEST_UUID
from tests.unit.conftest import FAKE_URL, TEST_CURRENT_GP_ODS, TEST_UUID
from tests.unit.helpers.data.test_documents import create_test_doc_store_refs

MOCK_USER_INFO = {
Expand Down Expand Up @@ -42,8 +42,11 @@

@pytest.fixture
def patched_service(mocker, set_env, context):
mocker.patch("services.base.s3_service.IAMService")

service = NRLGetDocumentReferenceService()
mocker.patch.object(service, "ssm_service")
mocker.patch.object(service, "s3_service")
mocker.patch.object(service, "pds_service")
mocker.patch.object(service, "document_service")
mocker.patch.object(service, "get_ndr_accepted_role_codes")
Expand Down Expand Up @@ -106,3 +109,10 @@ def test_user_allowed_to_see_file_happy_path(patched_service, mock_fetch_user_in
)
is True
)


def test_create_document_reference_fhir_response(patched_service):
response = patched_service.create_document_reference_fhir_response(
create_test_doc_store_refs()[0], FAKE_URL
)
print(response.json())

0 comments on commit 7935104

Please sign in to comment.