Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print specific message if CORE row isn't found #99

Merged
merged 6 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
##
## 4) Edit the ## REPOSITORY SPECIFIC ## section below.

name: Terraform Plan
name: PR Checks
on:
pull_request:
branches: [ main ]
Expand Down Expand Up @@ -42,7 +42,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:
Expand Down
8 changes: 7 additions & 1 deletion src/api/patients/patient-details-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/errors/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions src/services/database/ehr-conversation-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down
Loading