=============== LIBRARY RULES =============== From library maintainers: - Start on the sandbox: use an sk_test_ key and the 30 synthetic patients; never put real patient data in the sandbox and never use sk_live_ keys in examples. - Never invent LOINC, SNOMED CT, ICD-10, ICD-11, ATC or RxNorm codes. Look them up with the terminology endpoints (/v1/search, /v1/search/{id}) or take them from the official code system; if a code is unknown, leave it out. - A person's data is read or written only with their consent: request it through the consent flow (SMART on FHIR scopes) and respect its scope and expiry; when the API answers 403, ask for consent instead of working around it. - Store clinical data as standard FHIR R4 resources (Patient, Observation, Condition, MedicationStatement, AllergyIntolerance, Immunization, DiagnosticReport) with UCUM units, not as custom JSON. - Anpheros does not diagnose or recommend treatment; generated apps must not present diagnoses or medication advice to users. - Documentation and guides: https://developers.anpheros.com/guides/ ; documentation MCP server (no account): https://platform.anpheros.com/mcp/docs ### Install dependencies and run quickstart Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/quickstart-dart/README.md Install the required packages and execute the quickstart script with your Anpheros API key. ```bash dart pub get ANPHEROS_KEY=sk_test_… dart run bin/quickstart.dart ``` -------------------------------- ### Install and run the quickstart script Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/quickstart-ts/README.md Install the necessary dependencies and execute the script using a sandbox API key. The script will reject any key that is not a sandbox key. ```bash npm install ANPHEROS_KEY=sk_test_… npm start ``` -------------------------------- ### Install and run the backend service Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/backend-ts/README.md Commands to install dependencies, start the server with an API key, and test the available API endpoints. ```bash npm install ANPHEROS_KEY=sk_test_… npm start curl localhost:3000/api/patients curl localhost:3000/api/patients//summary curl -X POST -d '{"kg":72.5}' localhost:3000/api/patients//weight ``` -------------------------------- ### Run the application Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/consent-app-ts/README.md Install dependencies and start the application by providing your Anpheros client ID as an environment variable. ```bash npm install ANPHEROS_CLIENT_ID=client_… npm start ``` -------------------------------- ### Install dependencies and run with Ollama or hosted provider Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/ai-context-llm/README.md Install npm dependencies, then run the script with environment variables. For a local Ollama model, set ANPHEROS_KEY, PATIENT_ID, LLM_BASE_URL, and LLM_MODEL. For a hosted provider, also set LLM_API_KEY. The script prints the context's manifest_id. ```bash npm install # a local model served by Ollama ANPHEROS_KEY=sk_test_… PATIENT_ID=… LLM_BASE_URL=http://localhost:11434/v1 LLM_MODEL= \ npm start -- "How has my blood pressure changed?" # a hosted provider: set LLM_BASE_URL, LLM_MODEL and LLM_API_KEY ``` -------------------------------- ### Example HL7 import output Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/lab-integration-ts/README.md Sample console output showing the results of an HL7 import, including created and skipped records, LOINC mapping, and unmapped lab codes. ```text Imported HL7: created 6, skipped 0 Cholesterol [Mass/volume] in Serum or Plasma = 212 mg/dL → http://loinc.org|2093-3 … Example in-house marker = 3.2 U/L → urn:anpheros:lab-code|EX-991 Not mapped to LOINC (kept with the lab's own code): Example in-house marker … Sent again: created 0, skipped 6 ``` -------------------------------- ### Run lab integration scripts Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/lab-integration-ts/README.md Commands to install dependencies and execute the lab integration script using either HL7 v2 or CSV input formats. ```bash npm install ANPHEROS_KEY=sk_test_… npm start # HL7 v2 ANPHEROS_KEY=sk_test_… npm run csv # CSV ``` -------------------------------- ### GET /api/patients Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/backend-ts/README.md Retrieves the project's patients. In the sandbox, this returns your 30 synthetic patients and any you created. ```APIDOC ## GET /api/patients ### Description Retrieves the project's patients. In the sandbox, this returns your 30 synthetic patients and any you created. ### Method GET ### Endpoint /api/patients ### Response #### Success Response (200) - **patients** (array) - List of patient objects. #### Response Example { "patients": [] } ### Error Handling - **502** - Anpheros unreachable or server key invalid/revoked. - **403** - No access: consent missing, expired or revoked, or a read-only key. - **404** - Not in this project. - **422** - A reference that does not exist for you. - **503** - Rate limit exceeded. ``` -------------------------------- ### OAuth flow with PKCE for patient-authorized apps Source: https://github.com/anpheros/anpheros-sdk/blob/main/dart/anpheros_sdk/README.md Use this snippet for apps acting on behalf of a person. It generates a PKCE challenge, builds an authorization URL with requested scopes, exchanges the authorization code for tokens, and creates an Anpheros client with OAuth authentication including token refresh. The example then lists medications for the authorized patient. ```dart final flow = OAuthFlow(baseUrl: 'https://…', clientId: 'client_…', redirectUri: 'myapp://callback'); final pkce = Pkce.generate(); final url = flow.authorizeUrl(scopes: ['patient/Observation.rs?category=laboratory', 'patient/MedicationStatement.r', 'offline_access'], state: 'abc', pkce: pkce, lang: 'ro'); // open `url`; on return with ?code=…: final tokens = await flow.exchange(code: code, pkce: pkce); final anpheros = Anpheros(auth: AnpherosAuth.oauth( accessToken: tokens.accessToken, refreshToken: tokens.refreshToken, expiresAt: tokens.expiresAt, onRefresh: flow.refresh, onTokens: persist)); final meds = await anpheros.medications.listMedications(tokens.patient!); ``` -------------------------------- ### GET /api/patients/:id/fhir Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/backend-ts/README.md Retrieves the same record as FHIR R4 (Patient/$everything, first page of 100 entries). ```APIDOC ## GET /api/patients/:id/fhir ### Description Retrieves the same record as FHIR R4 (Patient/$everything, first page of 100 entries). ### Method GET ### Endpoint /api/patients/:id/fhir ### Parameters #### Path Parameters - **id** (string) - Required - The patient identifier. ### Response #### Success Response (200) - **resourceType** (string) - The FHIR resource type (Bundle). - **entry** (array) - List of FHIR resources. #### Response Example { "resourceType": "Bundle", "entry": [] } ### Error Handling - **502** - Anpheros unreachable or server key invalid/revoked. - **403** - No access: consent missing, expired or revoked, or a read-only key. - **404** - Not in this project. - **422** - A reference that does not exist for you. - **503** - Rate limit exceeded. ``` -------------------------------- ### GET /api/patients/:id/summary Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/backend-ts/README.md Retrieves the latest vital signs and lab results per code, active conditions, and active medications for a specific patient. ```APIDOC ## GET /api/patients/:id/summary ### Description Retrieves the latest vital signs and lab results per code, active conditions, and active medications for a specific patient. ### Method GET ### Endpoint /api/patients/:id/summary ### Parameters #### Path Parameters - **id** (string) - Required - The patient identifier. ### Response #### Success Response (200) - **vitalSigns** (object) - Latest vital signs per code. - **labResults** (object) - Latest lab results per code. - **activeConditions** (array) - Active conditions. - **activeMedications** (array) - Active medications. #### Response Example { "vitalSigns": {}, "labResults": {}, "activeConditions": [], "activeMedications": [] } ### Error Handling - **502** - Anpheros unreachable or server key invalid/revoked. - **403** - No access: consent missing, expired or revoked, or a read-only key. - **404** - Not in this project. - **422** - A reference that does not exist for you. - **503** - Rate limit exceeded. ``` -------------------------------- ### Initialize Anpheros SDK with API Key Source: https://github.com/anpheros/anpheros-sdk/blob/main/ts/README.md Demonstrates how to initialize the Anpheros client using an API key, list patients, retrieve laboratory observations, and build an AI context. ```ts import { Anpheros, apiKey } from '@anpheros/sdk'; const anpheros = new Anpheros({ auth: apiKey(process.env.ANPHEROS_KEY!) }); const { data: patients } = await anpheros.patients.list(); const labs = await anpheros.observations.list(patients[0].id, { category: 'laboratory', limit: 10 }); const ctx = await anpheros.context.build({ patient: patients[0].id, task: 'weekly check-in', budget_tokens: 1500, format: 'text' }); ``` -------------------------------- ### Initialize Anpheros with API key and list patients, observations, and build AI context Source: https://github.com/anpheros/anpheros-sdk/blob/main/dart/anpheros_sdk/README.md Use this snippet for server or sandbox environments where an API key is sufficient. It creates an Anpheros client, lists patients, retrieves laboratory observations for the first patient, and builds an AI context with a token budget. ```dart import 'package:anpheros_sdk/anpheros_sdk.dart'; final anpheros = Anpheros(auth: AnpherosAuth.apiKey('sk_test_…')); // server / sandbox final patients = await anpheros.patients.list(); final elena = patients.data.first; final labs = await anpheros.observations.list(elena.id, category: 'laboratory', limit: 10); final ctx = await anpheros.context.build(ContextRequest(patient: elena.id, task: 'weekly check-in', budgetTokens: 1500)); ``` -------------------------------- ### Connect with TypeScript SDK Source: https://github.com/anpheros/anpheros-sdk/blob/main/README.md Initializes the Anpheros client with an API key from the environment, lists patients, retrieves laboratory observations for the first patient, and builds a context for a weekly check-in task. Use in server-side environments where the API key is safe. ```TypeScript import { Anpheros, apiKey } from '@anpheros/sdk'; const anpheros = new Anpheros({ auth: apiKey(process.env.ANPHEROS_KEY!) }); // sk_test_… in the sandbox const { data: patients } = await anpheros.patients.list(); const labs = await anpheros.observations.list(patients[0].id, { category: 'laboratory', limit: 10 }); const ctx = await anpheros.context.build({ patient: patients[0].id, task: 'weekly check-in', budget_tokens: 1500, format: 'text' }); ``` -------------------------------- ### Perform OAuth 2.1 Authorization Flow Source: https://github.com/anpheros/anpheros-sdk/blob/main/ts/README.md Shows the process of initiating an OAuth flow with PKCE, generating an authorization URL, and exchanging the authorization code for tokens to authenticate the Anpheros client. ```ts import { OAuthFlow, OAuthAuth, generatePkce } from '@anpheros/sdk'; const flow = new OAuthFlow({ baseUrl: BASE, clientId: 'client_…', redirectUri: 'https://myapp.example/callback' }); const pkce = await generatePkce(); location.href = flow.authorizeUrl({ scopes: ['patient/Observation.rs?category=laboratory', 'offline_access'], state, pkce, lang: 'ro' }); // on the callback: const tokens = await flow.exchange(code, pkce); const anpheros = new Anpheros({ auth: new OAuthAuth({ tokens, onRefresh: flow.refresh, onTokens: persist }) }); ``` -------------------------------- ### Retrieve patient records and summaries Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/fhir-transaction/README.md Fetches the full patient record using the $everything operation or an International Patient Summary using the $summary operation. ```bash # the whole record curl "https://platform.anpheros.com/fhir/R4/Patient/$PID/$everything" -H "Authorization: Bearer $ANPHEROS_KEY" # an International Patient Summary document curl "https://platform.anpheros.com/fhir/R4/Patient/$PID/$summary?lang=en" -H "Authorization: Bearer $ANPHEROS_KEY" ``` -------------------------------- ### Connect with Dart SDK Source: https://github.com/anpheros/anpheros-sdk/blob/main/README.md Initializes the Anpheros client with an API key, lists patients, and retrieves laboratory observations for the first patient. Use in server-side Dart applications. ```Dart import 'package:anpheros_sdk/anpheros_sdk.dart'; final anpheros = Anpheros(auth: AnpherosAuth.apiKey('sk_test_…')); final patients = await anpheros.patients.list(); final labs = await anpheros.observations.list(patients.data.first.id, category: 'laboratory', limit: 10); ``` -------------------------------- ### POST /api/patients/:id/weight Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/backend-ts/README.md Creates a body-weight Observation (LOINC 29463-7) for a patient. The input is validated before being sent. ```APIDOC ## POST /api/patients/:id/weight ### Description Creates a body-weight Observation (LOINC 29463-7) for a patient. The input is validated before being sent. ### Method POST ### Endpoint /api/patients/:id/weight ### Parameters #### Path Parameters - **id** (string) - Required - The patient identifier. #### Request Body - **kg** (number) - Required - The weight in kilograms. ### Request Example { "kg": 72.5 } ### Response #### Success Response (200) - **observation** (object) - The created Observation resource. #### Response Example { "observation": {} } ### Error Handling - **400** - Invalid input; the message names the problem and `field` the field. - **502** - Anpheros unreachable or server key invalid/revoked. - **403** - No access: consent missing, expired or revoked, or a read-only key. - **404** - Not in this project. - **422** - A reference that does not exist for you. - **503** - Rate limit exceeded. ``` -------------------------------- ### Execute FHIR R4 transaction via cURL Source: https://github.com/anpheros/anpheros-sdk/blob/main/examples/fhir-transaction/README.md Sends a POST request to the FHIR R4 endpoint with a bundle file to create a patient record atomically. Requires an authorization bearer token and the X-Anpheros-Author-Type header set to import. ```bash curl -X POST https://platform.anpheros.com/fhir/R4 \ -H "Authorization: Bearer $ANPHEROS_KEY" -H "Content-Type: application/fhir+json" \ -H "X-Anpheros-Author-Type: import" \ --data-binary @bundle.json ```