add switch poly and spprove
This commit is contained in:
@@ -3,18 +3,17 @@ package encounter
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
sf "github.com/karincake/semprit"
|
||||
|
||||
// ua "github.com/karincake/tumpeng/auth/svc"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
u "simrs-vx/internal/use-case/main-use-case/encounter"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
)
|
||||
|
||||
type myBase struct{}
|
||||
@@ -31,7 +30,13 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
if valid := validateRequestCreate(w, dto); !valid {
|
||||
|
||||
// validate SubClass
|
||||
if err := verifyClassCode(dto); err != nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -192,3 +197,40 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) {
|
||||
res, err := u.UpdateStatusCode(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.SwitchUnitDto{}
|
||||
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 := validateRequestSwitchUnit(w, dto); !valid {
|
||||
return
|
||||
}
|
||||
|
||||
dto.Id = uint(id)
|
||||
res, err := u.RequestSwitchUnit(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveUnitDto{}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
dto.Id = uint(id)
|
||||
res, err := u.ApproveSwitchUnit(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package encounter
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
ere "simrs-vx/internal/domain/references/encounter"
|
||||
ua "simrs-vx/internal/use-case/main-use-case/ambulatory"
|
||||
ue "simrs-vx/internal/use-case/main-use-case/emergency"
|
||||
ui "simrs-vx/internal/use-case/main-use-case/inpatient"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
@@ -11,6 +16,25 @@ import (
|
||||
|
||||
const dataValidationFail = "data-validation-fail"
|
||||
|
||||
func verifyClassCode(input e.CreateDto) (err error) {
|
||||
switch input.Class_Code {
|
||||
case ere.ECAmbulatory:
|
||||
_, err = ua.CheckClassCode(input.SubClass_Code)
|
||||
case ere.ECEmergency:
|
||||
_, err = ue.CheckClassCode(input.SubClass_Code)
|
||||
case ere.ECInpatient:
|
||||
_, err = ui.CheckClassCode(input.SubClass_Code)
|
||||
default:
|
||||
return errors.New("invalid encounter class code")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) {
|
||||
if *i.Discharge_Method_Code == ere.DMCDeath && i.DeathCause == nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
@@ -19,34 +43,6 @@ func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid boo
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
//case ere.DMCConsulPoly, ere.DMCConsulExecutive:
|
||||
// if i.InternalReferences == nil {
|
||||
// rw.DataResponse(w, nil, d.FieldError{
|
||||
// Code: dataValidationFail,
|
||||
// Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code),
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// for _, v := range *i.InternalReferences {
|
||||
// if v.Unit_Id == nil {
|
||||
// rw.DataResponse(w, nil, d.FieldError{
|
||||
// Code: dataValidationFail,
|
||||
// Message: "internalReferences.unit_id required",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if v.Doctor_Id == nil {
|
||||
// rw.DataResponse(w, nil, d.FieldError{
|
||||
// Code: dataValidationFail,
|
||||
// Message: "internalReferences.doctor_id required",
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -62,18 +58,30 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool)
|
||||
return true
|
||||
}
|
||||
|
||||
func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) {
|
||||
switch {
|
||||
case i.Class_Code == ere.ECAmbulatory:
|
||||
// field allocatedVisitCount required if ambulatory visitMode_Code is adm
|
||||
if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRehab && *i.VisitMode_Code == ere.VMCAdm {
|
||||
if *i.AllocatedVisitCount == 0 {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: "allocatedVisitCount required",
|
||||
})
|
||||
return
|
||||
}
|
||||
func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) {
|
||||
if i.InternalReferences == nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: fmt.Sprintf("internalReferences required"),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
for _, v := range *i.InternalReferences {
|
||||
if v.Unit_Id == nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: "internalReferences.unit_id required",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if v.Doctor_Id == nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: "internalReferences.doctor_id required",
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -144,17 +144,19 @@ func SetRoutes() http.Handler {
|
||||
hc.RegCrud(r, "/v1/material-order-item", materialorderitem.O)
|
||||
|
||||
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}/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,
|
||||
"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,
|
||||
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit,
|
||||
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
|
||||
})
|
||||
hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{
|
||||
"GET /": mcuorder.O.GetList,
|
||||
|
||||
Reference in New Issue
Block a user