Server exports
Health
Server exports that read and write the Medical ID and medical records of the Health app.
The Health app keeps a Medical ID for every character and a list of medical records. These exports are how an ambulance job, a hospital or a pharmacy script reads and writes them. See Health.
In every export, target is a server id (number), a character identifier or a phone number (strings). An identifier or a number works for offline characters too.
#Medical ID
#GetMedicalProfile
Returns everything on a character's Medical ID.
lua---@class MedicalProfile
---@field name string
---@field birthdate string|nil from the character
---@field age integer|nil
---@field gender string|nil
---@field blood string
---@field bloodLocked boolean true when the framework owns the blood type
---@field height integer|nil cm
---@field weight integer|nil kg
---@field donor boolean
---@field emergencyAccess boolean medics may open it
---@field allergies string[]
---@field conditions string[]
---@field medications string[]
---@field contacts { name: string, number: string, relation?: string }[]
---@field notes string|nil
---@field updatedAt integer
---@param target integer|string
---@return MedicalProfile|nil profile
exports['fx-phone']:GetMedicalProfile(target)
lualocal profile = exports['fx-phone']:GetMedicalProfile(source)
#GetBloodType
Returns a character's blood type.
lua---@param target integer|string
---@return string|nil blood one of O+, A+, B+, AB+, O-, A-, B-, AB-
exports['fx-phone']:GetBloodType(target)
lualocal blood = exports['fx-phone']:GetBloodType(source)
- On QBCore and Qbox this is the blood type the framework gave the character. On other frameworks the phone gives every character one the first time it is asked, and keeps it.
#SetBloodType
Changes a character's blood type.
lua---@param target integer|string
---@param blood string
---@return boolean ok
exports['fx-phone']:SetBloodType(target, blood)
luaexports['fx-phone']:SetBloodType(source, 'O-')
- On QBCore and Qbox the framework's own value is changed too.
#SetMedicalField
Changes one field of a Medical ID.
lua---@param target integer|string
---@param key string
---@param value any
---@return boolean ok
exports['fx-phone']:SetMedicalField(target, key, value)
luaexports['fx-phone']:SetMedicalField(source, 'weight', 82)
key |
Value |
|---|---|
blood |
A blood type |
height |
100 to 250 (cm), or false to clear it |
weight |
30 to 300 (kg), or false to clear it |
donor |
true / false |
emergencyAccess |
true / false |
allergies, conditions, medications |
A list of texts, up to 12 of 60 characters each. The list replaces the old one |
contacts |
Up to 3 of { name, number, relation? } |
notes |
Up to 500 characters |
#Medical records
#AddMedicalRecord
Writes a record into a character's medical history. The patient sees it in the Health app and gets a notification.
lua---@class MedicalRecordInput
---@field kind? 'treatment'|'diagnosis'|'surgery'|'prescription'|'vaccine'|'test'|'checkup'|'injury'|'revive'|'note' default 'treatment'
---@field title string up to 80 characters; the only required field
---@field details? string up to 1000 characters (`description` is accepted too)
---@field doctor? string name shown on the record, up to 80 characters
---@field doctorIdentifier? string the medic's identifier, kept for your own lookups
---@field facility? string up to 80 characters
---@field severity? integer 0 info, 1 minor, 2 moderate, 3 serious, 4 critical
---@field cost? number shown on the record only; no money moves
---@field data? table small table of readings shown as a list, up to 2000 bytes as JSON
---@field days? number for a prescription: how long it is valid
---@field untilAt? integer or the end time in unix seconds
---@field at? integer record time in unix seconds; now by default
---@field notify? boolean false to add it without a notification
---@param target integer|string
---@param record MedicalRecordInput
---@return integer|nil id
---@return string|nil err
exports['fx-phone']:AddMedicalRecord(target, record)
lualocal id = exports['fx-phone']:AddMedicalRecord(patientSource, {
kind = 'prescription', title = 'Painkillers', details = 'Twice a day.', days = 5, doctor = 'Dr. Aras',
})
- Errors:
disabled(Config.Health.Enabled = false),invalid(no table or no title),not_found. - Once a character has more than
Config.Health.MaxRecordsrecords (200 by default), the oldest are deleted. - Fires the server event
fx-phone:server:medicalRecordAdded. See Server events.
#GetMedicalRecords
Returns a character's records, newest first.
lua---@param target integer|string
---@param opts? { kind?: string, limit?: integer, since?: integer, active?: boolean } limit 1 to 200, default 60; since in unix seconds; active = true keeps records that have not expired
---@return table[] records
exports['fx-phone']:GetMedicalRecords(target, opts)
lualocal records = exports['fx-phone']:GetMedicalRecords(source, { kind = 'surgery', limit = 20 })
- Each record:
{ id, kind, title, details, doctor, facility, severity, cost, data, untilAt, at }.
#GetActivePrescriptions
Returns the prescriptions that are still valid, at most 50.
lua---@param target integer|string
---@return table[] prescriptions
exports['fx-phone']:GetActivePrescriptions(target)
luafor _, rx in ipairs(exports['fx-phone']:GetActivePrescriptions(source)) do print(rx.title, rx.untilAt) end
#RemoveMedicalRecord
Deletes a record. Players cannot delete records from their phone.
lua---@param id integer the record id
---@return boolean removed
exports['fx-phone']:RemoveMedicalRecord(id)
luaexports['fx-phone']:RemoveMedicalRecord(recordId)
#For an ambulance job
#ShowMedicalId
Opens a patient's Medical ID on someone else's phone.
lua---@param viewer integer server id of the player who sees it
---@param patient integer server id of the patient
---@return boolean shown
exports['fx-phone']:ShowMedicalId(viewer, patient)
luaexports['fx-phone']:ShowMedicalId(medicSource, patientSource)
- If the viewer's job is in
Config.Health.MedicJobs, they also see the patient's records and can add one from the phone. - This works even when the patient switched emergency access off: your script is what decided the viewer may look, so check that yourself before calling it.