tested, add systemd deploy guide
This commit is contained in:
@@ -29,7 +29,7 @@ curl -X POST "http://localhost:8000/migrate/R.20240401.0138" \
|
|||||||
-H "Content-Type: application/json"
|
-H "Content-Type: application/json"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Response Example
|
### Response Success Example
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
@@ -58,6 +58,36 @@ curl -X POST "http://localhost:8000/migrate/R.20240401.0138" \
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Response Failed Example
|
||||||
|
Kalau sudah ada di tabel HIS:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"success":true,
|
||||||
|
"message":"Berhasil migrasi file DICOM tetapi gagal update HIS: ERR: Accession No. R.20240401.0142 sudah ada ke table `pacs_order_mwl`!",
|
||||||
|
"details":{
|
||||||
|
"accession_number":"R.20240401.0142",
|
||||||
|
"process_start_time":"2025-07-11 16:05:10",
|
||||||
|
"steps_completed":[
|
||||||
|
"study_found","study_retrieved","study_sent","log_created","his_api_failed","cleanup_success"
|
||||||
|
],
|
||||||
|
"study_uid":"1.2.826.1.3680043.9.5282.150415.204342.202404010142",
|
||||||
|
"patient_id":"00204342",
|
||||||
|
"study_description":"A103 - Thorax PA",
|
||||||
|
"instances_retrieved":4,
|
||||||
|
"files_sent":2,
|
||||||
|
"total_files":2,
|
||||||
|
"c_store_success":true,
|
||||||
|
"series_count":4,
|
||||||
|
"his_api_status_code":406,
|
||||||
|
"his_integration_success":false,
|
||||||
|
"his_error":"ERR: Accession No. R.20240401.0142 sudah ada ke table `pacs_order_mwl`!","cleanup_success":true,
|
||||||
|
"process_end_time":"2025-07-11 16:05:12"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Logs
|
## Logs
|
||||||
|
|
||||||
- Main API logs: `logs/api.log`
|
- Main API logs: `logs/api.log`
|
||||||
@@ -99,3 +129,52 @@ curl -X POST "http://localhost:8000/migrate/R.20240401.0138" \
|
|||||||
-H "Authorization: Bearer token-his2-untuk-hit-api-migrasi-clarity"
|
-H "Authorization: Bearer token-his2-untuk-hit-api-migrasi-clarity"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Deploy Systemd Service
|
||||||
|
|
||||||
|
1. Create a service file:
|
||||||
|
```bash
|
||||||
|
sudo nano /etc/systemd/system/api-pydicom-migrasi.service
|
||||||
|
```
|
||||||
|
2. Add the following content:
|
||||||
|
```ini
|
||||||
|
[Unit]
|
||||||
|
Description=DICOM Migration API Service
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=pacs
|
||||||
|
Group=pacs
|
||||||
|
WorkingDirectory=/home/pacs/pydicom-migrasi-clarity
|
||||||
|
Environment="PATH=/home/pacs/pydicom-migrasi-clarity/venv/bin"
|
||||||
|
Environment="API_TOKEN=$2y$05$o1Sfikmwynq76PmuBkJeROpS2WcD.Sh4lgrjohMicnlhBlGAt8UAq"
|
||||||
|
ExecStart=/home/pacs/pydicom-migrasi-clarity/venv/bin/python /home/pacs/pydicom-migrasi-clarity/api-app/run.py --host 0.0.0.0 --port 8000
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Reload systemd and enable the service:
|
||||||
|
```bash
|
||||||
|
# Reload the systemd configuration
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
|
||||||
|
# Enable the service to start on boot
|
||||||
|
sudo systemctl enable api-pydicom-migrasi.service
|
||||||
|
|
||||||
|
# Start the service
|
||||||
|
sudo systemctl start api-pydicom-migrasi.service
|
||||||
|
|
||||||
|
# Check the status
|
||||||
|
sudo systemctl status api-pydicom-migrasi.service
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Monitor logs:
|
||||||
|
```bash
|
||||||
|
# View all logs
|
||||||
|
sudo journalctl -u api-pydicom-migrasi.service
|
||||||
|
|
||||||
|
# Follow logs in real-time
|
||||||
|
sudo journalctl -u api-pydicom-migrasi.service -f
|
||||||
|
```
|
||||||
@@ -33,7 +33,7 @@ app = FastAPI(
|
|||||||
security = HTTPBearer()
|
security = HTTPBearer()
|
||||||
|
|
||||||
# Environment variable for API key (use a secure method in production)
|
# Environment variable for API key (use a secure method in production)
|
||||||
API_TOKEN = os.environ.get("API_TOKEN", "token-his2-untuk-hit-api-migrasi-clarity")
|
API_TOKEN = os.environ.get("API_TOKEN", "$2y$05$o1Sfikmwynq76PmuBkJeROpS2WcD.Sh4lgrjohMicnlhBlGAt8UAq")
|
||||||
|
|
||||||
class MigrationResponse(BaseModel):
|
class MigrationResponse(BaseModel):
|
||||||
"""Response model for migration endpoints."""
|
"""Response model for migration endpoints."""
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def main():
|
|||||||
|
|
||||||
# Check if API_TOKEN is set
|
# Check if API_TOKEN is set
|
||||||
if not os.environ.get('API_TOKEN'):
|
if not os.environ.get('API_TOKEN'):
|
||||||
print("WARNING: API_TOKEN not set. Using default token 'token-his2-untuk-hit-api-migrasi-clarity'.")
|
print("WARNING: API_TOKEN not set. Using default token '$2y$05$o1Sfikmwynq76PmuBkJeROpS2WcD.Sh4lgrjohMicnlhBlGAt8UAq'.")
|
||||||
print("Set environment variable API_TOKEN or use --token argument for better security.")
|
print("Set environment variable API_TOKEN or use --token argument for better security.")
|
||||||
|
|
||||||
# Set up signal handlers for graceful shutdown
|
# Set up signal handlers for graceful shutdown
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
@host = http://localhost:8000
|
@host = http://localhost:8000
|
||||||
@token = token-his2-untuk-hit-api-migrasi-clarity
|
@token = $2y$05$o1Sfikmwynq76PmuBkJeROpS2WcD.Sh4lgrjohMicnlhBlGAt8UAq
|
||||||
|
|
||||||
|
|
||||||
### Healtcheck
|
### Healtcheck
|
||||||
@@ -9,4 +9,9 @@ GET {{host}}/
|
|||||||
###
|
###
|
||||||
POST {{host}}/migrate/R.20240401.0138
|
POST {{host}}/migrate/R.20240401.0138
|
||||||
Authorization: Bearer {{token}}
|
Authorization: Bearer {{token}}
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
####
|
||||||
|
POST {{host}}/migrate/R.20240401.0142
|
||||||
|
Authorization: Bearer {{token}}
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Reference in New Issue
Block a user