Merge branch 'dev' of github.com:dikstub-rssa/simrs-be into fix/anything-moko

This commit is contained in:
dpurbosakti
2025-12-10 12:32:24 +07:00
137 changed files with 5214 additions and 1326 deletions
@@ -9,9 +9,12 @@ import (
sp "github.com/karincake/semprit"
sr "github.com/karincake/serabi"
is "simrs-vx/internal/infra/sync-consumer-cfg"
pa "simrs-vx/internal/lib/auth"
m "simrs-vx/internal/domain/main-entities/user"
mf "simrs-vx/internal/domain/main-entities/user-fes"
pa "simrs-vx/internal/lib/auth"
esga "simrs-vx/internal/domain/sync-entities/authentication"
s "simrs-vx/internal/use-case/main-use-case/authentication"
)
@@ -66,12 +69,37 @@ func Logout(w http.ResponseWriter, r *http.Request) {
}
func GuardMW(next http.Handler) http.Handler {
var (
accessDetail *pa.AuthInfo
err error
)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
accessDetail, err := s.ExtractToken(r, s.AccessToken)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
return
// Check if it's from sync
credential := esga.CredentialDto{}
credential.Source = r.Header.Get("X-Sync-Source")
credential.SecretKey = r.Header.Get("X-Sync-SecretKey")
credential.UserName = r.Header.Get("X-Sync-UserName")
if credential.Source != "" || credential.SecretKey != "" || credential.UserName != "" {
// validate secretKey and source
if credential.SecretKey != is.O.SecretKey || credential.Source != is.O.Source {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil)
return
}
accessDetail, err = s.GetAuthInfoByUserName(credential.UserName)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
return
}
} else {
// Normal flow goes here
accessDetail, err = s.ExtractToken(r, s.AccessToken)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil)
return
}
}
ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail)
next.ServeHTTP(w, r.WithContext(ctx))
})
@@ -69,7 +69,7 @@ import (
gs "simrs-vx/internal/infra/gorm-setting"
minio "simrs-vx/internal/infra/minio"
ssdb "simrs-vx/internal/infra/ss-db"
simgossync "simrs-vx/internal/infra/sync-cfg"
sync "simrs-vx/internal/infra/sync-consumer-cfg"
/******************** pkg ********************/
cmw "simrs-vx/pkg/cors-manager-mw"
@@ -154,7 +154,7 @@ func SetRoutes() http.Handler {
a.RegisterExtCall(mh.I.SetClient)
a.RegisterExtCall(ibpjs.SetConfig)
a.RegisterExtCall(validation.RegisterValidation)
a.RegisterExtCall(simgossync.SetConfig)
a.RegisterExtCall(sync.SetConfig)
a.RegisterExtCall(docscfg.ParseCfg)
a.RegisterExtCall(ibpjs.SetConfig)
@@ -68,6 +68,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
dto.AuthInfo = *authInfo
res, err := u.Update(dto)
@@ -81,7 +82,15 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
}
dto := e.DeleteDto{}
authInfo, err := pa.GetAuthInfo(r)
if err != nil {
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
}
dto.Id = uint(id)
dto.AuthInfo = *authInfo
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -47,7 +47,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
@@ -62,7 +62,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
@@ -74,7 +74,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
}
dto := e.DeleteDto{}
dto.Id = uint16(id)
dto.Id = uint(id)
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -7,13 +7,17 @@ import (
ambulatory "simrs-vx/internal/domain/main-entities/ambulatory"
antibioticinuse "simrs-vx/internal/domain/main-entities/antibiotic-in-use"
antibioticsrccategory "simrs-vx/internal/domain/main-entities/antibiotic-src-category"
apmcuorder "simrs-vx/internal/domain/main-entities/ap-mcu-order"
appointment "simrs-vx/internal/domain/main-entities/appointment"
authpartner "simrs-vx/internal/domain/main-entities/auth-partner"
chemo "simrs-vx/internal/domain/main-entities/chemo"
chemoplan "simrs-vx/internal/domain/main-entities/chemo-plan"
chemoprotocol "simrs-vx/internal/domain/main-entities/chemo-protocol"
consultation "simrs-vx/internal/domain/main-entities/consultation"
controlletter "simrs-vx/internal/domain/main-entities/control-letter"
counter "simrs-vx/internal/domain/main-entities/counter"
cpmcuorder "simrs-vx/internal/domain/main-entities/cp-mcu-order"
cpmcuorderitem "simrs-vx/internal/domain/main-entities/cp-mcu-order-item"
deathcause "simrs-vx/internal/domain/main-entities/death-cause"
device "simrs-vx/internal/domain/main-entities/device"
deviceorder "simrs-vx/internal/domain/main-entities/device-order"
@@ -66,6 +70,8 @@ import (
medicinemethod "simrs-vx/internal/domain/main-entities/medicine-method"
medicinemix "simrs-vx/internal/domain/main-entities/medicine-mix"
medicinemixitem "simrs-vx/internal/domain/main-entities/medicine-mix-item"
micromcuorder "simrs-vx/internal/domain/main-entities/micro-mcu-order"
micromcuorderitem "simrs-vx/internal/domain/main-entities/micro-mcu-order-item"
midwife "simrs-vx/internal/domain/main-entities/midwife"
nurse "simrs-vx/internal/domain/main-entities/nurse"
nutritionist "simrs-vx/internal/domain/main-entities/nutritionist"
@@ -87,7 +93,10 @@ import (
procedureroomorderitem "simrs-vx/internal/domain/main-entities/procedure-room-order-item"
proceduresrc "simrs-vx/internal/domain/main-entities/procedure-src"
province "simrs-vx/internal/domain/main-entities/province"
radiologymcuorder "simrs-vx/internal/domain/main-entities/radiology-mcu-order"
radiologymcuorderitem "simrs-vx/internal/domain/main-entities/radiology-mcu-order-item"
regency "simrs-vx/internal/domain/main-entities/regency"
registrator "simrs-vx/internal/domain/main-entities/registrator"
rehab "simrs-vx/internal/domain/main-entities/rehab"
responsibledoctorhist "simrs-vx/internal/domain/main-entities/responsible-doctor-hist"
resume "simrs-vx/internal/domain/main-entities/resume"
@@ -140,6 +149,7 @@ func getMainEntities() []any {
&proceduresrc.ProcedureSrc{},
&employee.Employee{},
&intern.Intern{},
&registrator.Registrator{},
&doctor.Doctor{},
&nurse.Nurse{},
&nutritionist.Nutritionist{},
@@ -200,6 +210,13 @@ func getMainEntities() []any {
&mcuorderitem.McuOrderItem{},
&mcusubsrc.McuSubSrc{},
&mcuordersubitem.McuOrderSubItem{},
&apmcuorder.ApMcuOrder{},
&radiologymcuorder.RadiologyMcuOrder{},
&radiologymcuorderitem.RadiologyMcuOrderItem{},
&cpmcuorder.CpMcuOrder{},
&cpmcuorderitem.CpMcuOrderItem{},
&micromcuorder.MicroMcuOrder{},
&micromcuorderitem.MicroMcuOrderItem{},
&antibioticsrccategory.AntibioticSrcCategory{},
&antibioticinuse.AntibioticInUse{},
&consultation.Consultation{},
@@ -235,5 +252,6 @@ func getMainEntities() []any {
&vclaimreference.VclaimReference{},
&screening.Screening{},
&procedurereport.ProcedureReport{},
&chemoplan.ChemoPlan{},
}
}
@@ -0,0 +1,58 @@
package soapi
import (
"net/http"
rw "github.com/karincake/risoles"
// ua "github.com/karincake/tumpeng/auth/svc"
e "simrs-vx/internal/domain/main-entities/soapi"
esync "simrs-vx/internal/domain/sync-entities/log"
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/soapi"
)
type myBase struct{}
var O myBase
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
dto := e.Soapi{}
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.Soapi{}
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 = uint(id)
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -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))
})
}
@@ -0,0 +1,48 @@
package patient
import (
"net/http"
p "simrs-vx/internal/domain/simgos-entities/m-pasien"
uo "simrs-vx/internal/use-case/simgos-sync-use-case/old/patient"
rw "github.com/karincake/risoles"
)
type myBase struct{}
var O myBase
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
dto := p.MPasienDto{}
if !rw.ValidateStructByIOR(w, r.Body, &dto) {
return
}
// mapping m_patient to patient
patient := dto.ToPatient()
res, err := uo.Create(patient)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
dto := p.MPasienDto{}
if !rw.ValidateStructByIOR(w, r.Body, &dto) {
return
}
patient := dto.ToPatient()
res, err := uo.Update(patient)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
dto := p.MPasienDto{}
if !rw.ValidateStructByIOR(w, r.Body, &dto) {
return
}
patient := dto.ToPatient()
res, err := uo.Delete(patient)
rw.DataResponse(w, res, err)
}
@@ -6,6 +6,7 @@ import (
/******************** infra ********************/
gs "simrs-vx/internal/infra/gorm-setting"
simgosdb "simrs-vx/internal/infra/simgos-db"
sync "simrs-vx/internal/infra/sync-cfg"
/******************** pkg ********************/
cmw "simrs-vx/pkg/cors-manager-mw"
@@ -24,9 +25,14 @@ import (
"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/soapi"
"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"
oldpatient "simrs-vx/internal/interface/simgos-sync-handler/old/patient"
oauth "simrs-vx/internal/interface/simgos-sync-handler/old/authentication" // just a reminder, an openauth
)
func SetRoutes() http.Handler {
@@ -34,6 +40,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()
@@ -67,9 +74,14 @@ func SetRoutes() http.Handler {
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
"PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit,
})
hc.SyncCrud(r, prefixnew+"/v1/soapi", soapi.O)
/******************** SvcToNew ******************/
//prefixold := "/old-to-new"
prefixold := "/old-to-new"
hk.GroupRoutes(prefixold+"/v1/patient", r, oauth.OldGuardMW, hk.MapHandlerFunc{
"POST /": oldpatient.O.Create,
"PATCH /{id}": oldpatient.O.Update,
"DELETE /{id}": oldpatient.O.Delete,
}) // FINISH THIS
return cmw.SetCors(handlerlogger.SetLog(r))
}