Skip to content

Commit 73becae

Browse files
authored
Merge pull request #2 from vintasoftware/feat/additional-backends
Additional backends
2 parents a5be815 + f166e86 commit 73becae

6 files changed

Lines changed: 52 additions & 7 deletions

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vintasend-medplum",
3-
"version": "0.7.1",
3+
"version": "0.8.1",
44
"description": "",
55
"main": "dist/index.js",
66
"scripts": {
@@ -25,7 +25,7 @@
2525
"@medplum/fhirtypes": "^5.0.10",
2626
"pdfmake": "^0.2.23",
2727
"pug": "^3.0.3",
28-
"vintasend": "^0.7.1"
28+
"vintasend": "^0.8.1"
2929
},
3030
"devDependencies": {
3131
"@medplum/definitions": "^5.0.10",

src/__tests__/medplum-adapter-attachments.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('MedplumNotificationAdapter - Attachments', () => {
2929

3030
mockTemplateRenderer = {
3131
render: jest.fn(),
32+
renderFromTemplateContent: jest.fn(),
3233
} as jest.Mocked<BaseEmailTemplateRenderer<any>>;
3334

3435
mockBackend = {

src/__tests__/medplum-adapter-one-off.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('MedplumNotificationAdapter - One-Off Notifications', () => {
3030

3131
mockTemplateRenderer = {
3232
render: jest.fn(),
33+
renderFromTemplateContent: jest.fn(),
3334
} as jest.Mocked<BaseEmailTemplateRenderer<any>>;
3435

3536
mockBackend = {

src/__tests__/medplum-adapter.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('MedplumNotificationAdapter', () => {
2727

2828
mockTemplateRenderer = {
2929
render: jest.fn(),
30+
renderFromTemplateContent: jest.fn(),
3031
} as jest.Mocked<BaseEmailTemplateRenderer<any>>;
3132

3233
mockBackend = {

src/__tests__/medplum-backend.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,33 @@ describe('MedplumNotificationBackend', () => {
122122
});
123123
});
124124

125+
it('should persist notification with predefined id when provided', async () => {
126+
const predefinedId = 'predefined-medplum-notification-id';
127+
const input = {
128+
id: predefinedId,
129+
userId: 'user-123',
130+
notificationType: 'EMAIL' as const,
131+
bodyTemplate: 'Test Body',
132+
contextName: 'testContext' as keyof TestConfig['ContextMap'],
133+
contextParameters: { param1: 'value1' },
134+
title: 'Test Title',
135+
subjectTemplate: 'Test Subject',
136+
extraParams: { key: 'value' },
137+
sendAfter: null,
138+
};
139+
140+
const createResourceSpy = jest.spyOn(medplumClient, 'createResource');
141+
const result = await backend.persistNotification(input);
142+
143+
expect(createResourceSpy).toHaveBeenCalledWith(
144+
expect.objectContaining({
145+
resourceType: 'Communication',
146+
id: predefinedId,
147+
}),
148+
);
149+
expect(result.id).toBe(predefinedId);
150+
});
151+
125152
it('should handle sendAfter date by setting sent extension', async () => {
126153
const sendAfter = new Date('2026-02-01T00:00:00Z');
127154
const input = {

src/medplum-backend.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import type { MedplumStorageIdentifiers } from './types';
3232

3333
type MedplumNotificationBackendOptions = {
3434
emailNotificationSubjectExtensionUrl?: string;
35+
identifier?: string;
3536
};
3637

3738
type StringFilterLookup = {
@@ -57,10 +58,18 @@ const IDENTIFIER_SYSTEMS = {
5758
export class MedplumNotificationBackend<Config extends BaseNotificationTypeConfig> implements BaseNotificationBackend<Config> {
5859
private attachmentManager?: BaseAttachmentManager;
5960
private logger?: BaseLogger;
61+
private identifier: string;
6062

6163
constructor(private medplum: MedplumClient, private options: MedplumNotificationBackendOptions = {
6264
emailNotificationSubjectExtensionUrl: 'http://vintasend.com/fhir/StructureDefinition/email-notification-subject',
63-
}) {}
65+
identifier: 'default-medplum',
66+
}) {
67+
this.identifier = options.identifier || 'default-medplum';
68+
}
69+
70+
getBackendIdentifier(): string {
71+
return this.identifier;
72+
}
6473

6574
/**
6675
* Inject attachment manager (called by VintaSend when both service and backend exist)
@@ -304,7 +313,9 @@ export class MedplumNotificationBackend<Config extends BaseNotificationTypeConfi
304313
.filter((n): n is DatabaseNotification<Config> => 'userId' in n);
305314
}
306315

307-
async persistNotification(notification: NotificationInput<Config>): Promise<DatabaseNotification<Config>> {
316+
async persistNotification(
317+
notification: Omit<Notification<Config>, 'id'> & { id?: Config['NotificationIdType'] },
318+
): Promise<DatabaseNotification<Config>> {
308319
const notificationWithOptionalGitCommitSha = notification as NotificationInput<Config> & {
309320
gitCommitSha?: string | null;
310321
};
@@ -344,6 +355,7 @@ export class MedplumNotificationBackend<Config extends BaseNotificationTypeConfi
344355

345356
const communication: Communication = {
346357
resourceType: 'Communication',
358+
...(notification.id ? { id: notification.id as string } : {}),
347359
status: 'in-progress',
348360
sent: notification.sendAfter?.toISOString(),
349361
topic: { text: notification.title || undefined },
@@ -705,7 +717,9 @@ export class MedplumNotificationBackend<Config extends BaseNotificationTypeConfi
705717
/* One-off notification methods */
706718

707719
async persistOneOffNotification(
708-
notification: Omit<OneOffNotificationInput<Config>, 'id'>,
720+
notification: Omit<OneOffNotificationInput<Config>, 'id'> & {
721+
id?: Config['NotificationIdType'];
722+
},
709723
): Promise<DatabaseOneOffNotification<Config>> {
710724
const notificationWithOptionalGitCommitSha = notification as Omit<
711725
OneOffNotificationInput<Config>,
@@ -749,6 +763,7 @@ export class MedplumNotificationBackend<Config extends BaseNotificationTypeConfi
749763

750764
const communication: Communication = {
751765
resourceType: 'Communication',
766+
...(notification.id ? { id: notification.id as string } : {}),
752767
status: 'in-progress',
753768
sent: notification.sendAfter?.toISOString(),
754769
topic: { text: notification.title || undefined },
@@ -1691,7 +1706,7 @@ export class MedplumNotificationBackend<Config extends BaseNotificationTypeConfi
16911706
}
16921707

16931708
export class MedplumNotificationBackendFactory<Config extends BaseNotificationTypeConfig> {
1694-
create(medplum: MedplumClient) {
1695-
return new MedplumNotificationBackend<Config>(medplum);
1709+
create(medplum: MedplumClient, options?: MedplumNotificationBackendOptions) {
1710+
return new MedplumNotificationBackend<Config>(medplum, options);
16961711
}
16971712
}

0 commit comments

Comments
 (0)