diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 682e7229..8ee36f40 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,21 +1,30 @@ ## When copying this to a new ORC repository... ## -## 1) Create environments for dev, test, pre-prod and prod (https://github.com/nhsconnect//settings/environments). +## 1) Visit https://github.com/nhsconnect//settings/environments and create environments: +## - dev +## - test +## - test-apply +## - pre-prod +## - pre-prod-apply +## - prod +## - prod-apply ## ## 2) For each environment, add the following secrets: -## - BACKEND_BUCKET -## - BACKEND_KEY -## - IAM_ROLE_READONLY +## - IAM_ROLE +## - TF_BACKEND_BUCKET +## - TF_BACKEND_DYNAMODB_TABLE +## - TF_BACKEND_KEY ## ## 3) Create the following repository secret (https://github.com/nhsconnect//settings/secrets/actions): ## - ECR_REPOSITORY_NAME ## ## 4) Edit the ## REPOSITORY SPECIFIC ## section below. -name: Terraform Plan +name: PR Checks on: pull_request: - branches: [ main ] + branches: + - main permissions: contents: read # Required for actions/checkout @@ -42,7 +51,7 @@ jobs: strategy: matrix: environment: [dev, test, pre-prod, prod] - name: ${{ matrix.environment }} + name: Terraform Plan (${{ matrix.environment }}) runs-on: ubuntu-latest environment: ${{ matrix.environment }} defaults: @@ -58,7 +67,7 @@ jobs: - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: - role-to-assume: ${{ secrets.IAM_ROLE_READONLY }} + role-to-assume: ${{ secrets.IAM_ROLE }} aws-region: eu-west-2 - name: terraform fmt diff --git a/src/api/patients/patient-details-controller.js b/src/api/patients/patient-details-controller.js index 4faa2637..6571e352 100644 --- a/src/api/patients/patient-details-controller.js +++ b/src/api/patients/patient-details-controller.js @@ -6,7 +6,7 @@ import { getCurrentConversationIdForPatient, getMessageIdsForConversation } from '../../services/database/ehr-conversation-repository'; -import { HealthRecordNotFoundError } from '../../errors/errors'; +import { HealthRecordNotFoundError, CoreNotFoundError } from '../../errors/errors'; export const patientDetailsValidation = [ param('nhsNumber') @@ -52,6 +52,12 @@ export const patientDetailsController = async (req, res) => { return; } + if (err instanceof CoreNotFoundError) { + logInfo('Did not find a core message'); + res.sendStatus(503); + return; + } + logError('Could not retrieve patient health record', err); res.sendStatus(503); } diff --git a/src/errors/errors.js b/src/errors/errors.js index d2248b56..5b0ff569 100644 --- a/src/errors/errors.js +++ b/src/errors/errors.js @@ -12,7 +12,7 @@ export class HealthRecordNotFoundError extends Error { } } -export class MessageNotFoundError extends Error { +export class CoreNotFoundError extends Error { constructor(error) { super(errorMessages.MessageNotFound); logError(errorMessages.MessageNotFound, error); diff --git a/src/services/database/__tests__/ehr-conversation-repository.integration.test.js b/src/services/database/__tests__/ehr-conversation-repository.integration.test.js index cfecadf7..1e5124a3 100644 --- a/src/services/database/__tests__/ehr-conversation-repository.integration.test.js +++ b/src/services/database/__tests__/ehr-conversation-repository.integration.test.js @@ -17,7 +17,7 @@ import { import { createCore } from '../ehr-core-repository'; import { EhrTransferTracker } from '../dynamo-ehr-transfer-tracker'; import { markFragmentAsReceivedAndCreateItsParts } from '../ehr-fragment-repository'; -import { HealthRecordNotFoundError, MessageNotFoundError } from '../../../errors/errors'; +import { HealthRecordNotFoundError, CoreNotFoundError } from '../../../errors/errors'; import moment from 'moment-timezone'; jest.mock('../../../middleware/logging'); @@ -247,7 +247,7 @@ describe('ehr-conversation-repository', () => { // when await expect(() => getMessageIdsForConversation(conversationId)) // then - .rejects.toThrowError(MessageNotFoundError); + .rejects.toThrowError(CoreNotFoundError); }); it('should return health record extract message id given a conversation id for a small health record', async () => { diff --git a/src/services/database/ehr-conversation-repository.js b/src/services/database/ehr-conversation-repository.js index fee9b2f6..08ebd17d 100644 --- a/src/services/database/ehr-conversation-repository.js +++ b/src/services/database/ehr-conversation-repository.js @@ -2,7 +2,7 @@ import { ConversationStatus, HealthRecordStatus, RecordType } from '../../models import { logError, logInfo } from '../../middleware/logging'; import { EhrTransferTracker } from './dynamo-ehr-transfer-tracker'; import { buildConversationUpdateParams, isInCompleteStatus } from '../../models/conversation'; -import { HealthRecordNotFoundError, MessageNotFoundError } from '../../errors/errors'; +import { HealthRecordNotFoundError, CoreNotFoundError } from '../../errors/errors'; import { isCore } from '../../models/core'; import { isFragment } from '../../models/fragment'; import { buildSoftDeleteUpdateParams } from '../../utilities/dynamodb-helper'; @@ -125,7 +125,7 @@ export const getMessageIdsForConversation = async (conversationId) => { const fragments = items.filter(isFragment); if (!core) { - throw new MessageNotFoundError(); + throw new CoreNotFoundError(); } const coreMessageId = core.InboundMessageId; const fragmentMessageIds = fragments.map((message) => message.InboundMessageId);