Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +24 -0
api_server.py
CHANGED
|
@@ -164,6 +164,7 @@ from pydantic import BaseModel
|
|
| 164 |
# 病患
|
| 165 |
class PatientCreate(BaseModel):
|
| 166 |
name: str
|
|
|
|
| 167 |
birth: str | None = None
|
| 168 |
gender: str | None = None
|
| 169 |
phone: str | None = None
|
|
@@ -221,7 +222,30 @@ def get_patient(patient_id: int, db: Session = Depends(get_db)):
|
|
| 221 |
if not patient:
|
| 222 |
raise HTTPException(status_code=404, detail="找不到病患")
|
| 223 |
return patient
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
# =================================================================
|
| 226 |
# 7. 護士 API
|
| 227 |
# =================================================================
|
|
|
|
| 164 |
# 病患
|
| 165 |
class PatientCreate(BaseModel):
|
| 166 |
name: str
|
| 167 |
+
mrn: str | None = None
|
| 168 |
birth: str | None = None
|
| 169 |
gender: str | None = None
|
| 170 |
phone: str | None = None
|
|
|
|
| 222 |
if not patient:
|
| 223 |
raise HTTPException(status_code=404, detail="找不到病患")
|
| 224 |
return patient
|
| 225 |
+
|
| 226 |
+
@app.put("/patients/{patient_id}")
|
| 227 |
+
def update_patient(patient_id: int, data: PatientCreate, db: Session = Depends(get_db)):
|
| 228 |
+
patient = db.query(Patient).filter(Patient.id == patient_id).first()
|
| 229 |
+
if not patient:
|
| 230 |
+
raise HTTPException(status_code=404, detail="找不到病患")
|
| 231 |
|
| 232 |
+
for key, value in data.dict().items():
|
| 233 |
+
setattr(patient, key, value)
|
| 234 |
+
|
| 235 |
+
db.commit()
|
| 236 |
+
db.refresh(patient)
|
| 237 |
+
return patient
|
| 238 |
+
|
| 239 |
+
@app.delete("/patients/{patient_id}")
|
| 240 |
+
def delete_patient(patient_id: int, db: Session = Depends(get_db)):
|
| 241 |
+
patient = db.query(Patient).filter(Patient.id == patient_id).first()
|
| 242 |
+
if not patient:
|
| 243 |
+
raise HTTPException(status_code=404, detail="找不到病患")
|
| 244 |
+
|
| 245 |
+
db.delete(patient)
|
| 246 |
+
db.commit()
|
| 247 |
+
return {"message": "病患已刪除"}
|
| 248 |
+
|
| 249 |
# =================================================================
|
| 250 |
# 7. 護士 API
|
| 251 |
# =================================================================
|