on going chemo plan
This commit is contained in:
@@ -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))
|
||||
})
|
||||
|
||||
@@ -2,7 +2,10 @@ package chemo_protocol
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
rw "github.com/karincake/risoles"
|
||||
sf "github.com/karincake/semprit"
|
||||
|
||||
@@ -39,7 +42,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ReadDetailDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
|
||||
dto.Id = uint16(id)
|
||||
dto.Id = uint(id)
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -54,7 +57,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)
|
||||
}
|
||||
@@ -66,7 +69,49 @@ 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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
ambulancetransportrequest "simrs-vx/internal/interface/main-handler/ambulance-transport-req"
|
||||
auth "simrs-vx/internal/interface/main-handler/authentication"
|
||||
chemo "simrs-vx/internal/interface/main-handler/chemo"
|
||||
chemoprotocol "simrs-vx/internal/interface/main-handler/chemo-protocol"
|
||||
consultation "simrs-vx/internal/interface/main-handler/consultation"
|
||||
controlletter "simrs-vx/internal/interface/main-handler/control-letter"
|
||||
counter "simrs-vx/internal/interface/main-handler/counter"
|
||||
@@ -69,7 +68,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"
|
||||
@@ -82,6 +81,7 @@ import (
|
||||
/******************** sources ********************/
|
||||
antibioticsrc "simrs-vx/internal/interface/main-handler/antibiotic-src"
|
||||
antibioticsrccat "simrs-vx/internal/interface/main-handler/antibiotic-src-category"
|
||||
chemoprotocol "simrs-vx/internal/interface/main-handler/chemo-protocol"
|
||||
device "simrs-vx/internal/interface/main-handler/device"
|
||||
diagnosesrc "simrs-vx/internal/interface/main-handler/diagnose-src"
|
||||
division "simrs-vx/internal/interface/main-handler/division"
|
||||
@@ -153,7 +153,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)
|
||||
|
||||
@@ -314,7 +314,15 @@ func SetRoutes() http.Handler {
|
||||
"PATCH /{id}/verify": therapyprotocol.O.Verify,
|
||||
"PATCH /{id}/reject": therapyprotocol.O.Reject,
|
||||
})
|
||||
hc.RegCrud(r, "/v1/chemo-protocol", chemoprotocol.O)
|
||||
hk.GroupRoutes("/v1/chemo-protocol", r, auth.GuardMW, hk.MapHandlerFunc{
|
||||
"GET /": chemoprotocol.O.GetList,
|
||||
"GET /{id}": chemoprotocol.O.GetDetail,
|
||||
"POST /": chemoprotocol.O.Create,
|
||||
"PATCH /{id}": chemoprotocol.O.Update,
|
||||
"DELETE /{id}": chemoprotocol.O.Delete,
|
||||
"PATCH /{id}/verify": chemoprotocol.O.Verify,
|
||||
"PATCH /{id}/reject": chemoprotocol.O.Reject,
|
||||
})
|
||||
hc.RegCrud(r, "/v1/upload-file", uploadfile.O)
|
||||
hc.RegCrud(r, "/v1/encounter-document", encounterdocument.O)
|
||||
hc.RegCrud(r, "/v1/general-consent", generalconsent.O)
|
||||
|
||||
@@ -63,7 +63,15 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
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.Update(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -75,7 +83,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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user