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

Update PDF demo bots to use DocumentReference rather than Media #5395

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 7 additions & 5 deletions examples/medplum-demo-bots/src/create-pdf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 5,18 @@ import { handler } from './create-pdf';
const medplum = new MockClient();

test('Create PDF', async () => {
const media = await handler(medplum, {
const documentReference = await handler(medplum, {
bot: { reference: 'Bot/123' },
input: 'Hello',
contentType: 'text/plain',
secrets: {},
});
expect(media).toBeDefined();
expect(media.resourceType).toEqual('Media');
expect(media.content.contentType).toEqual('application/pdf');
expect(media.content.url).toMatch('Binary');

const contents = documentReference.content?.[0];
expect(documentReference).toBeDefined();
expect(documentReference.resourceType).toEqual('DocumentReference');
expect(contents.attachment?.contentType).toEqual('application/pdf');
expect(contents?.attachment?.url).toMatch('Binary');

// TODO: Commenting this out until MockClient.createPDF is fixed to savePDFs properly
// const binary = await medplum.readReference({ reference: media.content.url });
Expand Down
25 changes: 15 additions & 10 deletions examples/medplum-demo-bots/src/create-pdf.ts
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
import { BotEvent, MedplumClient } from '@medplum/core';
import { DocumentReference } from '@medplum/fhirtypes';

export async function handler(medplum: MedplumClient, event: BotEvent): Promise<any> {
export async function handler(medplum: MedplumClient, event: BotEvent): Promise<DocumentReference> {
console.log(event);

// Generate the PDF
Expand All @@ -14,15 15,19 @@ export async function handler(medplum: MedplumClient, event: BotEvent): Promise<
});

// Create a Media, representing an attachment
const media = await medplum.createResource({
resourceType: 'Media',
status: 'completed',
content: {
contentType: 'application/pdf',
url: 'Binary/' binary.id,
title: 'report.pdf',
},
const documentReference = await medplum.createResource({
resourceType: 'DocumentReference',
status: 'current',
content: [
{
attachment: {
contentType: 'application/pdf',
url: 'Binary/' binary.id,
title: 'report.pdf',
},
},
],
});

return media;
return documentReference;
}
Loading