feat: add dynamic hospital database registry
This commit is contained in:
71
README.md
71
README.md
@@ -139,9 +139,80 @@ DB_PORT=3306
|
||||
DB_DATABASE=primaya
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
DB_DEFAULT_RS_CODE=AWALBROS_DEV
|
||||
DB_DEFAULT_RS_NAME=RS Dev Awalbros
|
||||
|
||||
CPONE_DB_HOST=127.0.0.1
|
||||
CPONE_DB_PORT=3306
|
||||
CPONE_DB_DATABASE=cpone_middleware
|
||||
CPONE_DB_USERNAME=root
|
||||
CPONE_DB_PASSWORD=
|
||||
CPONE_BEARER_TOKEN=replace-with-a-secure-token
|
||||
CPONE_DATABASE_SETTINGS_TOKEN=replace-with-a-different-admin-token
|
||||
CPONE_DATABASE_CREDENTIAL_KEY=replace-with-a-long-random-encryption-key
|
||||
```
|
||||
|
||||
`DB_*` tetap menjadi koneksi default (saat ini database dev Awalbros). Request
|
||||
lama yang tidak mengirim kode RS akan tetap menggunakan koneksi ini.
|
||||
|
||||
## Multi-database per kode RS
|
||||
|
||||
Tambahkan atau perbarui koneksi RS melalui API berikut. Koneksi akan dites
|
||||
sebelum disimpan; bila `Ping` gagal, setting tidak disimpan.
|
||||
|
||||
```http
|
||||
POST /api/cpone/database-settings
|
||||
Authorization: Bearer <your-database-settings-token>
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"kode_rs": "PRIMAYA_BEKASI_BARAT",
|
||||
"nama": "Primaya Hospital Bekasi Barat",
|
||||
"host": "10.10.10.20",
|
||||
"port": "3306",
|
||||
"database": "his_bekasi_barat",
|
||||
"username": "cpone",
|
||||
"password": "secret"
|
||||
}
|
||||
```
|
||||
|
||||
Endpoint pengelolaan yang tersedia:
|
||||
|
||||
```text
|
||||
POST /api/cpone/database-settings
|
||||
GET /api/cpone/database-settings
|
||||
GET /api/cpone/database-settings/{kodeRs}
|
||||
```
|
||||
|
||||
Saat startup, service otomatis membuat database `CPONE_DB_DATABASE` beserta
|
||||
tabel `hospitals` dan `hospital_databases`. Koneksi HIS lama dari `DB_*` otomatis
|
||||
menjadi RS default. Akun `CPONE_DB_USERNAME` harus memiliki izin `CREATE
|
||||
DATABASE` pada bootstrap pertama; alternatifnya jalankan migration
|
||||
`database/migrations/001_create_cpone_management.sql` secara manual.
|
||||
|
||||
Response list/detail tidak pernah menampilkan password, hanya field
|
||||
`has_password`. Password koneksi RS disimpan terenkripsi AES-GCM menggunakan
|
||||
`CPONE_DATABASE_CREDENTIAL_KEY`. Jangan mengubah key tersebut setelah data mulai
|
||||
disimpan karena password lama tidak akan bisa didekripsi. Jika key belum diisi,
|
||||
service memakai `CPONE_DATABASE_SETTINGS_TOKEN`, lalu `CPONE_BEARER_TOKEN`
|
||||
sebagai fallback; token fallback itu juga tidak boleh diubah tanpa rotasi
|
||||
credential.
|
||||
|
||||
Endpoint pengelolaan memakai `CPONE_DATABASE_SETTINGS_TOKEN`. Jika variabel ini
|
||||
belum diisi, service memakai `CPONE_BEARER_TOKEN` untuk kompatibilitas; gunakan
|
||||
token admin yang berbeda di production.
|
||||
|
||||
Pilih database pada semua endpoint bisnis dengan header:
|
||||
|
||||
```http
|
||||
X-RS-Code: PRIMAYA_BEKASI_BARAT
|
||||
```
|
||||
|
||||
Sebagai alternatif dapat memakai query `?kode_rs=PRIMAYA_BEKASI_BARAT`.
|
||||
Header memiliki prioritas lebih tinggi daripada query. Response juga memuat
|
||||
header `X-RS-Code` agar koneksi yang terpilih mudah diaudit. Jika keduanya tidak
|
||||
ada, service memakai `DB_DEFAULT_RS_CODE`.
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
|
||||
Reference in New Issue
Block a user