Merge branch 'dev' of https://github.com/dikstub-rssa/simrs-be into feat/encounter-adjustment

# Conflicts:
#	cmd/main-migration/migrations/atlas.sum
This commit is contained in:
vanilia
2025-11-02 18:40:22 +07:00
15 changed files with 59 additions and 35 deletions
@@ -0,0 +1,6 @@
-- Modify "McuOrder" table
ALTER TABLE "public"."McuOrder" ADD COLUMN "Scope_Code" character varying(10) NULL;
-- Create index "idx_McuOrder_Scope_Code" to table: "McuOrder"
CREATE INDEX "idx_McuOrder_Scope_Code" ON "public"."McuOrder" ("Scope_Code");
-- Create index "idx_McuSrcCategory_Scope_Code" to table: "McuSrcCategory"
CREATE INDEX "idx_McuSrcCategory_Scope_Code" ON "public"."McuSrcCategory" ("Scope_Code");
@@ -49,7 +49,8 @@ type FilterDto struct {
McuUrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"mcuUrgencyLevel-code"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Id uint `json:"id"`
Includes string `json:"includes"`
}
type UpdateDto struct {
@@ -8,6 +8,7 @@ import (
ercl "simrs-vx/internal/domain/references/clinical"
erc "simrs-vx/internal/domain/references/common"
ere "simrs-vx/internal/domain/references/encounter"
)
type McuOrder struct {
@@ -22,6 +23,7 @@ type McuOrder struct {
Number uint8 `json:"number"`
Temperature float64 `json:"temperature"`
McuUrgencyLevel_Code ercl.McuUrgencyLevelCode `json:"mcuUrgencyLevel_code" gorm:"not null;size:15"`
Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"index;size:10"`
}
func (d McuOrder) IsCompleted() bool {
@@ -9,5 +9,5 @@ type McuSrcCategory struct {
ecore.SmallMain // adjust this according to the needs
Code string `json:"code" gorm:"unique;size:20"`
Name string `json:"name" gorm:"size:50"`
Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"size:10"`
Scope_Code *ere.CheckupScopeCode `json:"scope_code" gorm:"index;size:10"`
}
+1 -1
View File
@@ -22,7 +22,7 @@ type ReadListDto struct {
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
McuSrcCategory_Code *string `json:"mcuSrcCategory-code"`
McuSrcCategory_Code *string `json:"mcu-src-category-code"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
}
@@ -34,8 +34,9 @@ type FilterDto struct {
Status_Code *erc.DataStatusCode `json:"status-code"`
}
type ReadDetailDto struct {
Id uint `json:"id"`
Encounter_Id *uint `json:"encounter_id"`
Id uint `json:"id"`
Encounter_Id *uint `json:"encounter_id"`
Includes string `json:"includes"`
}
type UpdateDto struct {
@@ -2,6 +2,7 @@ package subspecialist
import (
ecore "simrs-vx/internal/domain/base-entities/core"
es "simrs-vx/internal/domain/main-entities/specialist"
espb "simrs-vx/internal/domain/main-entities/subspecialist-position/base"
)
@@ -48,10 +49,11 @@ type MetaDto struct {
type ResponseDto struct {
ecore.SmallMain
Code string `json:"code"`
Name string `json:"name"`
Specialist_Id *uint16 `json:"specialist_id"`
Subspecialist []espb.Basic `json:"subspecialistPositions,omitempty"`
Code string `json:"code"`
Name string `json:"name"`
Specialist_Id *uint16 `json:"specialist_id"`
Specialist *es.Specialist `json:"specialist,omitempty"`
Subspecialist []espb.Basic `json:"subspecialistPositions,omitempty"`
}
func (d Subspecialist) ToResponse() ResponseDto {
@@ -59,6 +61,7 @@ func (d Subspecialist) ToResponse() ResponseDto {
Code: d.Code,
Name: d.Name,
Specialist_Id: d.Specialist_Id,
Specialist: d.Specialist,
Subspecialist: d.SubspecialistPositions,
}
resp.SmallMain = d.SmallMain
@@ -47,6 +47,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
return
}
dto := e.ReadDetailDto{}
sf.UrlQueryParam(&dto, *r.URL)
dto.Id = uint(id)
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
@@ -5,9 +5,6 @@ import (
"strconv"
e "simrs-vx/internal/domain/main-entities/adime"
ee "simrs-vx/internal/domain/main-entities/employee"
ue "simrs-vx/internal/use-case/main-use-case/employee"
dg "github.com/karincake/apem/db-gorm-pg"
d "github.com/karincake/dodol"
@@ -49,11 +46,13 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
employee, err := ue.ReadDetailData(ee.ReadDetailDto{User_Id: &input.AuthInfo.User_Id}, &event, tx)
if err != nil {
return err
if input.AuthInfo.Employee_Id != nil {
v := uint(*input.AuthInfo.Employee_Id)
input.Employee_Id = &v
} else {
input.Employee_Id = nil
}
input.Employee_Id = &employee.Id
if resData, err := CreateData(input, &event, tx); err != nil {
return err
} else {
@@ -128,6 +128,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) {
// employee position
if employee.Id > 0 && employee.Position_Code != nil {
atClaims["employee_position_code"] = *employee.Position_Code
switch *employee.Position_Code {
case erg.EPCDoc:
doctor := ed.Doctor{}
@@ -314,6 +315,7 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
data.Laborant_Id = checkIntPtrClaims(claims, "laborant_id")
data.Pharmachist_Id = checkIntPtrClaims(claims, "pharmachist_id")
data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code")
data.Employee_Id = checkIntPtrClaims(claims, "employee_id")
return
}
return nil, d.FieldError{Code: "token", Message: "token-invalid"}
@@ -15,9 +15,6 @@ import (
func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.McuOrderItem, error) {
pl.SetLogInfo(event, nil, "started", "DBCreate")
data := e.McuOrderItem{}
setData(&input, &data)
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
@@ -25,6 +22,20 @@ func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.McuOrde
tx = dg.I
}
deletedData := e.McuOrderItem{}
tx.Unscoped().
Where("\"McuOrder_Id\" = ? AND \"McuSrc_Id\" = ?", input.McuOrder_Id, input.McuSrc_Id).
First(&deletedData)
if deletedData.Id != 0 {
if err := tx.Model(e.McuOrderItem{}).Where("Id = ?", deletedData.Id).Update("DeletedAt", nil).Error; err != nil {
return nil, plh.HandleCreateError(input, event, err)
}
return &deletedData, nil
}
data := e.McuOrderItem{}
setData(&input, &data)
if err := tx.Create(&data).Error; err != nil {
return nil, plh.HandleCreateError(input, event, err)
}
@@ -81,7 +81,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
tx = dg.I
}
if err := tx.First(&data, input.Id).Error; err != nil {
if err := tx.Scopes(gh.Preload(input.Includes)).First(&data, input.Id).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr
}
@@ -89,7 +89,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx.First(&data).Error; err != nil {
if err := tx.Scopes(gh.Preload(input.Includes)).First(&data).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr
}
+6 -7
View File
@@ -4,11 +4,8 @@ import (
"errors"
"strconv"
ee "simrs-vx/internal/domain/main-entities/employee"
e "simrs-vx/internal/domain/main-entities/sbar"
ue "simrs-vx/internal/use-case/main-use-case/employee"
dg "github.com/karincake/apem/db-gorm-pg"
d "github.com/karincake/dodol"
@@ -49,11 +46,13 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
employee, err := ue.ReadDetailData(ee.ReadDetailDto{User_Id: &input.AuthInfo.User_Id}, &event, tx)
if err != nil {
return err
if input.AuthInfo.Employee_Id != nil {
v := uint(*input.AuthInfo.Employee_Id)
input.Employee_Id = &v
} else {
input.Employee_Id = nil
}
input.Employee_Id = &employee.Id
if resData, err := CreateData(input, &event, tx); err != nil {
return err
} else {
@@ -4,11 +4,8 @@ import (
"errors"
"strconv"
ee "simrs-vx/internal/domain/main-entities/employee"
e "simrs-vx/internal/domain/main-entities/soapi"
ue "simrs-vx/internal/use-case/main-use-case/employee"
dg "github.com/karincake/apem/db-gorm-pg"
d "github.com/karincake/dodol"
@@ -49,11 +46,13 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
employee, err := ue.ReadDetailData(ee.ReadDetailDto{User_Id: &input.AuthInfo.User_Id}, &event, tx)
if err != nil {
return err
if input.AuthInfo.Employee_Id != nil {
v := uint(*input.AuthInfo.Employee_Id)
input.Employee_Id = &v
} else {
input.Employee_Id = nil
}
input.Employee_Id = &employee.Id
if resData, err := CreateData(input, &event, tx); err != nil {
return err
} else {