xiaohongshu
xiaohongshu
medirecords-integration
Complete MediRecords FHIR/REST API integration guide for Dr. Sophia AI consultations. Covers two-phase workflow (FHIR Encounter creation + REST notes append), patient search, SOAP note formatting, and troubleshooting. Use when integrating MediRecords API, creating consultations, debugging FHIR/RE...
Full skill instructions
Access the complete guide for integrating Dr. Sophia AI consultations with MediRecords EHR system using FHIR v1 and REST v1 APIs. This skill provides the two-phase workflow, API credentials, FHIR schemas, troubleshooting guide, and test scripts.
Keywords: MediRecords, FHIR API, REST API, consultation creation, SOAP notes, encounter, EHR integration, patient records, clinical documentation
Status: ✅ Fully tested and working (verified Oct 22, 2025)
MediRecords requires TWO separate API calls to create a complete consultation:
POST https://api.medirecords.com/fhir/v1/EncounterPOST https://api.medirecords.com/v1/patients/{id}/consults/{encounterId}/consultnote/append✅ Must create encounter with status: "finished" (not "in-progress")
✅ Must include serviceProvider field (practice ID)
✅ Must append notes within 1 hour of encounter endTime
✅ Use FHIR token for Phase 1, REST token for Phase 2 (different tokens!)
const searchResponse = await fetch(
'https://api.medirecords.com/fhir/v1/[email protected]',
{
headers: {
'Authorization': `Bearer ${FHIR_TOKEN}`,
'Content-Type': 'application/fhir+json'
}
}
);
const patientData = await searchResponse.json();
const patientId = patientData.entry[0].resource.id;
const encounterResponse = await fetch(
'https://api.medirecords.com/fhir/v1/Encounter',
{
method: 'POST',
headers: {
'Authorization': `Bearer ${FHIR_TOKEN}`,
'Content-Type': 'application/fhir+json'
},
body: JSON.stringify({
resourceType: 'Encounter',
status: 'finished', // ✅ MUST be "finished"
class: {
system: 'http://terminology.hl7.org/CodeSystem/v3-ActCode',
code: 'AMB',
display: 'ambulatory'
},
subject: { reference: `Patient/${patientId}` },
participant: [{
individual: { reference: `Practitioner/${DR_SOPHIA_ID}` }
}],
serviceProvider: { // ✅ REQUIRED!
reference: `Organization/${PRACTICE_ID}`
},
period: {
start: new Date(Date.now() - 30*60000).toISOString(),
end: new Date().toISOString()
}
})
}
);
const encounter = await encounterResponse.json();
const encounterId = encounter.id;
const soapNotes = `
<div id="stamp">
<div><strong>${new Date().toLocaleString('en-AU')}</strong></div>
<div><strong>Dr. Sophia AI - Consultation Notes</strong></div>
</div>
<p><strong>Chief Complaint:</strong> Headaches for 3 months</p>
<p><strong>Subjective:</strong> Patient reports...</p>
<p><strong>Objective:</strong> BP 145/92...</p>
<p><strong>Assessment:</strong> Uncontrolled hypertension</p>
<p><strong>Plan:</strong> Adjust medication...</p>
`;
const noteResponse = await fetch(
`https://api.medirecords.com/v1/patients/${patientId}/consults/${encounterId}/consultnote/append`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${REST_TOKEN}`, // ✅ Different token!
'Content-Type': 'application/json'
},
body: JSON.stringify({ consultNote: soapNotes })
}
);
| Feature | Status | Details |
|---|---|---|
| Create finished consultation | ✅ Works | Use FHIR API with status: "finished" |
| Append notes (unlimited) | ✅ Works | Use REST API within 1 hour |
| HTML formatting in notes | ✅ Works | Supports p, strong, div, ul, li, br, table |
| Multiple appends | ✅ Works | Can append multiple times within 1 hour |
| Create "in-progress" consult | ❌ Blocked | API returns HTTP 409 error |
| Update consult status | ❌ No endpoint | Cannot change status after creation |
| Update/replace notes | ❌ No endpoint | Can only append, not edit |
For complete API credentials, FHIR schemas, and troubleshooting guide, see:
Run integration test script:
cd .claude/skills/medirecords-integration
./scripts/test-consultation.sh [email protected]
Expected output:
✅ Encounter created: [encounter-id]
✅ Notes appended: [note-id]
✅ Consultation visible in MediRecords UI
Add to backend consultation handler (/backend/backend-proxy-enhanced-current.js):
// After consultation completes and SOAP notes extracted
if (req.body.patientIdentifier && shouldSaveToMedirecords(aiResponse)) {
try {
const consultationData = {
chiefComplaint: extractedData.chiefComplaint,
subjective: extractedData.subjective,
objective: extractedData.objective,
assessment: extractedData.assessment,
plan: extractedData.plan,
prescriptions: extractedData.prescriptions
};
const result = await createDrSophiaConsultationWithNotes(
req.body.patientIdentifier,
consultationData
);
console.log(`✅ Consultation saved: ${result.encounterId}`);
} catch (error) {
console.error('❌ Failed to save consultation:', error);
// Don't fail the response - consultation still worked
}
}
| Error | Cause | Fix |
|---|---|---|
| HTTP 409 | Status "in-progress" | Change to "finished" |
| HTTP 500 | Missing serviceProvider | Add practice Organization reference |
| HTTP 400 (notes) | >1 hour since endTime | Use recent timestamps |
| Notes don't appear | Wrong token for append | Use REST token (not FHIR) |
| HTML not rendering | Unsupported tags | Use only: p, strong, div, ul, li, br, table |
Patient: Willie Prosek ([email protected]) Last Verified: October 22, 2025 at 8:17 PM Encounters Created: 3+ consultations Notes Appended: Multiple times per consultation UI Verification: ✅ All consultations visible in MediRecords HTML Formatting: ✅ Preserved correctly Character Limit: ✅ Tested up to 1,975 characters
Status: Production-ready, fully tested API Version: FHIR v1 + REST v1 Test Patient: [email protected] Last Updated: October 22, 2025
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience