Merge branch 'feat/sync-setting' into feat/sync-from-simgos-161

This commit is contained in:
poetrasapoetra
2025-11-28 13:18:29 +07:00
162 changed files with 5395 additions and 401 deletions
@@ -8,7 +8,8 @@ import (
e "simrs-vx/internal/domain/main-entities/division"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/division"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/division"
)
type myBase struct{}
@@ -0,0 +1,88 @@
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/new/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) {
dto := e.Encounter{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
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)
}
func (obj myBase) Checkin(w http.ResponseWriter, r *http.Request) {
dto := e.Encounter{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
res, err := u.CheckIn(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Checkout(w http.ResponseWriter, r *http.Request) {
dto := e.Encounter{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
res, err := u.CheckOut(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Cancel(w http.ResponseWriter, r *http.Request) {
dto := e.Encounter{}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
res, err := u.Cancel(dto)
rw.DataResponse(w, res, err)
}
@@ -8,7 +8,8 @@ import (
e "simrs-vx/internal/domain/main-entities/installation"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/installation"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/installation"
)
type myBase struct{}
@@ -8,7 +8,8 @@ import (
e "simrs-vx/internal/domain/main-entities/patient"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/patient"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/patient"
)
type myBase struct{}
@@ -8,7 +8,8 @@ import (
e "simrs-vx/internal/domain/main-entities/specialist"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/specialist"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/specialist"
)
type myBase struct{}
@@ -8,7 +8,7 @@ import (
e "simrs-vx/internal/domain/main-entities/subspecialist"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/subspecialist"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/subspecialist"
)
type myBase struct{}
@@ -8,7 +8,8 @@ import (
e "simrs-vx/internal/domain/main-entities/unit"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/unit"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/unit"
)
type myBase struct{}
@@ -0,0 +1,52 @@
package authentication
import (
"context"
"net/http"
d "github.com/karincake/dodol"
rw "github.com/karincake/risoles"
sc "simrs-vx/internal/lib/sync-credential"
e "simrs-vx/internal/domain/sync-entities/authentication"
is "simrs-vx/internal/infra/sync-cfg"
)
func NewGuardMW(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// check the data format
input := e.CredentialDto{}
if success := sc.CheckCredentialData(&input, r, w); !success {
return
}
// check the validity
if input.Source != is.O.NewSource || input.SecretKey != is.O.NewSecretKey {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil)
return
}
ctx := context.WithValue(r.Context(), e.SyncKey{}, input)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
func OldGuardMW(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// check the data format
input := e.CredentialDto{}
if success := sc.CheckCredentialData(&input, r, w); !success {
return
}
// check the validity
if input.Source != is.O.OldSource || input.SecretKey != is.O.OldSecretKey {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil)
return
}
ctx := context.WithValue(r.Context(), e.SyncKey{}, input)
next.ServeHTTP(w, r.WithContext(ctx))
})
}
@@ -1,31 +1,35 @@
package simgossynchandler
import (
"fmt"
"net/http"
hc "simrs-vx/pkg/handler-crud-helper"
/******************** infra ********************/
gs "simrs-vx/internal/infra/gorm-setting"
simgosdb "simrs-vx/internal/infra/simgos-db"
sync "simrs-vx/internal/infra/sync-consumer-cfg"
/******************** pkg ********************/
cmw "simrs-vx/pkg/cors-manager-mw"
hc "simrs-vx/pkg/handler-crud-helper"
lh "simrs-vx/pkg/lang-helper"
handlerlogger "simrs-vx/pkg/middleware/handler-logger"
zlc "simrs-vx/pkg/zerolog-ctx"
/******************** external ********************/
a "github.com/karincake/apem"
hk "github.com/karincake/hongkue"
/******************** internal ********************/
"simrs-vx/internal/interface/main-handler/home"
division "simrs-vx/internal/interface/simgos-sync-handler/division"
installation "simrs-vx/internal/interface/simgos-sync-handler/installation"
oldPatient "simrs-vx/internal/interface/simgos-sync-handler/old/patient"
patient "simrs-vx/internal/interface/simgos-sync-handler/patient"
specialist "simrs-vx/internal/interface/simgos-sync-handler/specialist"
subspecialist "simrs-vx/internal/interface/simgos-sync-handler/subspecialist"
unit "simrs-vx/internal/interface/simgos-sync-handler/unit"
"simrs-vx/internal/interface/simgos-sync-handler/new/division"
"simrs-vx/internal/interface/simgos-sync-handler/new/encounter"
"simrs-vx/internal/interface/simgos-sync-handler/new/installation"
"simrs-vx/internal/interface/simgos-sync-handler/new/patient"
"simrs-vx/internal/interface/simgos-sync-handler/new/specialist"
"simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist"
"simrs-vx/internal/interface/simgos-sync-handler/new/unit"
oauth "simrs-vx/internal/interface/simgos-sync-handler/old/authentication" // just a reminder, an openauth
)
func SetRoutes() http.Handler {
@@ -33,6 +37,7 @@ func SetRoutes() http.Handler {
a.RegisterExtCall(gs.Adjust)
a.RegisterExtCall(zlc.Adjust)
a.RegisterExtCall(lh.Populate)
a.RegisterExtCall(sync.SetConfig)
a.RegisterExtCall(simgosdb.SetInstance)
r := http.NewServeMux()
@@ -40,18 +45,32 @@ func SetRoutes() http.Handler {
/******************** Main ********************/
r.HandleFunc("/", home.Home)
/******************** Source ******************/
prefix := "/new-to-old"
hc.SyncCrud(r, prefix+"/v1/installation", installation.O)
hc.SyncCrud(r, prefix+"/v1/unit", unit.O)
hc.SyncCrud(r, prefix+"/v1/division", division.O)
hc.SyncCrud(r, prefix+"/v1/specialist", specialist.O)
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)
/******************** SvcToOld ******************/
prefixnew := "/new-to-old"
hc.SyncCrud(r, prefixnew+"/v1/installation", installation.O)
hc.SyncCrud(r, prefixnew+"/v1/unit", unit.O)
hc.SyncCrud(r, prefixnew+"/v1/division", division.O)
hc.SyncCrud(r, prefixnew+"/v1/specialist", specialist.O)
hc.SyncCrud(r, prefixnew+"/v1/subspecialist", subspecialist.O)
hk.GroupRoutes(prefixnew+"/v1/patient", r, hk.MapHandlerFunc{
"POST /": patient.O.Create,
"POST /log": patient.O.CreateLog,
"PATCH /{id}": patient.O.Update,
"DELETE /{id}": patient.O.Delete,
"POST /nomr": patient.O.GenerateNomr,
})
hk.GroupRoutes(prefixnew+"/v1/encounter", r, hk.MapHandlerFunc{
"POST /": encounter.O.Create,
"POST /log": encounter.O.CreateLog,
"PATCH /{id}": encounter.O.Update,
"DELETE /{id}": encounter.O.Delete,
"PATCH /{id}/checkin": encounter.O.Checkin,
"PATCH /{id}/checkout": encounter.O.Checkout,
"PATCH /{id}/cancel": encounter.O.Cancel,
})
/*********** Source old-to-new ****************/
oldPrefix := "/old-to-new"
hc.SyncCrud(r, oldPrefix+"/v1/patient", oldPatient.O)
/******************** SvcToNew ******************/
prefixold := "/old-to-new"
hk.GroupRoutes(prefixold+"/v1/patient", r, oauth.OldGuardMW, hk.MapHandlerFunc{}) // FINISH THIS
return cmw.SetCors(handlerlogger.SetLog(r))
}