add encounter-checkin

This commit is contained in:
vanilia
2025-10-27 06:25:12 +07:00
parent a7ce13c76e
commit a2ce9d9357
9 changed files with 192 additions and 66 deletions
@@ -102,6 +102,27 @@ func (obj myBase) CheckOut(w http.ResponseWriter, r *http.Request) {
rw.DataResponse(w, res, err)
}
func (obj myBase) CheckIn(w http.ResponseWriter, r *http.Request) {
dto := e.CheckinDto{}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
// validate request body
if valid := validateRequestCheckIn(w, dto); !valid {
return
}
dto.Id = uint(id)
res, err := u.CheckIn(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Process(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
@@ -10,9 +10,9 @@ import (
rw "github.com/karincake/risoles"
)
func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) {
const dataValidationFail = ""
const dataValidationFail = "data-validation-fail"
func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) {
switch *i.Discharge_Method_Code {
case ere.DMCDeath:
if i.DeathCause == nil {
@@ -51,3 +51,15 @@ func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid boo
}
return true
}
func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) {
if i.Responsible_Doctor_Id == nil && i.Adm_Employee_Id == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "responsible_doctor_id or adm_employee_id required",
})
return
}
return true
}
+11 -10
View File
@@ -172,16 +172,17 @@ func SetRoutes() http.Handler {
"PATCH /{id}/complete": mcuordersubitem.O.Complete,
})
hk.GroupRoutes("/v1/encounter", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": encounter.O.GetList,
"GET /{id}": encounter.O.GetDetail,
"POST /": encounter.O.Create,
"PATCH /{id}": encounter.O.Update,
"DELETE /{id}": encounter.O.Delete,
"PATCH /{id}/checkout": encounter.O.CheckOut,
"PATCH /{id}/proccess": encounter.O.Process,
"PATCH /{id}/cancel": encounter.O.Cancel,
"PATCH /{id}/reject": encounter.O.Reject,
"PATCH /{id}/skip": encounter.O.Skip,
"GET /": encounter.O.GetList,
"GET /{id}": encounter.O.GetDetail,
"POST /": encounter.O.Create,
"PATCH /{id}": encounter.O.Update,
"DELETE /{id}": encounter.O.Delete,
"PATCH /{id}/check-out": encounter.O.CheckOut,
"PATCH /{id}/check-in": encounter.O.CheckIn,
"PATCH /{id}/proccess": encounter.O.Process,
"PATCH /{id}/cancel": encounter.O.Cancel,
"PATCH /{id}/reject": encounter.O.Reject,
"PATCH /{id}/skip": encounter.O.Skip,
})
hk.GroupRoutes("/v1/medication", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": medication.O.GetList,