Spaces:
Paused
Paused
Update app/core/database.py
Browse files- app/core/database.py +22 -4
app/core/database.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
# app/core/database.py -
|
| 2 |
|
| 3 |
"""
|
| 4 |
JSON-based database manager for MVP
|
|
@@ -43,6 +43,22 @@ class JSONDatabase:
|
|
| 43 |
"""data/ papkasini yaratish"""
|
| 44 |
DATA_DIR.mkdir(exist_ok=True)
|
| 45 |
logger.info(f"β
Data papka tekshirildi: {DATA_DIR}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
def _initialize_files(self):
|
| 48 |
"""JSON fayllarni boshlang'ich holatda yaratish"""
|
|
@@ -64,9 +80,10 @@ class JSONDatabase:
|
|
| 64 |
if not DOCTORS_FILE.exists() or os.path.getsize(DOCTORS_FILE) == 0:
|
| 65 |
self._write_json(DOCTORS_FILE, {"doctors": []})
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
logger.info("β
Barcha data fayllar tayyor")
|
| 72 |
|
|
@@ -446,3 +463,4 @@ class JSONDatabase:
|
|
| 446 |
|
| 447 |
# Global database instance
|
| 448 |
db = JSONDatabase()
|
|
|
|
|
|
| 1 |
+
# app/core/database.py - BRIGADALARNI BOSHLANG'ICH YUKLASH BILAN TUZATILGAN
|
| 2 |
|
| 3 |
"""
|
| 4 |
JSON-based database manager for MVP
|
|
|
|
| 43 |
"""data/ papkasini yaratish"""
|
| 44 |
DATA_DIR.mkdir(exist_ok=True)
|
| 45 |
logger.info(f"β
Data papka tekshirildi: {DATA_DIR}")
|
| 46 |
+
|
| 47 |
+
# --- YANGI FUNKSIYA ---
|
| 48 |
+
def _initialize_brigades(self):
|
| 49 |
+
"""Agar brigades.json bo'sh bo'lsa, uni boshlang'ich ma'lumotlar bilan to'ldirish"""
|
| 50 |
+
logger.info("π Brigadalarni boshlang'ich yuklash tekshirilmoqda...")
|
| 51 |
+
initial_brigades = [
|
| 52 |
+
{"brigade_id": "brigade_001", "brigade_name": "Tez Yordam 1", "specialization": "umumiy", "current_status": "free", "current_lat": 41.3111, "current_lon": 69.2797, "assigned_case_id": None},
|
| 53 |
+
{"brigade_id": "brigade_002", "brigade_name": "Kardiologiya 2", "specialization": "kardiologiya", "current_status": "free", "current_lat": 41.2856, "current_lon": 69.2043, "assigned_case_id": None},
|
| 54 |
+
{"brigade_id": "brigade_003", "brigade_name": "Pediatriya 3", "specialization": "pediatriya", "current_status": "free", "current_lat": 41.3333, "current_lon": 69.2599, "assigned_case_id": None},
|
| 55 |
+
{"brigade_id": "brigade_004", "brigade_name": "Reanimatsiya 4", "specialization": "reanimatsiya", "current_status": "free", "current_lat": 41.3005, "current_lon": 69.2987, "assigned_case_id": None},
|
| 56 |
+
{"brigade_id": "brigade_005", "brigade_name": "Travmatologiya 5", "specialization": "travmatologiya", "current_status": "free", "current_lat": 41.3510, "current_lon": 69.2801, "assigned_case_id": None},
|
| 57 |
+
{"brigade_id": "brigade_006", "brigade_name": "Umumiy 6", "specialization": "umumiy", "current_status": "free", "current_lat": 41.2750, "current_lon": 69.2442, "assigned_case_id": None}
|
| 58 |
+
]
|
| 59 |
+
self._write_json(BRIGADES_FILE, {"brigades": initial_brigades})
|
| 60 |
+
logger.info(f"β
{len(initial_brigades)} ta boshlang'ich brigada yuklandi.")
|
| 61 |
+
# ----------------------
|
| 62 |
|
| 63 |
def _initialize_files(self):
|
| 64 |
"""JSON fayllarni boshlang'ich holatda yaratish"""
|
|
|
|
| 80 |
if not DOCTORS_FILE.exists() or os.path.getsize(DOCTORS_FILE) == 0:
|
| 81 |
self._write_json(DOCTORS_FILE, {"doctors": []})
|
| 82 |
|
| 83 |
+
# --- O'ZGARTIRILGAN QATOR ---
|
| 84 |
+
# Brigade file - endi har doim boshidan yuklanadi
|
| 85 |
+
self._initialize_brigades()
|
| 86 |
+
# ---------------------------
|
| 87 |
|
| 88 |
logger.info("β
Barcha data fayllar tayyor")
|
| 89 |
|
|
|
|
| 463 |
|
| 464 |
# Global database instance
|
| 465 |
db = JSONDatabase()
|
| 466 |
+
|