How earthians/marley works
Purpose and runtime
Marley Health is a Frappe application that adds hospital-information-system workflows to ERPNext: clinical care, outpatient/inpatient operations, diagnostics, rehabilitation, insurance, and patient access. It runs as a Python/Frappe app, with Frappe’s metadata-driven DocType persistence, permissions, desk UI, web routing, and API layer; ERPNext supplies adjacent finance, inventory, and accounting capabilities.
Application lifecycle and registration entry points are healthcare/hooks.py, healthcare/install.py, and healthcare/modules.txt. Schema/data upgrades are versioned and sequenced through healthcare/patches.txt.
Domain model and business boundary
The central architecture is a large set of Frappe DocTypes. Each domain object normally combines declarative schema/UI metadata (*.json), server lifecycle/business rules (*.py), and optional Desk behavior (*.js). Frappe owns request dispatch, ORM storage, access control, and document events; this repository implements healthcare-specific rules.
Representative anchors:
• Patient identity and longitudinal record: healthcare/healthcare/doctype/patient/patient.py, healthcare/healthcare/doctype/patient_medical_record/patient_medical_record.py
• Facility/practitioner scheduling: healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py, healthcare/healthcare/doctype/practitioner_schedule/practitioner_schedule.py
• Shared healthcare module utilities: healthcare/healthcare/healthcare.py, healthcare/healthcare/utils.py
Care delivery flow
Outpatient care typically progresses from patient and practitioner availability to appointment, encounter, clinical findings, and prescriptions/procedures. These documents form the primary clinical-control boundary and can invoke ERPNext-facing billing/customization logic.
• Booking: healthcare/healthcare/doctype/patient_appointment/patient_appointment.py
• Consultation and diagnoses/symptoms: healthcare/healthcare/doctype/patient_encounter/patient_encounter.py, healthcare/healthcare/doctype/patient_encounter_diagnosis/patient_encounter_diagnosis.py
• Procedures and medication requests: healthcare/healthcare/doctype/clinical_procedure/clinical_procedure.py, healthcare/healthcare/doctype/medication_request/medication_request.py
• ERPNext document extensions: healthcare/healthcare/custom_doctype/sales_invoice.py, healthcare/healthcare/custom_doctype/payment_entry.py
Acute, inpatient, and rehabilitation workflows
Separate but connected workflows model emergency triage, admission/occupancy, inpatient medication execution, and therapy plans/sessions. Their document status transitions are the operational control points.
• Emergency intake: healthcare/healthcare/doctype/emergency_record/emergency_record.py
• Admission and bed occupancy: healthcare/healthcare/doctype/inpatient_record/inpatient_record.py, healthcare/healthcare/doctype/inpatient_occupancy/inpatient_occupancy.py
• Medication orders and administration: healthcare/healthcare/doctype/inpatient_medication_order/inpatient_medication_order.py, healthcare/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py
• Rehabilitation: healthcare/healthcare/doctype/therapy_plan/therapy_plan.py, healthcare/healthcare/doctype/therapy_session/therapy_session.py
Diagnostics and observations
Diagnostic workflows convert prescriptions/service needs into sample collection, lab tests, results, reports, and structured observations. Templates and reference-range child documents make the data model configurable rather than hard-coded.
• Lab order/result path: healthcare/healthcare/doctype/lab_test/lab_test.py, healthcare/healthcare/doctype/sample_collection/sample_collection.py, healthcare/healthcare/doctype/diagnostic_report/diagnostic_report.py
• Clinical measurements: healthcare/healthcare/doctype/observation/observation.py, healthcare/healthcare/doctype/observation_template/observation_template.py
• Service-request abstraction: healthcare/healthcare/doctype/service_request/service_request.py, healthcare/controllers/service_request_controller.py
External and user-facing interfaces
Frappe Desk workspaces, reports, dashboards, print formats, web forms, and REST endpoints expose the document model. A separate Vue/Vite patient-portal SPA is built from patient_portal/ and is served alongside Frappe portal routes; its backend-facing API is healthcare/healthcare/api/patient_portal.py.
• Portal shell/routes: healthcare/www/patient-portal/index.py, healthcare/www/patient_portal.py
• SPA entry and real-time client: patient_portal/src/patient_portal.js, patient_portal/src/socket.js
• Regional ABDM integration/configuration: healthcare/regional/india/abdm/abdm_config.py, healthcare/regional/india/abdm/utils.py
Reporting and operational visibility
Workspace definitions organize Desk modules, while reports, chart sources, and number cards query persisted DocTypes for queues and analytics. They are read-model/UI boundaries rather than primary workflow owners.
• Workspaces: healthcare/healthcare/workspace/outpatient/outpatient.json, healthcare/healthcare/workspace/inpatient/inpatient.json
• Operational reports: healthcare/healthcare/report/emergency_triage_queue/emergency_triage_queue.py, healthcare/healthcare/report/lab_test_report/lab_test_report.py
• Dashboard query sources: healthcare/healthcare/dashboard_chart_source/insurance_claim_status/insurance_claim_status.py
Main entry points: patient.py Patient longitudinal record · healthcare.py Healthcare DocType model · medication_request.py Procedures & medication requests · inpatient_record.py Admission & occupancy
Components 21
Platform
- Frappe framework · Owns routing, ORM, permissions, events, and Desk.
- App lifecycle & patches · Registers modules and sequences schema/data upgrades.
healthcare/hooks.py - Healthcare DocType model · DocTypes combine schema, lifecycle rules, and optional Desk behavior.
healthcare/healthcare/healthcare.py - ERPNext · Provides finance, inventory, and accounting capabilities.
Clinical care
- Patient longitudinal record
healthcare/healthcare/doctype/patient/patient.py - Facility & practitioner scheduling
healthcare/healthcare/doctype/practitioner_schedule/practitioner_schedule.py - Patient appointment
healthcare/healthcare/doctype/patient_appointment/patient_appointment.py - Patient encounter · Captures consultation, diagnoses, and symptoms.
healthcare/healthcare/doctype/patient_encounter/patient_encounter.py - Procedures & medication requests
healthcare/healthcare/doctype/medication_request/medication_request.py
Hospital operations
- Emergency intake
healthcare/healthcare/doctype/emergency_record/emergency_record.py - Admission & occupancy · Controls admission status and bed occupancy.
healthcare/healthcare/doctype/inpatient_record/inpatient_record.py - Inpatient medication execution
healthcare/healthcare/doctype/inpatient_medication_entry/inpatient_medication_entry.py - Therapy plans & sessions
healthcare/healthcare/doctype/therapy_plan/therapy_plan.py
Diagnostics
- Service requests · Shared controller-backed request boundary for services.
healthcare/healthcare/doctype/service_request/service_request.py - Lab collection, tests & reports
healthcare/healthcare/doctype/lab_test/lab_test.py - Observations & templates · Configurable templates and reference ranges drive captured observations.
healthcare/healthcare/doctype/observation_template/observation_template.py
Interfaces & visibility
- Desk, REST & document UI · Frappe exposes DocTypes through Desk, web forms, print, and APIs.
- Patient portal SPA · Patient-facing portal with real-time client behavior.
patient_portal/src/patient_portal.js - Portal API & routes
healthcare/healthcare/api/patient_portal.py - ABDM integration
healthcare/regional/india/abdm/abdm_config.py - Workspaces, reports & dashboards · Queries persisted DocTypes for queues and analytics.
healthcare/healthcare/report/emergency_triage_queue/emergency_triage_queue.py
Connections 21
- App lifecycle & patches → Frappe framework: registers with
- Frappe framework → Healthcare DocType model: persists and governs
- Healthcare DocType model → Patient longitudinal record: defines
- Patient longitudinal record → Patient appointment: books
- Facility & practitioner scheduling → Patient appointment: provides availability
- Patient appointment → Patient encounter: leads to
- Patient encounter → Procedures & medication requests: creates
- Procedures & medication requests → ERPNext: invokes billing and inventory
- Patient longitudinal record → Emergency intake: identifies
- Emergency intake → Admission & occupancy: admits to
- Admission & occupancy → Inpatient medication execution: executes medication orders
- Admission & occupancy → Therapy plans & sessions: initiates therapy
- Procedures & medication requests → Service requests: requests services
- Service requests → Lab collection, tests & reports: drives
- Lab collection, tests & reports → Observations & templates: records results as
- Frappe framework → Desk, REST & document UI: serves
- Desk, REST & document UI → Healthcare DocType model: operates
- Patient portal SPA → Portal API & routes: calls
- Portal API & routes → Patient longitudinal record: accesses
- Portal API & routes → ABDM integration: integrates with
- Workspaces, reports & dashboards → Healthcare DocType model: queries