feat (therapy-protocol): add verification

This commit is contained in:
dpurbosakti
2025-11-14 14:16:07 +07:00
parent 1c04ff23f6
commit d03c1c7a93
5 changed files with 167 additions and 41 deletions
@@ -152,7 +152,6 @@ func SetRoutes() http.Handler {
hc.RegCrud(r, "/v1/prescription-item", prescriptionitem.O)
hc.RegCrud(r, "/v1/device-order-item", deviceorderitem.O)
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,
@@ -211,7 +210,6 @@ func SetRoutes() http.Handler {
"DELETE /{id}": medication.O.Delete,
"PATCH /{id}/complete": medication.O.Complete,
})
hk.GroupRoutes("/v1/medication-item", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": medicationitem.O.GetList,
"GET /{id}": medicationitem.O.GetDetail,
@@ -220,7 +218,6 @@ func SetRoutes() http.Handler {
"DELETE /{id}": medicationitem.O.Delete,
"PATCH /{id}/redeem": medicationitem.O.Redeem,
})
hk.GroupRoutes("/v1/medication-item-dist", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": medicationitemdist.O.GetList,
"GET /{id}": medicationitemdist.O.GetDetail,
@@ -229,7 +226,6 @@ func SetRoutes() http.Handler {
"DELETE /{id}": medicationitemdist.O.Delete,
"PATCH /{id}/consume": medicationitemdist.O.Consume,
})
hk.GroupRoutes("/v1/device-order", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": deviceorder.O.GetList,
"GET /{id}": deviceorder.O.GetDetail,
@@ -238,7 +234,6 @@ func SetRoutes() http.Handler {
"DELETE /{id}": deviceorder.O.Delete,
"PATCH /{id}/complete": deviceorder.O.Complete,
})
hk.GroupRoutes("/v1/material-order", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": materialorder.O.GetList,
"GET /{id}": materialorder.O.GetDetail,
@@ -247,7 +242,6 @@ func SetRoutes() http.Handler {
"DELETE /{id}": materialorder.O.Delete,
"PATCH /{id}/complete": materialorder.O.Complete,
})
hk.GroupRoutes("/v1/consultation", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": consultation.O.GetList,
"GET /{id}": consultation.O.GetDetail,
@@ -256,7 +250,6 @@ func SetRoutes() http.Handler {
"DELETE /{id}": consultation.O.Delete,
"PATCH /{id}/reply": consultation.O.Reply,
})
hk.GroupRoutes("/v1/chemo", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": chemo.O.GetList,
"GET /{id}": chemo.O.GetDetail,
@@ -266,13 +259,20 @@ func SetRoutes() http.Handler {
"PATCH /{id}/verify": chemo.O.Verify,
"PATCH /{id}/reject": chemo.O.Reject,
})
hc.RegCrud(r, "/v1/control-letter", controlletter.O)
hc.RegCrud(r, "/v1/internal-reference", internalreference.O)
hc.RegCrud(r, "/v1/ambulance-transport-req", ambulancetransportrequest.O)
hc.RegCrud(r, "/v1/responsible-doctor-hist", responsibledoctorhist.O)
hc.RegCrud(r, "/v1/adm-employee-hist", admemployeehist.O)
hc.RegCrud(r, "/v1/therapy-protocol", therapyprotocol.O)
hk.GroupRoutes("/v1/therapy-protocol", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": therapyprotocol.O.GetList,
"GET /{id}": therapyprotocol.O.GetDetail,
"POST /": therapyprotocol.O.Create,
"PATCH /{id}": therapyprotocol.O.Update,
"DELETE /{id}": therapyprotocol.O.Delete,
"PATCH /{id}/verify": therapyprotocol.O.Verify,
"PATCH /{id}/reject": therapyprotocol.O.Reject,
})
hc.RegCrud(r, "/v1/chemo-protocol", chemoprotocol.O)
hc.RegCrud(r, "/v1/upload", upload.O)
hc.RegCrud(r, "/v1/encounter-document", encounterdocument.O)
@@ -297,7 +297,6 @@ func SetRoutes() http.Handler {
"PATCH /{id}/active": user.O.Active,
})
hc.RegCrud(r, "/v1/user-fes", userfes.O)
hk.GroupRoutes("/v1/patient", r, hk.MapHandlerFunc{
"GET /": patient.O.GetList,
"GET /{id}": patient.O.GetDetail,
@@ -9,7 +9,12 @@ import (
// ua "github.com/karincake/tumpeng/auth/svc"
e "simrs-vx/internal/domain/main-entities/therapy-protocol"
erc "simrs-vx/internal/domain/references/common"
u "simrs-vx/internal/use-case/main-use-case/therapy-protocol"
d "github.com/karincake/dodol"
pa "simrs-vx/internal/lib/auth"
)
type myBase struct{}
@@ -71,3 +76,44 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Verify(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.VerifyDto{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto.AuthInfo = *authInfo
dto.Status_Code = erc.DVCVerified
res, err := u.Verify(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Reject(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.VerifyDto{}
dto.Id = uint(id)
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto.AuthInfo = *authInfo
dto.Status_Code = erc.DVCRejected
res, err := u.Verify(dto)
rw.DataResponse(w, res, err)
}