set checkin checkout

This commit is contained in:
vanilia
2025-11-24 10:17:37 +07:00
parent ee6f37bb54
commit 157ea603a4
13 changed files with 694 additions and 136 deletions
@@ -70,6 +70,11 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
@@ -80,29 +85,39 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
return
}
dto.Id = uint16(id)
dto.AuthInfo = *authInfo
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.DeleteDto{}
dto.Id = uint16(id)
dto.AuthInfo = *authInfo
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) CheckOut(w http.ResponseWriter, r *http.Request) {
dto := e.DischargeDto{}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
@@ -118,12 +133,20 @@ func (obj myBase) CheckOut(w http.ResponseWriter, r *http.Request) {
}
dto.Id = uint(id)
dto.AuthInfo = *authInfo
res, err := u.CheckOut(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) CheckIn(w http.ResponseWriter, r *http.Request) {
dto := e.CheckinDto{}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
@@ -139,6 +162,8 @@ func (obj myBase) CheckIn(w http.ResponseWriter, r *http.Request) {
}
dto.Id = uint(id)
dto.AuthInfo = *authInfo
res, err := u.CheckIn(dto)
rw.DataResponse(w, res, err)
}
@@ -0,0 +1,63 @@
package encounter
import (
"net/http"
rw "github.com/karincake/risoles"
// ua "github.com/karincake/tumpeng/auth/svc"
e "simrs-vx/internal/domain/main-entities/encounter"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/encounter"
)
type myBase struct{}
var O myBase
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
dto := e.Encounter{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
res, err := u.Create(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) CreateLog(w http.ResponseWriter, r *http.Request) {
dto := esync.SimxLogDto{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
res, err := u.CreateSimxLog(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.Encounter{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
dto := e.DeleteDto{}
dto.Id = uint16(id)
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -19,6 +19,7 @@ import (
/******************** internal ********************/
"simrs-vx/internal/interface/main-handler/home"
division "simrs-vx/internal/interface/simgos-sync-handler/division"
encounter "simrs-vx/internal/interface/simgos-sync-handler/encounter"
installation "simrs-vx/internal/interface/simgos-sync-handler/installation"
patient "simrs-vx/internal/interface/simgos-sync-handler/patient"
specialist "simrs-vx/internal/interface/simgos-sync-handler/specialist"
@@ -47,6 +48,7 @@ func SetRoutes() http.Handler {
hc.SyncCrud(r, prefix+"/v1/subspecialist", subspecialist.O)
hc.SyncCrud(r, prefix+"/v1/patient", patient.O)
r.HandleFunc(fmt.Sprintf("GET %s/v1/patient-nomr-generator", prefix), patient.O.GenerateNomr)
hc.SyncCrud(r, prefix+"/v1/encounter", encounter.O)
return cmw.SetCors(handlerlogger.SetLog(r))
}