Skip to content

Commit

Permalink
PDF example
Browse files Browse the repository at this point in the history
  • Loading branch information
codyebberson committed Jun 9, 2022
1 parent 174558b commit 13c23ea
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
22 changes: 22 additions & 0 deletions medplum.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"bots": [
{
"name": "hello-world",
"id": "488fe72d-b5cf-4a8a-81df-908647c19e02",
"source": "src/hello-world.ts",
"dist": "dist/hello-world.js"
},
{
"name": "patient-intake",
"id": "add1bd8d-0901-46a3-87ec-222ef88abccd",
"source": "src/patient-intake.ts",
"dist": "dist/patient-intake.js"
},
{
"name": "create-pdf",
"id": "daae7b6b-3481-4a60-a4b1-31f8fbff4468",
"source": "src/create-pdf.ts",
"dist": "dist/create-pdf.js"
}
]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"author": "Medplum <[email protected]>",
"license": "Apache-2.0",
"devDependencies": {
"@medplum/cli": "0.9.6",
"@medplum/core": "0.9.6",
"@medplum/fhirtypes": "0.9.6",
"@medplum/mock": "0.9.6",
"@medplum/cli": "0.9.10",
"@medplum/core": "0.9.10",
"@medplum/fhirtypes": "0.9.10",
"@medplum/mock": "0.9.10",
"@types/node": "17.0.33",
"c8": "7.11.2",
"eslint": "8.15.0",
Expand Down
19 changes: 19 additions & 0 deletions src/create-pdf.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MockClient } from '@medplum/mock';
import { expect, test } from 'vitest';
import { handler } from './create-pdf';

const medplum = new MockClient();

test('Create PDF', async () => {
const input = 'Hello';
const contentType = 'text/plain';

const media = await handler(medplum, { input, contentType });
expect(media).toBeDefined();
expect(media.resourceType).toEqual('Media');
expect(media.content.contentType).toEqual('application/pdf');
expect(media.content.url).toMatch('Binary');

const binary = await medplum.readReference({ reference: media.content.url });
expect(binary).toBeDefined();
});
25 changes: 25 additions & 0 deletions src/create-pdf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { BotEvent, MedplumClient } from '@medplum/core';

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

// Generate the PDF
const binary = await medplum.createPdf({
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines',
],
});

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

return media;
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"outDir": "dist",
"lib": ["esnext"],
"target": "es2020",
"module": "es2020",
"target": "es2018",
"module": "commonjs",
"moduleResolution": "node",
"strict": true,
"sourceMap": true,
Expand Down

0 comments on commit 13c23ea

Please sign in to comment.