change ids into codes for device-order,material-order,mcu-order

This commit is contained in:
dpurbosakti
2025-11-10 16:14:31 +07:00
parent 2f1a857497
commit 42ac3deeb0
17 changed files with 41 additions and 74 deletions
@@ -18,7 +18,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataStatusCode `json:"status_code"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
pa.AuthInfo
}
@@ -32,7 +32,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Status_Code erc.DataStatusCode `json:"status-code"`
Doctor_Id *uint `json:"doctor-id"`
Doctor_Code *string `json:"doctor-code"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
@@ -57,7 +57,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -66,7 +66,7 @@ func (d DeviceOrder) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Status_Code: d.Status_Code,
}
@@ -12,9 +12,8 @@ type DeviceOrder struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -22,6 +21,6 @@ func (d DeviceOrder) IsCompleted() bool {
return d.Status_Code == erc.DSCDone
}
func (d DeviceOrder) IsSameDoctor(doctor_id *uint) bool {
return d.Doctor_Id == doctor_id
func (d DeviceOrder) IsSameDoctor(doctor_code *string) bool {
return d.Doctor_Code == doctor_code
}
@@ -37,7 +37,7 @@ type CreateDto struct {
RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"`
SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub
Infra_Id *uint16 `json:"infra_id"` // for inpatient
Infra_Code *string `json:"infra_code"` // for inpatient
Unit_Code *string `json:"unit_code"`
Specialist_Code *string `json:"specialist_code"`
Subspecialist_Code *string `json:"subspecialist_code"`
@@ -10,7 +10,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.InpatientClassCode `json:"class_code" validate:"maxLength=10"`
Infra_Id *uint16 `json:"infra_id"`
Infra_Code *string `json:"infra_code"`
}
type ReadListDto struct {
@@ -22,7 +22,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Class_Code ere.InpatientClassCode `json:"class-code"`
Infra_Id *uint16 `json:"infra-id"`
Infra_Code *string `json:"infra-code"`
}
type ReadDetailDto struct {
@@ -48,7 +48,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.InpatientClassCode `json:"class_code"`
Infra_Id *uint16 `json:"infra_id"`
Infra_Code *string `json:"infra_code"`
Infra *ei.Infra `json:"infra,omitempty"`
}
@@ -56,7 +56,7 @@ func (d Inpatient) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Class_Code: d.Class_Code,
Infra_Id: d.Infra_Id,
Infra_Code: d.Infra_Code,
Infra: d.Infra,
}
resp.Main = d.Main
@@ -10,7 +10,6 @@ type Inpatient struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.InpatientClassCode `json:"class_code" gorm:"size:10"`
Infra_Id *uint16 `json:"infra_id"`
Infra_Code string `json:"infra_code" gorm:"size:10"`
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"`
Infra_Code *string `json:"infra_code" gorm:"size:10"`
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"`
}
@@ -18,7 +18,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataStatusCode `json:"status_code"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
pa.AuthInfo
}
@@ -56,7 +56,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -65,7 +65,7 @@ func (d MaterialOrder) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Status_Code: d.Status_Code,
}
@@ -12,9 +12,8 @@ type MaterialOrder struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -22,6 +21,6 @@ func (d MaterialOrder) IsCompleted() bool {
return d.Status_Code == erc.DSCDone
}
func (d MaterialOrder) IsSameDoctor(doctor_id *uint) bool {
return d.Doctor_Id == doctor_id
func (d MaterialOrder) IsSameDoctor(doctor_code *string) bool {
return d.Doctor_Code == doctor_code
}
@@ -22,7 +22,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
Number uint8 `json:"number"`
@@ -42,7 +42,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Status_Code erc.DataStatusCode `json:"status-code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor-id"`
Doctor_Code *string `json:"doctor-code"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
Number uint8 `json:"number"`
@@ -79,7 +79,7 @@ type ResponseDto struct {
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
@@ -93,7 +93,7 @@ func (d McuOrder) ToResponse() ResponseDto {
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Status_Code: d.Status_Code,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
SpecimenPickTime: d.SpecimenPickTime,
ExaminationDate: d.ExaminationDate,
@@ -15,9 +15,8 @@ type McuOrder struct {
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
Number uint8 `json:"number"`
@@ -30,6 +29,6 @@ func (d McuOrder) IsCompleted() bool {
return d.Status_Code == erc.DSCDone
}
func (d McuOrder) IsSameDoctor(doctor_id *uint) bool {
return d.Doctor_Id == doctor_id
func (d McuOrder) IsSameDoctor(doctor_code *string) bool {
return d.Doctor_Code == doctor_code
}
@@ -6,7 +6,6 @@ import (
e "simrs-vx/internal/domain/main-entities/device-order"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
@@ -60,11 +59,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if resData, err := CreateData(input, &event, tx); err != nil {
return err
@@ -236,11 +231,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if !data.IsSameDoctor(doctor_id) {
if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "auth-forbidden",
@@ -250,7 +241,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if err := UpdateData(input, data, &event, tx); err != nil {
return err
@@ -21,5 +21,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DeviceOrder) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Doctor_Code = inputSrc.Doctor_Code
}
@@ -787,7 +787,7 @@ func insertdataClassCode(input e.CreateDto, soapiData []es.CreateDto, event *pl.
inpCreate := ei.CreateDto{
Encounter_Id: &input.Id,
Class_Code: subCode,
Infra_Id: input.Infra_Id,
Infra_Code: input.Infra_Code,
}
// create data inpatient
@@ -22,6 +22,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Inpatient) {
data.Encounter_Id = inputSrc.Encounter_Id
data.Class_Code = inputSrc.Class_Code
data.Infra_Code = inputSrc.Infra_Code
}
func CheckClassCode(input *string) (ere.InpatientClassCode, error) {
@@ -6,7 +6,6 @@ import (
e "simrs-vx/internal/domain/main-entities/material-order"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
@@ -56,11 +55,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if resData, err := CreateData(input, &event, tx); err != nil {
return err
@@ -233,12 +228,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if !data.IsSameDoctor(doctor_id) {
if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "auth-forbidden",
@@ -248,7 +238,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if err := UpdateData(input, data, &event, tx); err != nil {
return err
@@ -21,5 +21,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MaterialOrder) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Doctor_Code = inputSrc.Doctor_Code
}
@@ -6,7 +6,6 @@ import (
e "simrs-vx/internal/domain/main-entities/mcu-order"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
@@ -56,11 +55,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if resData, err := CreateData(input, &event, tx); err != nil {
return err
@@ -233,12 +228,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if !data.IsSameDoctor(doctor_id) {
if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "auth-forbidden",
@@ -248,7 +238,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if err := UpdateData(input, data, &event, tx); err != nil {
return err
@@ -21,12 +21,11 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrder) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Doctor_Code = inputSrc.Doctor_Code
data.SpecimenPickTime = inputSrc.SpecimenPickTime
data.ExaminationDate = inputSrc.ExaminationDate
data.Number = inputSrc.Number
data.Temperature = inputSrc.Temperature
data.UrgencyLevel_Code = inputSrc.UrgencyLevel_Code
data.Doctor_Id = inputSrc.Doctor_Id
data.Scope_Code = inputSrc.Scope_Code
}