### Install and Start Medplum Source: https://www.medplum.com/docs/self-hosting/install-on-ubuntu Commands to add the Medplum repository, install the package, and start the service. ```bash curl -fsSL https://apt.medplum.com/setup.sh | sudo bash - sudo apt-get update ``` ```bash sudo apt-get install medplum ``` ```bash sudo systemctl start medplum ``` -------------------------------- ### Perform GET Requests Source: https://www.medplum.com/docs/cli Syntax and examples for retrieving resources via GET. ```bash medplum get ``` ```bash medplum get 'Patient?name=homer' ``` ```bash medplum get Patient/$id ``` -------------------------------- ### Install and Configure Nginx Source: https://www.medplum.com/docs/self-hosting/install-on-ubuntu Commands to install Nginx and Certbot, start the service, and request SSL certificates. ```bash sudo apt-get install nginx certbot python3-certbot-nginx ``` ```bash sudo systemctl start nginx sudo systemctl enable nginx ``` ```bash sudo certbot --nginx -d app.example.com sudo certbot --nginx -d api.example.com ``` -------------------------------- ### Install Node.js Source: https://www.medplum.com/docs/self-hosting/install-from-scratch Adds the Node.js repository and installs the runtime. ```bash curl -fsSL https://deb.nodesource.com/setup_24.x | sudo bash - ``` ```bash sudo apt-get install nodejs ``` -------------------------------- ### Install Node.js Source: https://www.medplum.com/docs/self-hosting/install-on-ubuntu Commands to add the Node.js v22.x repository and install the runtime. ```bash curl -fsSL https://deb.nodesource.com/setup_22.x | sudo bash - ``` ```bash sudo apt-get install nodejs ``` -------------------------------- ### Start and enable Nginx Source: https://www.medplum.com/docs/self-hosting/install-from-scratch Ensure the Nginx service is running and configured to start on boot. ```bash sudo systemctl start nginx sudo systemctl enable nginx ``` -------------------------------- ### Example $smart-launch Request and Response Source: https://www.medplum.com/docs/api/fhir/operations/clientapplication-smart-launch Demonstrates a sample GET request with a patient parameter and the resulting 302 redirect response. ```http GET /fhir/R4/ClientApplication/my-smart-app/$smart-launch?patient=patient123 ``` ```http HTTP/1.1 302 Found Location: https://my-smart-app.example.com/launch?iss=https://api.medplum.com/fhir/R4/&launch=launch456 ``` -------------------------------- ### Start PostgreSQL Service Source: https://www.medplum.com/docs/self-hosting/install-on-ubuntu Initializes and starts the PostgreSQL 16 cluster. ```bash sudo pg_ctlcluster 16 main start ``` -------------------------------- ### View Docker logs Source: https://www.medplum.com/docs/contributing/run-the-stack Example output showing successful PostgreSQL initialization. ```text postgres-1 | PostgreSQL init process complete; ready for start up. postgres-1 | postgres-1 | 2024-12-13 17:27:57.492 GMT [1] LOG: starting PostgreSQL 16.5 (Debian 16.5-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit postgres-1 | 2024-12-13 17:27:57.492 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432 postgres-1 | 2024-12-13 17:27:57.492 GMT [1] LOG: listening on IPv6 address "::", port 5432 postgres-1 | 2024-12-13 17:27:57.493 GMT [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432" postgres-1 | 2024-12-13 17:27:57.495 GMT [67] LOG: database system was shut down at 2024-12-13 17:27:57 GMT postgres-1 | 2024-12-13 17:27:57.508 GMT [1] LOG: database system is ready to accept connections ``` -------------------------------- ### Initialize a New Bot File Source: https://www.medplum.com/docs/bots/bots-in-production Copy an existing example bot file to the source directory to begin development. ```bash cd src cp examples/hello-patient.ts my-first-bot.ts ``` -------------------------------- ### Start app preview server Source: https://www.medplum.com/docs/self-hosting/install-from-scratch Run the built app using the Vite preview server in the background. ```bash cd packages/app nohup npx vite preview > app.log 2>&1 & cd ../.. ``` -------------------------------- ### Configure Client Credentials Profile Source: https://www.medplum.com/docs/cli/external-fhir-servers Example command to set up a profile using client credentials authentication. ```bash medplum profile set example \ --auth-type "client-credentials" \ --base-url "https://api.example.com" \ --fhir-url-path "fhir/R4" \ --token-url "oauth2/token" \ --client-id "MY_CLIENT_ID" \ --client-secret "MY_CLIENT_SECRET" ``` -------------------------------- ### UserInfo Request Example Source: https://www.medplum.com/docs/api/oauth/userinfo Example of a GET request to the UserInfo endpoint including the required Authorization header. ```http GET https://api.medplum.com/oauth2/userinfo Authorization: Bearer ``` -------------------------------- ### Clone and Install Bot Repository Source: https://www.medplum.com/docs/bots/bots-in-production Initializes the local environment by cloning the demo repository and installing dependencies. ```bash git clone git@github.com:medplum/medplum-demo-bots.git my-bots cd my-bots npm install ``` -------------------------------- ### Example Claim $export Requests Source: https://www.medplum.com/docs/api/fhir/operations/claim-export Concrete examples of invoking the $export operation using both GET and POST methods. ```http GET /fhir/R4/Claim/claim123/$export ``` ```http POST /fhir/R4/Claim/$export Content-Type: application/fhir+json { "resourceType": "Parameters", "parameter": [ { "name": "resource", "resource": { "resourceType": "Claim", "status": "active", "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/claim-type", "code": "professional" } ] }, "use": "claim", "patient": { "reference": "Patient/patient123" }, "provider": { "reference": "Organization/org456" }, "created": "2026-01-08", "priority": { "coding": [ { "code": "normal" } ] } } } ] } ``` -------------------------------- ### Execute $extract via HTTP GET Source: https://www.medplum.com/docs/api/fhir/operations/extract Example of invoking the operation using a standard HTTP GET request. ```http GET https://api.medplum.com/fhir/R4/QuestionnaireResponse/1c503f4e-a08c-4b7d-8ebd-bfc67b0ab761/$extract ``` -------------------------------- ### Initialize .env File Source: https://www.medplum.com/docs/bots/bots-in-production Copies the example environment file to a local .env file for persistent configuration. ```bash cp .env.example .env ``` -------------------------------- ### Execute Bot via GET Source: https://www.medplum.com/docs/api/fhir/operations/bot-execute Examples of triggering a bot execution using a GET request, where query parameters are passed to the bot. ```typescript const getResult = await medplum.get(medplum.fhirUrl('Bot', id, '$execute').toString() + '?foo=bar'); console.log(getResult); ``` ```bash medplum login medplum get 'Bot/[id]/$execute?foo=bar' ``` ```bash curl 'https://api.medplum.com/fhir/R4/Bot/[id]/$execute?foo=bar' \ -H "Authorization: Bearer $MY_ACCESS_TOKEN" ``` -------------------------------- ### Start Medplum server with configuration file Source: https://www.medplum.com/docs/self-hosting/setting-configuration Execute the server binary passing the path to your configuration file as an argument. ```bash nodepackages/server/dist/index.js medplum.config.json ``` -------------------------------- ### Lookup Request Source: https://www.medplum.com/docs/api/fhir/operations/codesystem-lookup Example of a GET request to the $lookup operation. ```http GET /CodeSystem/$lookup?system=http://loinc.org&code=invalid ``` -------------------------------- ### Upgrade Agent Examples Source: https://www.medplum.com/docs/agent/agent-cli-commands Examples showing how to upgrade agents by ID, search criteria, or specific version. ```bash # Upgrade specific agents to latest version medplum agent upgrade 123e4567-e89b-12d3-a456-426614174000 123e4567-e89b-12d3-a456-426614174001 # Upgrade using search criteria medplum agent upgrade --criteria "Agent?name=Test Agent" # Upgrade to specific version medplum agent upgrade --criteria "Agent?name=Test Agent" --version 1.2.3 ``` -------------------------------- ### Prepare and Run Server with Profiler Source: https://www.medplum.com/docs/contributing/server-profiling Commands to navigate to the server package, build the project, and execute the server with the Node.js profiler enabled. ```bash cd packages/server ``` ```bash npm run build ``` ```bash NODE_ENV=production node --prof dist/index.js ``` ```bash NODE_ENV=production node --prof dist/index.js file:medplum.docker.config.json ``` -------------------------------- ### Request $subsumes via HTTP GET Source: https://www.medplum.com/docs/api/fhir/operations/codesystem-subsumes Example request to check the relationship between two SNOMED codes using a direct GET request. ```http GET https://api.medplum.com/fhir/R4/CodeSystem/$subsumes?system=http://snomed.info/sct&codeA=364075005&codeB=363787002 ``` -------------------------------- ### Example: Cancel a Bulk Export Source: https://www.medplum.com/docs/api/fhir/operations/asyncjob-cancel Workflow demonstrating starting a bulk export and subsequently cancelling it. ```bash # Start a bulk export curl -X GET 'https://api.medplum.com/fhir/R4/$export' \ -H "Authorization: Bearer MY_ACCESS_TOKEN" \ -H "Prefer: respond-async" # Response includes Content-Location header # Content-Location: https://api.medplum.com/fhir/R4/AsyncJob/abc123 # Cancel the export if needed curl -X POST 'https://api.medplum.com/fhir/R4/AsyncJob/abc123/$cancel' \ -H "Authorization: Bearer MY_ACCESS_TOKEN" ``` -------------------------------- ### Invoke $graph Operation Source: https://www.medplum.com/docs/api/fhir/operations/resource-graph Perform a GET request to retrieve a graph of resources starting from a specific resource instance. ```http GET [base]/[ResourceType]/[id]/$graph?graph=[GraphDefinition name] ``` -------------------------------- ### Run the development server Source: https://www.medplum.com/docs/tutorials/medplum-hello-world Start the local development server to view the application at http://localhost:3000/. ```bash npm run dev ``` -------------------------------- ### SmartAppLaunch Resource Example Source: https://www.medplum.com/docs/api/fhir/operations/clientapplication-smart-launch The background resource created by the operation to store launch context. ```json { "resourceType": "SmartAppLaunch", "id": "launch456", "patient": { "reference": "Patient/patient123" } } ``` -------------------------------- ### Execute CLI Command with Custom Base URL Source: https://www.medplum.com/docs/cli Example of performing a GET request against a specific server URL. ```bash medplum get --base-url https://api.example.com 'Patient/homer-simpson' ``` -------------------------------- ### Install Dependencies and Build Application Source: https://www.medplum.com/docs/self-hosting/install-on-azure Install required development dependencies and execute the fast build command for the application. ```bash npm ci --include dev npm run build:fast ``` -------------------------------- ### Install dependencies using npm ci Source: https://www.medplum.com/docs/contributing/package-json Use npm ci for clean installations to ensure consistency with package-lock.json and improve installation speed. ```bash # ✅ Preferred installation method npm ci ``` -------------------------------- ### Production Configuration Example Source: https://www.medplum.com/docs/agent/configuration A complete configuration example for a production environment, including agent credentials and separated logger settings. ```text baseUrl=https://api.medplum.com clientId=production-client-id clientSecret=production-client-secret agentId=production-agent-id # Main logger: INFO level, moderate retention logger.main.logLevel=INFO logger.main.logDir=/var/log/medplum/main logger.main.maxFileSizeMb=10 logger.main.filesToKeep=10 # Channel logger: WARN level (only warnings and errors), extended retention logger.channel.logLevel=INFO logger.channel.logDir=/var/log/medplum/channels logger.channel.maxFileSizeMb=20 logger.channel.filesToKeep=60 ``` -------------------------------- ### Configure Log Directories Source: https://www.medplum.com/docs/agent/configuration Examples for setting log storage paths on different operating systems. ```text logger.main.logDir=/var/log/medplum-agent logger.channel.logDir=/var/log/medplum-agent/channels ``` ```text logger.main.logDir=C:\Logs\MedplumAgent logger.channel.logDir=C:\Logs\MedplumAgent\Channels ``` -------------------------------- ### Install React Router Source: https://www.medplum.com/docs/react Install React Router for client-side routing. ```bash npm i -D react-router ``` -------------------------------- ### Install dependencies Source: https://www.medplum.com/docs/contributing/run-the-stack Install all dependencies for the monorepo using npm workspaces. ```bash cd medplum npm ci ``` -------------------------------- ### Configure Basic Auth Profile Source: https://www.medplum.com/docs/cli/external-fhir-servers Example command to set up a profile using basic authentication. ```bash medplum profile set example \ --auth-type "basic" \ --base-url "https://api.example.com" \ --fhir-url-path "fhir/R4" \ --client-id "MY_CLIENT_ID" \ --client-secret "MY_CLIENT_SECRET" ``` -------------------------------- ### Install Medplum dependencies Source: https://www.medplum.com/docs/self-hosting/install-on-aws Install the Medplum CDK construct and CLI tools. ```bash npm i @medplum/cdk @medplum/cli ``` -------------------------------- ### Clone and Install Dependencies Source: https://www.medplum.com/docs/self-hosting/install-from-scratch Clones the Medplum repository and installs project dependencies. ```bash git clone https://github.com/medplum/medplum.git cd medplum ``` ```bash npm ci ``` -------------------------------- ### Push Message Command Examples Source: https://www.medplum.com/docs/agent/agent-cli-commands Examples demonstrating how to push messages using specific agent IDs, search criteria, or the no-wait flag. ```bash # Push message using specific agent medplum agent push device123 "Hello World" 123e4567-e89b-12d3-a456-426614174000 # Push message using search criteria medplum agent push device123 "Hello World" --criteria "Agent?name=Test Agent" # Push message without waiting for response medplum agent push device123 "Hello World" --criteria "Agent?name=Test Agent" --no-wait ``` -------------------------------- ### Install Redis Server Source: https://www.medplum.com/docs/self-hosting/install-from-scratch Installs the Redis server package on Ubuntu systems. ```bash sudo apt-get install redis-server ``` -------------------------------- ### Project $clone Configuration Examples Source: https://www.medplum.com/docs/api/fhir/operations/project-clone Various JSON configurations for specific cloning scenarios such as creating test environments, templates, or selecting specific resources. ```json { "name": "Production Copy - Testing", "excludeIds": ["sensitive-patient-1", "sensitive-patient-2"] } ``` ```json { "name": "New Client Project", "resourceTypes": ["Bot", "StructureDefinition", "ValueSet", "Questionnaire"] } ``` ```json { "includeIds": ["bot-1", "bot-2", "questionnaire-1"] } ``` -------------------------------- ### Upgrade Path Example Source: https://www.medplum.com/docs/self-hosting/upgrading-server Visual representation of the required sequential upgrade path between minor versions. ```text v3.1.2 → v3.3.0 → v4.0.4 → v4.1.12 → v4.2.6 → v4.3.x ``` -------------------------------- ### Install PostCSS dependencies Source: https://www.medplum.com/docs/react Install PostCSS and the Mantine preset for CSS processing. ```bash npm i -D postcss postcss-preset-mantine ``` -------------------------------- ### Install React dependencies Source: https://www.medplum.com/docs/react Install the required React and React DOM packages. ```bash npm i -D react react-dom ``` -------------------------------- ### Initialize Medplum application Source: https://www.medplum.com/docs/react Full example of setting up the Medplum client, theme, and providers in the root entry point. ```typescript import { MantineProvider, createTheme } from '@mantine/core'; import '@mantine/core/styles.css'; import { MedplumClient } from '@medplum/core'; import { MedplumProvider } from '@medplum/react'; import '@medplum/react/styles.css'; import { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; import { BrowserRouter } from 'react-router'; import { App } from './App'; const medplum = new MedplumClient({ onUnauthenticated: () => (window.location.href = '/'), }); const theme = createTheme({ headings: { sizes: { h1: { fontSize: '1.125rem', fontWeight: '500', lineHeight: '2.0', }, }, }, fontSizes: { xs: '0.6875rem', sm: '0.875rem', md: '0.875rem', lg: '1.0rem', xl: '1.125rem', }, }); const container = document.getElementById('root') as HTMLDivElement; const root = createRoot(container); root.render( ); ``` -------------------------------- ### Install esbuild Dependencies Source: https://www.medplum.com/docs/bots/bot-code-organization Install the necessary build tools via npm. ```bash npm install --save-dev esbuild glob ``` -------------------------------- ### Install Medplum CLI Source: https://www.medplum.com/docs/agent Global installation command for the Medplum CLI tool. ```bash npm install --global @medplum/cli ``` -------------------------------- ### Configure PostgreSQL Repository and Install Source: https://www.medplum.com/docs/self-hosting/install-on-ubuntu Adds the official PostgreSQL repository and installs version 16 on the system. ```bash # Configure the Apt repository sudo apt install -y postgresql-common sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh # Install Postgres 16 sudo apt install postgresql-16 postgresql-client-16 ```