From d5d4d663e146c73825da5472a5a4dff7390e1462 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 6 Nov 2025 14:32:55 +0700 Subject: [PATCH 01/22] update entity and conslist --- .../migrations/20251106054706.sql | 6 ++ .../migrations/20251106054849.sql | 2 + cmd/main-migration/migrations/atlas.sum | 6 +- .../domain/main-entities/ambulatory/entity.go | 7 +- .../domain/main-entities/encounter/entity.go | 3 +- .../internal-reference/entity.go | 13 ++-- .../domain/main-entities/rehab/base/entity.go | 17 +++-- .../domain/references/clinical/clinical.go | 48 ++++++------- internal/domain/references/common/common.go | 5 ++ .../domain/references/encounter/encounter.go | 28 ++++---- .../encounter/request-validation.go | 70 +++++++++---------- .../use-case/main-use-case/encounter/case.go | 13 ++-- 12 files changed, 121 insertions(+), 97 deletions(-) create mode 100644 cmd/main-migration/migrations/20251106054706.sql create mode 100644 cmd/main-migration/migrations/20251106054849.sql diff --git a/cmd/main-migration/migrations/20251106054706.sql b/cmd/main-migration/migrations/20251106054706.sql new file mode 100644 index 00000000..dd292709 --- /dev/null +++ b/cmd/main-migration/migrations/20251106054706.sql @@ -0,0 +1,6 @@ +-- Modify "Ambulatory" table +ALTER TABLE "public"."Ambulatory" DROP COLUMN "VisitMode_Code"; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" ADD COLUMN "Status_Code" text NULL; +-- Modify "Rehab" table +ALTER TABLE "public"."Rehab" ADD COLUMN "Parent_Encounter_Id" bigint NULL, ADD COLUMN "ExpiredAt" timestamptz NULL, ADD COLUMN "VisitMode_Code" text NULL, ADD COLUMN "Status_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251106054849.sql b/cmd/main-migration/migrations/20251106054849.sql new file mode 100644 index 00000000..45e5f4e4 --- /dev/null +++ b/cmd/main-migration/migrations/20251106054849.sql @@ -0,0 +1,2 @@ +-- Modify "Rehab" table +ALTER TABLE "public"."Rehab" DROP COLUMN "Doctor_Id"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 40b66b02..4dbe2544 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:drtrRtMhlNYK0c9wV3CUkJvXwWgrD8xGPPJy9wlcvNA= +h1:KxMvALnpFUI2RXpBZgkJ312FeLtrm9L0o+CqgJbm40U= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -68,4 +68,6 @@ h1:drtrRtMhlNYK0c9wV3CUkJvXwWgrD8xGPPJy9wlcvNA= 20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= 20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= 20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= -20251104084135.sql h1:Y4coFrHgDXd/DM8ihEy+qMkOSrO8M4SI4shRCJIiBBA= +20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= +20251106054706.sql h1:a17rQ3uAX09BpVFpAFoY8NM6gfsmYVvgNNZaQuWs6T0= +20251106054849.sql h1:TU0HU+jAfs5225rggWP5TjPgb272vQoeiLvEoGhKRbs= diff --git a/internal/domain/main-entities/ambulatory/entity.go b/internal/domain/main-entities/ambulatory/entity.go index ecf9915e..06754385 100644 --- a/internal/domain/main-entities/ambulatory/entity.go +++ b/internal/domain/main-entities/ambulatory/entity.go @@ -6,8 +6,7 @@ import ( ) type Ambulatory struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Class_Code ere.AmbulatoryClassCode `json:"class_code" gorm:"size:10"` - VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` + ecore.Main // adjust this according to the needs + Encounter_Id *uint `json:"encounter_id"` + Class_Code ere.AmbulatoryClassCode `json:"class_code" gorm:"size:10"` } diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index 5e950def..c53912ab 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -68,7 +68,8 @@ type Encounter struct { Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Emergency *eem.Emergency `json:"emergency,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Inpatient *eip.Inpatient `json:"inpatient,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Rehab *er.Basic `json:"rehab,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Rehab_Adm *er.Basic `json:"rehab_adm,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Rehab_Series *[]er.Basic `json:"rehab_series,omitempty" gorm:"foreignKey:Parent_Encounter_Id;references:Id"` } func (d Encounter) IsDone() bool { diff --git a/internal/domain/main-entities/internal-reference/entity.go b/internal/domain/main-entities/internal-reference/entity.go index 85334449..060b21aa 100644 --- a/internal/domain/main-entities/internal-reference/entity.go +++ b/internal/domain/main-entities/internal-reference/entity.go @@ -1,6 +1,8 @@ package internal_reference import ( + erc "simrs-vx/internal/domain/references/common" + ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" eu "simrs-vx/internal/domain/main-entities/unit" @@ -8,9 +10,10 @@ import ( type InternalReference struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Id *uint16 `json:"unit_id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Status_Code *erc.DataApprovalCode `json:"status_code"` } diff --git a/internal/domain/main-entities/rehab/base/entity.go b/internal/domain/main-entities/rehab/base/entity.go index b1713811..d932a991 100644 --- a/internal/domain/main-entities/rehab/base/entity.go +++ b/internal/domain/main-entities/rehab/base/entity.go @@ -1,16 +1,21 @@ package base import ( + erc "simrs-vx/internal/domain/references/common" + ere "simrs-vx/internal/domain/references/encounter" + "time" + ecore "simrs-vx/internal/domain/base-entities/core" - ed "simrs-vx/internal/domain/main-entities/doctor" ) type Basic struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` - AllocatedVisitCount *int `json:"allocatedVisitCount"` + ecore.Main // adjust this according to the needs + Parent_Encounter_Id *uint `json:"parent_encounter_id"` + Encounter_Id *uint `json:"encounter_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` + ExpiredAt *time.Time `json:"expiredAt"` + VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` + Status_Code *erc.DataStatusCode `json:"status_code"` } func (Basic) TableName() string { diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index 8120adb3..26a1c651 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -2,25 +2,25 @@ package clinical type ( - SubjectCode string - ObjectCode string - AssessmentCode string - PlanCode string - InstructionCode string - HeadToToeCode string - McuUrgencyLevelCode string - SoapiTypeCode string - MedicalAction string - VehicleTypeCode string - GeneralEduCode string - SpecialEduCode string - EduAssessmentCode string - AbilityCode string - WillCode string - MedObstacleCode string - LearnMethodCode string - LangClassCode string - TranslatorSrcCode string + SubjectCode string + ObjectCode string + AssessmentCode string + PlanCode string + InstructionCode string + HeadToToeCode string + McuUrgencyLevelCode string + SoapiTypeCode string + MedicalActionTypeCode string + VehicleTypeCode string + GeneralEduCode string + SpecialEduCode string + EduAssessmentCode string + AbilityCode string + WillCode string + MedObstacleCode string + LearnMethodCode string + LangClassCode string + TranslatorSrcCode string ) const ( @@ -120,11 +120,11 @@ const ( STCProgress SoapiTypeCode = "progress" // CPPT STCDevRecord SoapiTypeCode = "dev-record" // Catatan Perkembangan - MAChemo MedicalAction = "chemo" - MAHemo MedicalAction = "hemo" - MAThalasemia MedicalAction = "thalasemia" - MAEchocardio MedicalAction = "echocardio" - MASpirometry MedicalAction = "spirometry" + MATCChemo MedicalActionTypeCode = "chemo" + MATCHemo MedicalActionTypeCode = "hemo" + MATCThalasemia MedicalActionTypeCode = "thalasemia" + MATCEchocardio MedicalActionTypeCode = "echocardio" + MATCSpirometry MedicalActionTypeCode = "spirometry" VTCAmbulance VehicleTypeCode = "ambulance" // Ambulans VTCTransport VehicleTypeCode = "transport" // Transport diff --git a/internal/domain/references/common/common.go b/internal/domain/references/common/common.go index 9e532b14..2941049c 100644 --- a/internal/domain/references/common/common.go +++ b/internal/domain/references/common/common.go @@ -15,6 +15,7 @@ type ( DataAvailabilityCode string DataVerifiedCode string CrudCode string + DataApprovalCode string ) const ( @@ -96,6 +97,10 @@ const ( CCRead CrudCode = "r" // Read CCUpdate CrudCode = "u" // Update CCDelete CrudCode = "d" // Delete + + DACNew DataApprovalCode = "new" + DACApproved DataApprovalCode = "approved" + DACRejected DataApprovalCode = "rejected" ) func GetDayCodes() map[DayCode]string { diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index 97eae05b..35681689 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -19,6 +19,7 @@ type ( AllPaymentMethodCode string SEPRefTypeCode string VisitModeCode string + PolySwitchCode string ) const ( @@ -32,18 +33,18 @@ const ( QSCCancel QueueStatusCode = "cancel" // Dibatalkan QSCSkip QueueStatusCode = "skip" // Dilewati - DMCHome DischargeMethodCode = "home" // Pulang - DMCHomeReq DischargeMethodCode = "home-request" // Pulang Atas Permintaan Sendiri - DMCConsulBack DischargeMethodCode = "consul-back" // Konsultasi Balik / Lanjutan - DMCConsulPoly DischargeMethodCode = "consul-poly" // Konsultasi Poliklinik Lain - DMCConsulExecutive DischargeMethodCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif - DMCConsulChDay DischargeMethodCode = "consul-ch-day" // Konsultasi Hari Lain - DMCEmergency DischargeMethodCode = "emergency" // Rujuk IGD - DMCEmergencyCovid DischargeMethodCode = "emergency-covid" // Rujuk IGD Covid - DMCInpatient DischargeMethodCode = "inpatient" // Rujuk Rawat Inap - DMCExtRef DischargeMethodCode = "external" // Rujuk Faskes Lain - DMCDeath DischargeMethodCode = "death" // Meninggal - DMCDeathOnArrival DischargeMethodCode = "death-on-arrival" // Meninggal Saat Tiba + DMCHome DischargeMethodCode = "home" // Pulang + DMCHomeReq DischargeMethodCode = "home-request" // Pulang Atas Permintaan Sendiri + DMCConsulBack DischargeMethodCode = "consul-back" // Konsultasi Balik / Lanjutan + //DMCConsulPoly DischargeMethodCode = "consul-poly" // Konsultasi Poliklinik Lain + //DMCConsulExecutive DischargeMethodCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif + DMCConsulChDay DischargeMethodCode = "consul-ch-day" // Konsultasi Hari Lain + DMCEmergency DischargeMethodCode = "emergency" // Rujuk IGD + DMCEmergencyCovid DischargeMethodCode = "emergency-covid" // Rujuk IGD Covid + DMCInpatient DischargeMethodCode = "inpatient" // Rujuk Rawat Inap + DMCExtRef DischargeMethodCode = "external" // Rujuk Faskes Lain + DMCDeath DischargeMethodCode = "death" // Meninggal + DMCDeathOnArrival DischargeMethodCode = "death-on-arrival" // Meninggal Saat Tiba TCAmbulance TransportationCode = "ambulance" // Ambulans TCCar TransportationCode = "car" // Mobil @@ -112,6 +113,9 @@ const ( VMCAdm VisitModeCode = "adm" VMCSeries VisitModeCode = "series" + + PSCConsulPoly PolySwitchCode = "consul-poly" // Konsultasi Poliklinik Lain + PSCConsulExecutive PolySwitchCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif ) func (ec EncounterClassCode) Code() string { diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index 025298fc..0fb49e54 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -1,7 +1,6 @@ package encounter import ( - "fmt" "net/http" e "simrs-vx/internal/domain/main-entities/encounter" ere "simrs-vx/internal/domain/references/encounter" @@ -13,42 +12,41 @@ import ( const dataValidationFail = "data-validation-fail" func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) { - switch *i.Discharge_Method_Code { - case ere.DMCDeath: - if i.DeathCause == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "deathCause required if discharge_method_code is death", - }) - return - } - case ere.DMCConsulPoly, ere.DMCConsulExecutive: - if i.InternalReferences == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code), - }) - return - } - - for _, v := range *i.InternalReferences { - if v.Unit_Id == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "internalReferences.unit_id required", - }) - return - } - - if v.Doctor_Id == nil { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "internalReferences.doctor_id required", - }) - return - } - } + if *i.Discharge_Method_Code == ere.DMCDeath && i.DeathCause == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "deathCause required if discharge_method_code is death", + }) + return } + + //case ere.DMCConsulPoly, ere.DMCConsulExecutive: + // if i.InternalReferences == nil { + // rw.DataResponse(w, nil, d.FieldError{ + // Code: dataValidationFail, + // Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code), + // }) + // return + // } + // + // for _, v := range *i.InternalReferences { + // if v.Unit_Id == nil { + // rw.DataResponse(w, nil, d.FieldError{ + // Code: dataValidationFail, + // Message: "internalReferences.unit_id required", + // }) + // return + // } + // + // if v.Doctor_Id == nil { + // rw.DataResponse(w, nil, d.FieldError{ + // Code: dataValidationFail, + // Message: "internalReferences.doctor_id required", + // }) + // return + // } + // } + return true } diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 829cf86c..89395f83 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -458,19 +458,18 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { return err } - switch *input.Discharge_Method_Code { - case ere.DMCDeath: + if *input.Discharge_Method_Code == ere.DMCDeath { // insert data death-cause if _, err = udc.CreateData(edc.CreateDto{Encounter_Id: &input.Id, Value: input.DeathCause}, &event, tx); err != nil { return err } - case ere.DMCConsulPoly, ere.DMCConsulExecutive: - // bulk insert internal-references - if err = createInternalReferences(input, &event, tx); err != nil { - return err - } } + //// bulk insert internal-references + //if err = createInternalReferences(input, &event, tx); err != nil { + // return err + //} + pl.SetLogInfo(&event, nil, "complete") return nil From d5082d01ede844399fe77c115293218caa7d65c8 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 6 Nov 2025 14:34:44 +0700 Subject: [PATCH 02/22] fix import cycle encounter related --- .../domain/references/clinical/clinical.go | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/internal/domain/references/clinical/clinical.go b/internal/domain/references/clinical/clinical.go index 8120adb3..26a1c651 100644 --- a/internal/domain/references/clinical/clinical.go +++ b/internal/domain/references/clinical/clinical.go @@ -2,25 +2,25 @@ package clinical type ( - SubjectCode string - ObjectCode string - AssessmentCode string - PlanCode string - InstructionCode string - HeadToToeCode string - McuUrgencyLevelCode string - SoapiTypeCode string - MedicalAction string - VehicleTypeCode string - GeneralEduCode string - SpecialEduCode string - EduAssessmentCode string - AbilityCode string - WillCode string - MedObstacleCode string - LearnMethodCode string - LangClassCode string - TranslatorSrcCode string + SubjectCode string + ObjectCode string + AssessmentCode string + PlanCode string + InstructionCode string + HeadToToeCode string + McuUrgencyLevelCode string + SoapiTypeCode string + MedicalActionTypeCode string + VehicleTypeCode string + GeneralEduCode string + SpecialEduCode string + EduAssessmentCode string + AbilityCode string + WillCode string + MedObstacleCode string + LearnMethodCode string + LangClassCode string + TranslatorSrcCode string ) const ( @@ -120,11 +120,11 @@ const ( STCProgress SoapiTypeCode = "progress" // CPPT STCDevRecord SoapiTypeCode = "dev-record" // Catatan Perkembangan - MAChemo MedicalAction = "chemo" - MAHemo MedicalAction = "hemo" - MAThalasemia MedicalAction = "thalasemia" - MAEchocardio MedicalAction = "echocardio" - MASpirometry MedicalAction = "spirometry" + MATCChemo MedicalActionTypeCode = "chemo" + MATCHemo MedicalActionTypeCode = "hemo" + MATCThalasemia MedicalActionTypeCode = "thalasemia" + MATCEchocardio MedicalActionTypeCode = "echocardio" + MATCSpirometry MedicalActionTypeCode = "spirometry" VTCAmbulance VehicleTypeCode = "ambulance" // Ambulans VTCTransport VehicleTypeCode = "transport" // Transport From 686f2fbd51fe174ce1550b42594ef5796879494b Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 6 Nov 2025 15:03:51 +0700 Subject: [PATCH 03/22] not yet finish --- .../domain/main-entities/ambulatory/dto.go | 10 ++-- .../main-entities/internal-reference/dto.go | 28 ++++++---- internal/domain/main-entities/rehab/dto.go | 35 ++++++++---- .../main-use-case/ambulatory/helper.go | 1 - .../use-case/main-use-case/encounter/case.go | 9 +-- .../main-use-case/encounter/helper.go | 56 +++++++++---------- .../use-case/main-use-case/encounter/lib.go | 2 +- .../use-case/main-use-case/rehab/helper.go | 5 +- 8 files changed, 80 insertions(+), 66 deletions(-) diff --git a/internal/domain/main-entities/ambulatory/dto.go b/internal/domain/main-entities/ambulatory/dto.go index f580467a..ec34f37f 100644 --- a/internal/domain/main-entities/ambulatory/dto.go +++ b/internal/domain/main-entities/ambulatory/dto.go @@ -6,9 +6,8 @@ import ( ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"` - VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` + Encounter_Id *uint `json:"encounter_id"` + Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"` } type ReadListDto struct { @@ -50,9 +49,8 @@ type ResponseDto struct { func (d Ambulatory) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Class_Code: d.Class_Code, - VisitMode_Code: d.VisitMode_Code, + Encounter_Id: d.Encounter_Id, + Class_Code: d.Class_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/internal-reference/dto.go b/internal/domain/main-entities/internal-reference/dto.go index 360c3193..c957d60b 100644 --- a/internal/domain/main-entities/internal-reference/dto.go +++ b/internal/domain/main-entities/internal-reference/dto.go @@ -1,15 +1,18 @@ package internal_reference import ( + erc "simrs-vx/internal/domain/references/common" + ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" eu "simrs-vx/internal/domain/main-entities/unit" ) type CreateDto struct { - Encounter_Id *uint `json:"-"` - Unit_Id *uint16 `json:"unit_id"` - Doctor_Id *uint `json:"doctor_Id"` + Encounter_Id *uint `json:"-"` + Unit_Id *uint16 `json:"unit_id"` + Doctor_Id *uint `json:"doctor_Id"` + Status_Code erc.DataApprovalCode `json:"status_code"` } type ReadListDto struct { @@ -19,9 +22,10 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Unit_Id *uint `json:"unit-id"` - Doctor_Id *uint `json:"doctor-id"` + Encounter_Id *uint `json:"encounter-id"` + Unit_Id *uint `json:"unit-id"` + Doctor_Id *uint `json:"doctor-id"` + Status_Code erc.DataApprovalCode `json:"status-code"` } type ReadDetailDto struct { @@ -46,11 +50,12 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Id *uint16 `json:"unit_id"` + Unit *eu.Unit `json:"unit,omitempty"` + Doctor_Id *uint `json:"doctor_id"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + Status_Code *erc.DataApprovalCode `json:"status_code"` } func (d InternalReference) ToResponse() ResponseDto { @@ -60,6 +65,7 @@ func (d InternalReference) ToResponse() ResponseDto { Unit: d.Unit, Doctor_Id: d.Doctor_Id, Doctor: d.Doctor, + Status_Code: d.Status_Code, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/rehab/dto.go b/internal/domain/main-entities/rehab/dto.go index 0cec61d8..9dd16c3e 100644 --- a/internal/domain/main-entities/rehab/dto.go +++ b/internal/domain/main-entities/rehab/dto.go @@ -1,14 +1,20 @@ package rehab import ( + erc "simrs-vx/internal/domain/references/common" + ere "simrs-vx/internal/domain/references/encounter" + ecore "simrs-vx/internal/domain/base-entities/core" - ed "simrs-vx/internal/domain/main-entities/doctor" + "time" ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - AllocatedVisitCount *int `json:"allocatedVisitCount"` + Encounter_Id *uint `json:"encounter_id"` + Parent_Encounter_Id *uint `json:"parent_encounter_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` + ExpiredAt *time.Time `json:"expiredAt"` + VisitMode_Code ere.VisitModeCode `json:"visitMode_code"` + Status_Code erc.DataStatusCode `json:"status_code"` } type ReadListDto struct { @@ -18,8 +24,9 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Encounter_Id *uint `json:"encounter-id"` + Parent_Encounter_Id *uint `json:"parent-encounter-id"` + VisitMode_Code ere.VisitModeCode `json:"visitMode-code"` } type ReadDetailDto struct { @@ -44,18 +51,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` - AllocatedVisitCount *int `json:"allocatedVisitCount"` + Encounter_Id *uint `json:"encounter_id"` + Parent_Encounter_Id *uint `json:"parent_encounter_id"` + AllocatedVisitCount *int `json:"allocatedVisitCount"` + ExpiredAt *time.Time `json:"expiredAt"` + VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` + Status_Code *erc.DataStatusCode `json:"status_code"` } func (d Rehab) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, - Doctor_Id: d.Doctor_Id, - Doctor: d.Doctor, + Parent_Encounter_Id: d.Parent_Encounter_Id, AllocatedVisitCount: d.AllocatedVisitCount, + ExpiredAt: d.ExpiredAt, + VisitMode_Code: d.VisitMode_Code, + Status_Code: d.Status_Code, } resp.Main = d.Main return resp diff --git a/internal/use-case/main-use-case/ambulatory/helper.go b/internal/use-case/main-use-case/ambulatory/helper.go index a8a00e0d..912211c0 100644 --- a/internal/use-case/main-use-case/ambulatory/helper.go +++ b/internal/use-case/main-use-case/ambulatory/helper.go @@ -22,7 +22,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Ambulatory) { data.Encounter_Id = inputSrc.Encounter_Id data.Class_Code = inputSrc.Class_Code - data.VisitMode_Code = inputSrc.VisitMode_Code } func CheckClassCode(input *string) (ere.AmbulatoryClassCode, error) { diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 102b8a1f..ec2ea231 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -128,9 +128,8 @@ func Create(input e.CreateDto) (*d.Data, error) { case ere.ECAmbulatory: subCodeAmbulatory := subCode.(ere.AmbulatoryClassCode) ambCreate := ea.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCodeAmbulatory, - VisitMode_Code: *input.VisitMode_Code, + Encounter_Id: &data.Id, + Class_Code: subCodeAmbulatory, } _, err = ua.CreateData(ambCreate, &event, tx) if err != nil { @@ -153,7 +152,6 @@ func Create(input e.CreateDto) (*d.Data, error) { // create data rehab if _, err = ur.CreateData(er.CreateDto{ Encounter_Id: &data.Id, - Doctor_Id: input.Appointment_Doctor_Id, AllocatedVisitCount: input.AllocatedVisitCount}, &event, tx); err != nil { return err } @@ -441,7 +439,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { } func CheckOut(input e.DischargeDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory"} + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory,Rehab"} var data *e.Encounter var err error @@ -682,7 +680,6 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { if data.Ambulatory.Class_Code == ere.ACCRehab { if err := updateRehabDoctor(er.UpdateDto{CreateDto: er.CreateDto{ Encounter_Id: &data.Id, - Doctor_Id: input.Responsible_Doctor_Id, }}, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 67cef58b..9c522ed6 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -781,31 +781,31 @@ func setDBError(event *pl.Event, err error, ctx any) error { return pl.SetLogError(event, ctx) } -func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { - pl.SetLogInfo(event, "started", "DBUpdate") - - var tx *gorm.DB - if len(dbx) > 0 { - tx = dbx[0] - } else { - tx = dg.I - } - - result := tx. - Model(&er.Rehab{}). - Where("\"Encounter_Id\" = (?)", input.Encounter_Id). - Update("\"Doctor_Id\"", input.Doctor_Id) - - if result.Error != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-update-fail", - Detail: "Database update failed", - Raw: result.Error, - } - return pl.SetLogError(event, input) - } - - pl.SetLogInfo(event, nil, "complete") - return nil -} +//func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { +// pl.SetLogInfo(event, "started", "DBUpdate") +// +// var tx *gorm.DB +// if len(dbx) > 0 { +// tx = dbx[0] +// } else { +// tx = dg.I +// } +// +// result := tx. +// Model(&er.Rehab{}). +// Where("\"Encounter_Id\" = (?)", input.Encounter_Id). +// Update("\"Doctor_Id\"", input.Doctor_Id) +// +// if result.Error != nil { +// event.Status = "failed" +// event.ErrInfo = pl.ErrorInfo{ +// Code: "data-update-fail", +// Detail: "Database update failed", +// Raw: result.Error, +// } +// return pl.SetLogError(event, input) +// } +// +// pl.SetLogInfo(event, nil, "complete") +// return nil +//} diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 0c51a8d6..88c50113 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -292,5 +292,5 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo return e.Encounter{}, false, pl.SetLogError(event, i) } - return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab.AllocatedVisitCount), nil + return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab_Adm.AllocatedVisitCount), nil } diff --git a/internal/use-case/main-use-case/rehab/helper.go b/internal/use-case/main-use-case/rehab/helper.go index 5c06ca0a..c5da08ad 100644 --- a/internal/use-case/main-use-case/rehab/helper.go +++ b/internal/use-case/main-use-case/rehab/helper.go @@ -18,6 +18,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Rehab) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Parent_Encounter_Id = inputSrc.Parent_Encounter_Id data.AllocatedVisitCount = inputSrc.AllocatedVisitCount + data.ExpiredAt = inputSrc.ExpiredAt + data.VisitMode_Code = &inputSrc.VisitMode_Code + data.Status_Code = &inputSrc.Status_Code } From 3e3213da3884ed5f4b2fa287fd60ed3ef0d7acd7 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 6 Nov 2025 15:10:16 +0700 Subject: [PATCH 04/22] rename encounter rehab --- cmd/main-migration/migrations/atlas.sum | 6 +++--- internal/domain/main-entities/encounter/entity.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 4dbe2544..6b18cefe 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:KxMvALnpFUI2RXpBZgkJ312FeLtrm9L0o+CqgJbm40U= +h1:cfOFDnxgOCgOIto2DMofzQkPlSF7P+eTsp8Msr3p8sw= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -69,5 +69,5 @@ h1:KxMvALnpFUI2RXpBZgkJ312FeLtrm9L0o+CqgJbm40U= 20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= 20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= 20251104084135.sql h1:rg+eRE5/5sYWR7z+Xyn0zKw8rr8P/oWxF0xhcNVnNec= -20251106054706.sql h1:a17rQ3uAX09BpVFpAFoY8NM6gfsmYVvgNNZaQuWs6T0= -20251106054849.sql h1:TU0HU+jAfs5225rggWP5TjPgb272vQoeiLvEoGhKRbs= +20251106054706.sql h1:WIUuH4oOWHkMJwo2OFlwQc+jT+B1xwXauw0+wbgVdnI= +20251106054849.sql h1:VJHNZBBzNiibsEwvDp90/h3BLOOLx76Pszpl6e/YqvU= diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index c53912ab..bfd70333 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -68,8 +68,8 @@ type Encounter struct { Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Emergency *eem.Emergency `json:"emergency,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Inpatient *eip.Inpatient `json:"inpatient,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Rehab_Adm *er.Basic `json:"rehab_adm,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Rehab_Series *[]er.Basic `json:"rehab_series,omitempty" gorm:"foreignKey:Parent_Encounter_Id;references:Id"` + Rehab *er.Basic `json:"rehab,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + RehabChildren *[]er.Basic `json:"rehabChildren,omitempty" gorm:"foreignKey:Parent_Encounter_Id;references:Id"` } func (d Encounter) IsDone() bool { From 8d9fe70d41002560da3157da26c06cb5de335aec Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 7 Nov 2025 16:21:03 +0700 Subject: [PATCH 05/22] migration from server --- cmd/main-migration/migrations/atlas.sum | 42 ++++++++++++------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 30f9fd3c..0da32e52 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:6umIsneejLUg0V9wUaB2HuCvEHD+2v/dwbxg+y23+wo= +h1:69CxJYTc7MIeFR2nLQwjoba/TUnw7lIzVApYkI34yss= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,23 +75,23 @@ h1:6umIsneejLUg0V9wUaB2HuCvEHD+2v/dwbxg+y23+wo= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= -20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= -20251107071420.sql h1:Q+e+OqjdiuK/sghDQ5NxjU+u2zYl+vh/eRBlUz9Idhg= -20251107074318.sql h1:VbOWMw2rClEWgMnDSejXPqXkFoQ4odVsHn3/UAEiCYA= -20251107075050.sql h1:ZZaKJEWXIJ94/0/2Gzzz+HXjmebEs5eP8iUIot26/c8= -20251107080604.sql h1:aq+tINa0ULCZlJcUK2jaeGh6rRH4jJz3e2NrK47m0Ec= -20251107081830.sql h1:Bl9kniyLWeMqd3nrvgCgiUpdcJWp8qX1F41JAM1WbiE= -20251107091033.sql h1:ETTCaAHBT6wipXrEGXIepxLMdD2LNzprPAp99+jnW0w= -20251107091209.sql h1:BUI9JlTzZxCdVHsrRbOye7m47AJEvXNhCaCVv/HzILs= -20251107091541.sql h1:/tW2uXv/o0Q2E4lQzlYNgEftvDqjf3c2AQpZ83Vb6zc= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= +20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= +20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= From fcbec59a1767772c331e6f4b186e2301dd0e1760 Mon Sep 17 00:00:00 2001 From: vanilia Date: Sun, 9 Nov 2025 22:25:55 +0700 Subject: [PATCH 06/22] add switch poly and spprove --- .../domain/main-entities/encounter/dto.go | 47 +- .../main-handler/encounter/handler.go | 54 +- .../encounter/request-validation.go | 88 +-- .../interface/main-handler/main-handler.go | 24 +- .../use-case/main-use-case/encounter/case.go | 398 +++++++------ .../main-use-case/encounter/helper.go | 529 ++++++++++++------ .../use-case/main-use-case/encounter/lib.go | 101 +++- .../internal-reference/helper.go | 4 + 8 files changed, 836 insertions(+), 409 deletions(-) diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 6782b18c..966a53d3 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -1,6 +1,13 @@ package encounter import ( + eam "simrs-vx/internal/domain/main-entities/ambulatory" + edc "simrs-vx/internal/domain/main-entities/death-cause" + eem "simrs-vx/internal/domain/main-entities/emergency" + eip "simrs-vx/internal/domain/main-entities/inpatient" + eir "simrs-vx/internal/domain/main-entities/internal-reference" + er "simrs-vx/internal/domain/main-entities/rehab/base" + // std "time" @@ -19,7 +26,6 @@ import ( ea "simrs-vx/internal/domain/main-entities/appointment" ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/employee" - eir "simrs-vx/internal/domain/main-entities/internal-reference" ep "simrs-vx/internal/domain/main-entities/patient" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" @@ -48,8 +54,10 @@ type CreateDto struct { Appointment_Id *uint `json:"appointment_id"` RefTypeCode ere.RefTypeCode `json:"refTypeCode"` NewStatus bool `json:"newStatus"` - VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` // if subClass_Code is rehab - AllocatedVisitCount *int `json:"allocatedVisitCount"` // if subClass_Code is rehab and VisitMode_Code is "adm" + + Id uint `json:"-"` + RecentEncounterAdm *Encounter `json:"-"` // if subClass_Code is rehab + VisitMode_Code ere.VisitModeCode `json:"-"` // if subClass_Code is rehab pa.AuthInfo } @@ -114,7 +122,6 @@ type DischargeDto struct { AdmDischargeEducation *string `json:"admDischargeEducation"` DischargeReason *string `json:"dischargeReason"` DeathCause *string `json:"deathCause"` - InternalReferences *[]eir.CreateDto `json:"internalReferences,omitempty"` } type CheckinDto struct { @@ -125,6 +132,17 @@ type CheckinDto struct { FinishedAt *time.Time `json:"finishedAt"` } +type SwitchUnitDto struct { + Id uint `json:"id"` + PolySwitchCode *ere.PolySwitchCode `json:"polySwitchCode"` + InternalReferences *[]eir.CreateDto `json:"internalReferences" validate:"required"` +} + +type ApproveUnitDto struct { + Id uint `json:"id"` + InternalReferences_Id uint16 `json:"internalReferences_id" validate:"required"` +} + type ResponseDto struct { ecore.Main Patient_Id *uint `json:"patient_id"` @@ -159,6 +177,17 @@ type ResponseDto struct { DischargeReason *string `json:"dischargeReason"` Status_Code erc.DataStatusCode `json:"status_code"` VclaimSep *evs.VclaimSep `json:"vclaimSep,omitempty"` + StartedAt *time.Time `json:"startedAt"` + FinishedAt *time.Time `json:"finishedAt"` + Discharge_Date *time.Time `json:"discharge_date"` + InternalReferences *[]eir.InternalReference `json:"internalReferences,omitempty"` + DeathCause *edc.DeathCause `json:"deathCause,omitempty"` + NewStatus bool `json:"newStatus"` + Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty"` + Emergency *eem.Emergency `json:"emergency,omitempty"` + Inpatient *eip.Inpatient `json:"inpatient,omitempty"` + Rehab *er.Basic `json:"rehab,omitempty"` + RehabChildren *[]er.Basic `json:"rehabChildren,omitempty"` } func (d Encounter) ToResponse() ResponseDto { @@ -195,6 +224,16 @@ func (d Encounter) ToResponse() ResponseDto { DischargeReason: d.DischargeReason, Status_Code: d.Status_Code, VclaimSep: d.VclaimSep, + StartedAt: d.StartedAt, + FinishedAt: d.FinishedAt, + Discharge_Date: d.Discharge_Date, + InternalReferences: d.InternalReferences, + DeathCause: d.DeathCause, + NewStatus: d.NewStatus, + Emergency: d.Emergency, + Inpatient: d.Inpatient, + Rehab: d.Rehab, + RehabChildren: d.RehabChildren, } resp.Main = d.Main return resp diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index b66abe76..22d1d8cf 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -3,18 +3,17 @@ package encounter import ( "net/http" + pa "simrs-vx/internal/lib/auth" + + d "github.com/karincake/dodol" rw "github.com/karincake/risoles" sf "github.com/karincake/semprit" // ua "github.com/karincake/tumpeng/auth/svc" + erc "simrs-vx/internal/domain/references/common" e "simrs-vx/internal/domain/main-entities/encounter" u "simrs-vx/internal/use-case/main-use-case/encounter" - - erc "simrs-vx/internal/domain/references/common" - pa "simrs-vx/internal/lib/auth" - - d "github.com/karincake/dodol" ) type myBase struct{} @@ -31,7 +30,13 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - if valid := validateRequestCreate(w, dto); !valid { + + // validate SubClass + if err := verifyClassCode(dto); err != nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: err.Error(), + }) return } @@ -192,3 +197,40 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) { res, err := u.UpdateStatusCode(dto) rw.DataResponse(w, res, err) } + +func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) { + dto := e.SwitchUnitDto{} + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + + // validate request body + if valid := validateRequestSwitchUnit(w, dto); !valid { + return + } + + dto.Id = uint(id) + res, err := u.RequestSwitchUnit(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) { + dto := e.ApproveUnitDto{} + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { + return + } + + dto.Id = uint(id) + res, err := u.ApproveSwitchUnit(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index d8e0619a..be370074 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -1,9 +1,14 @@ package encounter import ( + "errors" + "fmt" "net/http" e "simrs-vx/internal/domain/main-entities/encounter" ere "simrs-vx/internal/domain/references/encounter" + ua "simrs-vx/internal/use-case/main-use-case/ambulatory" + ue "simrs-vx/internal/use-case/main-use-case/emergency" + ui "simrs-vx/internal/use-case/main-use-case/inpatient" d "github.com/karincake/dodol" rw "github.com/karincake/risoles" @@ -11,6 +16,25 @@ import ( const dataValidationFail = "data-validation-fail" +func verifyClassCode(input e.CreateDto) (err error) { + switch input.Class_Code { + case ere.ECAmbulatory: + _, err = ua.CheckClassCode(input.SubClass_Code) + case ere.ECEmergency: + _, err = ue.CheckClassCode(input.SubClass_Code) + case ere.ECInpatient: + _, err = ui.CheckClassCode(input.SubClass_Code) + default: + return errors.New("invalid encounter class code") + } + + if err != nil { + return + } + + return nil +} + func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) { if *i.Discharge_Method_Code == ere.DMCDeath && i.DeathCause == nil { rw.DataResponse(w, nil, d.FieldError{ @@ -19,34 +43,6 @@ func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid boo }) return } - - //case ere.DMCConsulPoly, ere.DMCConsulExecutive: - // if i.InternalReferences == nil { - // rw.DataResponse(w, nil, d.FieldError{ - // Code: dataValidationFail, - // Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code), - // }) - // return - // } - // - // for _, v := range *i.InternalReferences { - // if v.Unit_Id == nil { - // rw.DataResponse(w, nil, d.FieldError{ - // Code: dataValidationFail, - // Message: "internalReferences.unit_id required", - // }) - // return - // } - // - // if v.Doctor_Id == nil { - // rw.DataResponse(w, nil, d.FieldError{ - // Code: dataValidationFail, - // Message: "internalReferences.doctor_id required", - // }) - // return - // } - // } - return true } @@ -62,18 +58,30 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) return true } -func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) { - switch { - case i.Class_Code == ere.ECAmbulatory: - // field allocatedVisitCount required if ambulatory visitMode_Code is adm - if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRehab && *i.VisitMode_Code == ere.VMCAdm { - if *i.AllocatedVisitCount == 0 { - rw.DataResponse(w, nil, d.FieldError{ - Code: dataValidationFail, - Message: "allocatedVisitCount required", - }) - return - } +func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) { + if i.InternalReferences == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: fmt.Sprintf("internalReferences required"), + }) + return + } + + for _, v := range *i.InternalReferences { + if v.Unit_Id == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "internalReferences.unit_id required", + }) + return + } + + if v.Doctor_Id == nil { + rw.DataResponse(w, nil, d.FieldError{ + Code: dataValidationFail, + Message: "internalReferences.doctor_id required", + }) + return } } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 1c703b64..ee33d4a5 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -144,17 +144,19 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/material-order-item", materialorderitem.O) hk.GroupRoutes("/v1/encounter", r, auth.GuardMW, hk.MapHandlerFunc{ - "GET /": encounter.O.GetList, - "GET /{id}": encounter.O.GetDetail, - "POST /": encounter.O.Create, - "PATCH /{id}": encounter.O.Update, - "DELETE /{id}": encounter.O.Delete, - "PATCH /{id}/check-out": encounter.O.CheckOut, - "PATCH /{id}/check-in": encounter.O.CheckIn, - "PATCH /{id}/proccess": encounter.O.Process, - "PATCH /{id}/cancel": encounter.O.Cancel, - "PATCH /{id}/reject": encounter.O.Reject, - "PATCH /{id}/skip": encounter.O.Skip, + "GET /": encounter.O.GetList, + "GET /{id}": encounter.O.GetDetail, + "POST /": encounter.O.Create, + "PATCH /{id}": encounter.O.Update, + "DELETE /{id}": encounter.O.Delete, + "PATCH /{id}/check-out": encounter.O.CheckOut, + "PATCH /{id}/check-in": encounter.O.CheckIn, + "PATCH /{id}/proccess": encounter.O.Process, + "PATCH /{id}/cancel": encounter.O.Cancel, + "PATCH /{id}/reject": encounter.O.Reject, + "PATCH /{id}/skip": encounter.O.Skip, + "PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit, + "PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit, }) hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{ "GET /": mcuorder.O.GetList, diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index ec2ea231..9798a28b 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -2,7 +2,7 @@ package encounter import ( "errors" - authhelper "simrs-vx/internal/lib/auth" + "fmt" "strconv" "time" @@ -17,28 +17,18 @@ import ( ere "simrs-vx/internal/domain/references/encounter" eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" - ea "simrs-vx/internal/domain/main-entities/ambulatory" - ec "simrs-vx/internal/domain/main-entities/chemo" edc "simrs-vx/internal/domain/main-entities/death-cause" - ed "simrs-vx/internal/domain/main-entities/doctor" - ee "simrs-vx/internal/domain/main-entities/emergency" eem "simrs-vx/internal/domain/main-entities/employee" e "simrs-vx/internal/domain/main-entities/encounter" - ei "simrs-vx/internal/domain/main-entities/inpatient" - er "simrs-vx/internal/domain/main-entities/rehab" + eir "simrs-vx/internal/domain/main-entities/internal-reference" erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" es "simrs-vx/internal/domain/main-entities/soapi" uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist" - ua "simrs-vx/internal/use-case/main-use-case/ambulatory" - uc "simrs-vx/internal/use-case/main-use-case/chemo" udc "simrs-vx/internal/use-case/main-use-case/death-cause" - ud "simrs-vx/internal/use-case/main-use-case/doctor" - ue "simrs-vx/internal/use-case/main-use-case/emergency" uem "simrs-vx/internal/use-case/main-use-case/employee" - ui "simrs-vx/internal/use-case/main-use-case/inpatient" - ur "simrs-vx/internal/use-case/main-use-case/rehab" - us "simrs-vx/internal/use-case/main-use-case/soapi" + uir "simrs-vx/internal/use-case/main-use-case/internal-reference" + urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" ) const source = "encounter" @@ -46,8 +36,11 @@ const source = "encounter" var now = time.Now() func Create(input e.CreateDto) (*d.Data, error) { - data := e.Encounter{} - createSoapi := []es.CreateDto{} + var ( + data e.Encounter + recentSoapiDataforCopy []es.CreateDto + err error + ) event := pl.Event{ Feature: "Create", @@ -57,51 +50,36 @@ func Create(input e.CreateDto) (*d.Data, error) { // Start log pl.SetLogInfo(&event, input, "started", "create") - // validate SubClass - var subCode interface{} - subCode, err := verifyClassCode(input) - if err != nil { - return nil, err - } - - // verify whether the allocated visit count has not exceeded the limit - if input.Class_Code == ere.ECAmbulatory && subCode.(ere.AmbulatoryClassCode) == ere.ACCRehab && - *input.VisitMode_Code == ere.VMCSeries { - - dataEncounter, valid, err := verifyAllocatedVisitCount(input, &event) + // validate rehab bpjs + if input.RefTypeCode == ere.RTCBpjs && input.Class_Code == ere.ECAmbulatory && ere.AmbulatoryClassCode(*input.SubClass_Code) == ere.ACCRehab { + // identify visit mode from latest rehab data + recentRehabData, err := identifyVisitModeCode(input, &event) if err != nil { return nil, err } - if !valid { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "visit-limit-exceeded", - Detail: "Encounter has exceeded the allowed number of visits", - Raw: errors.New("visit count exceeds allowed limit"), + if recentRehabData != nil { + // determine VisitModeCode + input.VisitMode_Code, *input.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input, &event) + if err != nil { + return nil, err } - return nil, pl.SetLogError(&event, input) + } else { + input.VisitMode_Code = ere.VMCAdm } - // get data soapi - createSoapi, err = getSoapiEncounterAdm(dataEncounter, &event) - if err != nil { - return nil, err + // if visitMode_Code is series, then get data soapi for copy + if input.VisitMode_Code == ere.VMCSeries { + // get data soapi + recentSoapiDataforCopy, err = getSoapiEncounterAdm(*input.RecentEncounterAdm, &event) + if err != nil { + return nil, err + } } } // check if patient is new in the hospital - dataPatient, err := ReadList(e.ReadListDto{ - FilterDto: e.FilterDto{Patient_Id: input.Patient_Id}, - AuthInfo: authhelper.AuthInfo{User_Id: input.User_Id}}) - if err != nil { - return nil, err - } - if list, ok := dataPatient.Data.([]e.ResponseDto); ok { - if len(list) < 1 { - input.NewStatus = true - } - } + input.NewStatus, err = identifyPatientStatus(input) err = dg.I.Transaction(func(tx *gorm.DB) error { mwRunner := newMiddlewareRunner(&event, tx) @@ -122,72 +100,18 @@ func Create(input e.CreateDto) (*d.Data, error) { return err } else { data = *resData + input.Id = data.Id } - switch input.Class_Code { - case ere.ECAmbulatory: - subCodeAmbulatory := subCode.(ere.AmbulatoryClassCode) - ambCreate := ea.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCodeAmbulatory, - } - _, err = ua.CreateData(ambCreate, &event, tx) - if err != nil { - return err - } - - if subCodeAmbulatory == ere.ACCChemo { - chemoCreate := ec.CreateDto{ - Encounter_Id: &data.Id, - Status_Code: erc.DVCNew, - SrcUnit_Id: input.Unit_Id, - } - _, err = uc.CreateData(chemoCreate, &event, tx) - if err != nil { - return err - } - } - - if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCAdm { - // create data rehab - if _, err = ur.CreateData(er.CreateDto{ - Encounter_Id: &data.Id, - AllocatedVisitCount: input.AllocatedVisitCount}, &event, tx); err != nil { - return err - } - } else if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCSeries { - // Insert Soapi - if err = us.CreateBulkData(createSoapi, data.Id, &event, tx); err != nil { - return err - } - } - - case ere.ECEmergency: - emerCreate := ee.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCode.(ere.EmergencyClassCode), - } - _, err = ue.CreateData(emerCreate, &event, tx) - if err != nil { - return err - } - case ere.ECInpatient: - inpCreate := ei.CreateDto{ - Encounter_Id: &data.Id, - Class_Code: subCode.(ere.InpatientClassCode), - Infra_Id: input.Infra_Id, - } - _, err = ui.CreateData(inpCreate, &event, tx) - if err != nil { - return err - } - default: - return errors.New("invalid encounter class code") + // insert ambulatory/emergency/inpatient + err = insertdataClassCode(input, recentSoapiDataforCopy, &event, tx) + if err != nil { + return err } // insert adm_employee_hist if _, err := uaeh.CreateData(eaeh.CreateDto{ - Encounter_Id: &data.Main.Id, + Encounter_Id: &data.Id, Employee_Id: data.Adm_Employee_Id, StartedAt: &now}, &event, tx); err != nil { return err @@ -469,10 +393,15 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) { // validate if soapi exist - err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-out") - if err != nil { + if err = getSoapiByTypeCode(data, &event, "check-out"); err != nil { return err } + + // verify and update rehabData if visit count has reached the allowed limit + if err = verifyRehabLimit(data, &event, tx); err != nil { + return err + } + } else { // chemo TBC if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil { @@ -495,27 +424,22 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { } // update finishedAt in latest responsible_doctor_hist - if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, StartedAt: &now}, &event, tx); err != nil { + if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil { return err } // update finishedAt in latest adm_employee_hist - if err = updateLatestAdmEmployeeHist(e.CheckinDto{Id: input.Id, StartedAt: &now}, &event, tx); err != nil { + if err = updateLatestAdmEmployeeHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil { return err } + // insert data death-cause if *input.Discharge_Method_Code == ere.DMCDeath { - // insert data death-cause if _, err = udc.CreateData(edc.CreateDto{Encounter_Id: &input.Id, Value: input.DeathCause}, &event, tx); err != nil { return err } } - //// bulk insert internal-references - //if err = createInternalReferences(input, &event, tx); err != nil { - // return err - //} - pl.SetLogInfo(&event, nil, "complete") return nil @@ -642,13 +566,13 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { // validate if soapi exist if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) { - err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-in") + err = getSoapiByTypeCode(data, &event, "check-in") if err != nil { return err } } - // Insert responsible_doctor_hist if responsible_doctor_id has changed && update latest history + // Upsert responsible_doctor_hist if responsible_doctor_id has changed if data.Responsible_Doctor_Id == nil || *input.Responsible_Doctor_Id != *data.Responsible_Doctor_Id { // upsert responsibleDoctorHist if err = upsertResponsibleDoctorHist(erdh.CreateDto{ @@ -660,7 +584,7 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } } - // Insert adm_employee_hist if adm_employee_id has changed && update latest history + // Upsert adm_employee_hist if adm_employee_id has changed if input.Adm_Employee_Id != nil && *input.Adm_Employee_Id != *data.Adm_Employee_Id { // upsert admEmployeeHist if err = upsertAdmEmployeeHist(eaeh.CreateDto{ @@ -677,14 +601,6 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { return err } - if data.Ambulatory.Class_Code == ere.ACCRehab { - if err := updateRehabDoctor(er.UpdateDto{CreateDto: er.CreateDto{ - Encounter_Id: &data.Id, - }}, &event, tx); err != nil { - return err - } - } - pl.SetLogInfo(&event, nil, "complete") return nil @@ -704,43 +620,205 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { }, nil } -func validateForeignKey(input e.CheckinDto) error { - // validate employee_Id - if input.Adm_Employee_Id != nil { - if _, err := uem.ReadDetail(eem.ReadDetailDto{Id: uint16(*input.Adm_Employee_Id)}); err != nil { +func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"} + var data *e.Encounter + var err error + + event := pl.Event{ + Feature: "RequestSwitchUnit", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "checkOut") + + unitIDs := make(map[uint16]struct{}) + doctorIDs := make(map[uint]struct{}) + for _, ref := range *input.InternalReferences { + if ref.Unit_Id != nil { + unitIDs[*ref.Unit_Id] = struct{}{} + } + if ref.Doctor_Id != nil { + doctorIDs[*ref.Doctor_Id] = struct{}{} + } + } + + // validate unit + if err = validateUnitIds(unitIDs, &event); err != nil { + return nil, err + } + + // validate doctor + if err = validateDoctorIds(doctorIDs, &event); err != nil { + return nil, err + } + + err = dg.I.Transaction(func(tx *gorm.DB) error { + pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail") + if data, err = ReadDetailData(rdDto, &event, tx); err != nil { return err } - } - // validate doctor_id - if input.Responsible_Doctor_Id != nil { - if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Responsible_Doctor_Id)}); err != nil { + //if data.IsDone() { + // event.Status = "failed" + // event.ErrInfo = pl.ErrorInfo{ + // Code: "data-state-mismatch", + // Detail: "encounter is done", + // Raw: errors.New("encounter is done"), + // } + // return pl.SetLogError(&event, input) + //} + + // verify Soapi exist for current responsible doctor + dataSoapi, err := getSoapiByResponsibleDoctor(*data, &event) + if err != nil { return err } + if len(dataSoapi) < 1 { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "missing-soapi", + Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"), + } + return pl.SetLogError(&event, input) + } + + // bulk internal references + if err := uir.CreateBulkData(*input.InternalReferences, input.Id, &event, tx); err != nil { + return err + } + + pl.SetLogInfo(&event, nil, "complete") + return nil + }) + + if err != nil { + return nil, err } - return nil + return &d.Data{ + Meta: d.IS{ + "source": source, + "structure": "single-data", + "status": "requestSwitchUnit", + }, + Data: data.ToResponse(), + }, nil } -func verifyClassCode(input e.CreateDto) (subCode interface{}, err error) { - switch input.Class_Code { - case ere.ECAmbulatory: - subCode, err = ua.CheckClassCode(input.SubClass_Code) - if err != nil { - return nil, err - } - case ere.ECEmergency: - subCode, err = ue.CheckClassCode(input.SubClass_Code) - if err != nil { - return nil, err - } - case ere.ECInpatient: - subCode, err = ui.CheckClassCode(input.SubClass_Code) - if err != nil { - return nil, err - } - default: - return nil, errors.New("invalid encounter class code") +func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { + rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"} + var data *e.Encounter + var err error + + event := pl.Event{ + Feature: "ApproveSwitchUnit", + Source: source, } - return + + // Start log + pl.SetLogInfo(&event, input, "started", "approveSwitchUnit") + + err = dg.I.Transaction(func(tx *gorm.DB) error { + pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail") + if data, err = ReadDetailData(rdDto, &event, tx); err != nil { + return err + } + + // get internal reference + irData, err := uir.ReadDetailData(eir.ReadDetailDto{ + Id: input.InternalReferences_Id, Includes: "Doctor"}, &event, tx) + if err != nil { + return err + } + + if *irData.Status_Code != erc.DACNew { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-state-mismatch", + Detail: "internal references is approve", + Raw: errors.New("internal references is approve"), + } + return pl.SetLogError(&event, input) + } + + //if data.IsDone() { + // event.Status = "failed" + // event.ErrInfo = pl.ErrorInfo{ + // Code: "data-state-mismatch", + // Detail: "encounter is done", + // Raw: errors.New("encounter is done"), + // } + // return pl.SetLogError(&event, input) + //} + + // verify Soapi exist for current responsible doctor + dataSoapi, err := getSoapiByResponsibleDoctor(*data, &event) + if err != nil { + return err + } + if len(dataSoapi) < 1 { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "missing-soapi", + Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"), + } + return pl.SetLogError(&event, input) + } + + // update internal reference + if err = uir.UpdateData(eir.UpdateDto{ + Id: input.InternalReferences_Id, + CreateDto: eir.CreateDto{ + Encounter_Id: &input.Id, + Doctor_Id: irData.Doctor_Id, + Unit_Id: irData.Unit_Id, + Status_Code: erc.DACApproved, + }}, irData, &event, tx); err != nil { + return err + } + + // update encounter + if err = updateEncounterApproveSwitchUnit(*irData, &event, tx); err != nil { + return err + } + + // update latest responsible doctor hist + if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil { + return err + } + + // create responsible doctor based on internal reference data + if _, err = urdh.CreateData(erdh.CreateDto{ + Encounter_Id: &input.Id, + Doctor_Id: irData.Doctor_Id, + StartedAt: &now, + }, &event, tx); err != nil { + return err + } + + // update data response + data.Responsible_Doctor_Id = irData.Doctor_Id + data.Unit = irData.Unit + data.Specialist_Id = irData.Doctor.Specialist_Id + data.Subspecialist_Id = irData.Doctor.Subspecialist_Id + + pl.SetLogInfo(&event, nil, "complete") + return nil + }) + + if err != nil { + return nil, err + } + + return &d.Data{ + Meta: d.IS{ + "source": source, + "structure": "single-data", + "status": "updated", + }, + Data: data.ToResponse(), + }, nil + } diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 9c522ed6..dc825348 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -10,6 +10,8 @@ import ( "strings" "time" + authhelper "simrs-vx/internal/lib/auth" + dg "github.com/karincake/apem/db-gorm-pg" "gorm.io/gorm" @@ -23,9 +25,13 @@ import ( eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist" ea "simrs-vx/internal/domain/main-entities/ambulatory" + ec "simrs-vx/internal/domain/main-entities/chemo" edo "simrs-vx/internal/domain/main-entities/device-order" ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/emergency" + eem "simrs-vx/internal/domain/main-entities/employee" e "simrs-vx/internal/domain/main-entities/encounter" + ei "simrs-vx/internal/domain/main-entities/inpatient" emo "simrs-vx/internal/domain/main-entities/material-order" emco "simrs-vx/internal/domain/main-entities/mcu-order" em "simrs-vx/internal/domain/main-entities/medication" @@ -36,19 +42,26 @@ import ( epi "simrs-vx/internal/domain/main-entities/prescription-item" er "simrs-vx/internal/domain/main-entities/rehab" erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" + es "simrs-vx/internal/domain/main-entities/soapi" eu "simrs-vx/internal/domain/main-entities/unit" // udo "simrs-vx/internal/use-case/main-use-case/device-order" - es "simrs-vx/internal/domain/main-entities/soapi" uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist" - uir "simrs-vx/internal/use-case/main-use-case/internal-reference" + ua "simrs-vx/internal/use-case/main-use-case/ambulatory" + uc "simrs-vx/internal/use-case/main-use-case/chemo" + ud "simrs-vx/internal/use-case/main-use-case/doctor" + ue "simrs-vx/internal/use-case/main-use-case/emergency" + uem "simrs-vx/internal/use-case/main-use-case/employee" + ui "simrs-vx/internal/use-case/main-use-case/inpatient" um "simrs-vx/internal/use-case/main-use-case/medication" umei "simrs-vx/internal/use-case/main-use-case/medication-item" umi "simrs-vx/internal/use-case/main-use-case/medicine-mix" ummi "simrs-vx/internal/use-case/main-use-case/medicine-mix-item" up "simrs-vx/internal/use-case/main-use-case/prescription" upi "simrs-vx/internal/use-case/main-use-case/prescription-item" + ur "simrs-vx/internal/use-case/main-use-case/rehab" urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist" + us "simrs-vx/internal/use-case/main-use-case/soapi" ) func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { @@ -104,6 +117,19 @@ func setDataDischarge(src e.DischargeDto, dst *e.Encounter) { dst.FinishedAt = &now } +func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) { + dst.Status_Code = src.StatusCode +} + +func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) { + if src.Adm_Employee_Id != nil { + dst.Adm_Employee_Id = src.Adm_Employee_Id + } + + dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id + dst.StartedAt = src.StartedAt +} + func checkSoapiByDocExists(encounter_id uint, event *pl.Event, tx *gorm.DB) error { pl.SetLogInfo(event, nil, "started", "checkSoapiByDocExists") var soapies []es.Soapi @@ -335,113 +361,6 @@ func getMcuOrders(encounter_id uint, event *pl.Event, tx *gorm.DB) error { return nil } -func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) { - dst.Status_Code = src.StatusCode -} - -func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) { - if src.Adm_Employee_Id != nil { - dst.Adm_Employee_Id = src.Adm_Employee_Id - } - - dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id - dst.StartedAt = src.StartedAt -} - -func createInternalReferences(input e.DischargeDto, event *pl.Event, tx *gorm.DB) error { - unitIDs := make(map[uint16]struct{}) - doctorIDs := make(map[uint]struct{}) - - for _, ref := range *input.InternalReferences { - if ref.Unit_Id != nil { - unitIDs[*ref.Unit_Id] = struct{}{} - } - if ref.Doctor_Id != nil { - doctorIDs[*ref.Doctor_Id] = struct{}{} - } - } - - // validate unitIds - if len(unitIDs) > 0 { - var ids []uint16 - for id := range unitIDs { - ids = append(ids, id) - } - - units, err := getUnits(ids, event, tx) - if err != nil { - return fmt.Errorf("failed to fetch units: %w", err) - } - if len(units) != len(ids) { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-validation-fail", - Detail: "unit_id not found", - } - return pl.SetLogError(event, nil) - } - } - - // validate doctorIds - if len(doctorIDs) > 0 { - var ids []uint - for id := range doctorIDs { - ids = append(ids, id) - } - - doctors, err := getDoctors(ids, event, tx) - if err != nil { - return fmt.Errorf("failed to fetch doctors: %w", err) - } - if len(doctors) != len(ids) { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-validation-fail", - Detail: "doctor_id not found", - } - return pl.SetLogError(event, nil) - } - } - - if err := uir.CreateBulkData(*input.InternalReferences, input.Id, event, tx); err != nil { - return err - } - - return nil -} - -func getUnits(unitIds []uint16, event *pl.Event, tx *gorm.DB) ([]eu.Unit, error) { - pl.SetLogInfo(event, nil, "started", "getUnits") - var units []eu.Unit - err := tx.Where("\"Id\" IN ?", unitIds).Find(&units).Error - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-get-fail", - Detail: "get units", - Raw: err, - } - return nil, pl.SetLogError(event, nil) - } - return units, nil -} - -func getDoctors(doctorIds []uint, event *pl.Event, tx *gorm.DB) ([]ed.Doctor, error) { - pl.SetLogInfo(event, nil, "started", "getDoctors") - var doctors []ed.Doctor - err := tx.Where("\"Id\" IN ?", doctorIds).Find(&doctors).Error - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "data-get-fail", - Detail: "get doctors", - Raw: err, - } - return nil, pl.SetLogError(event, nil) - } - return doctors, nil -} - func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, nil, "started", "DBCreate") @@ -566,7 +485,7 @@ func updateLatestResponsibleDoctorHist(input e.CheckinDto, event *pl.Event, dbx result := tx. Model(&erdh.ResponsibleDoctorHist{}). Where("\"Id\" = (?)", subQuery). - Update("\"FinishedAt\"", input.StartedAt) + Update("\"FinishedAt\"", input.FinishedAt) if result.Error != nil { event.Status = "failed" @@ -607,7 +526,7 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go result := tx. Model(&eaeh.AdmEmployeeHist{}). Where("\"Id\" = (?)", subQuery). - Update("\"FinishedAt\"", input.StartedAt) + Update("\"FinishedAt\"", input.FinishedAt) if result.Error != nil { event.Status = "failed" @@ -628,9 +547,7 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go return nil } -func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { - var data []es.Soapi - +func getSoapiByResponsibleDoctor(enc e.Encounter, event *pl.Event) (data []es.Soapi, err error) { pl.SetLogInfo(event, enc, "started", "DBReadList") if enc.Responsible_Doctor == nil { @@ -653,21 +570,22 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea if err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ - Raw: err, + Raw: err, + Code: "read-fail", + Detail: "Database read failed", } - - if errors.Is(err, gorm.ErrRecordNotFound) { - event.ErrInfo.Code = "data-not-found" - event.ErrInfo.Detail = "Data not found" - return nil, pl.SetLogError(event, enc) - } - - event.ErrInfo.Code = "read-fail" - event.ErrInfo.Detail = "Database read failed" return nil, pl.SetLogError(event, enc) } pl.SetLogInfo(event, nil, "complete") + return +} + +func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) { + data, err := getSoapiByResponsibleDoctor(enc, event) + if err != nil { + return nil, err + } for _, s := range data { // set data soapi for copy @@ -690,39 +608,46 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea return } -func getSoapiByTypeCode(encounterId uint, dataAmbulatory ea.Ambulatory, event *pl.Event, mode string) (err error) { - pl.SetLogInfo(event, encounterId, "started", "DBReadList") +func getSoapiByTypeCode(encounter *e.Encounter, event *pl.Event, mode string) (err error) { + pl.SetLogInfo(event, encounter, "started", "DBReadList") var ( dataSoapi []es.Soapi + amb = encounter.Ambulatory + rehab = encounter.Rehab ) // Set Query for get data Soapi tx := dg.I. Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). - Where("\"Encounter_Id\" = ?", encounterId). + Where("\"Encounter_Id\" = ?", encounter.Id). Where("\"Employee\".\"Position_Code\" = ?", erg.EPCDoc) // Set Case switch { - case dataAmbulatory.Class_Code == ere.ACCReg: + case amb.Class_Code == ere.ACCReg: tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEEarlyMedic) - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCAdm: tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab}) - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCSeries: tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEarlyRehab) } if err = tx.Find(&dataSoapi).Error; err != nil { - return setDBError(event, err, encounterId) + return setDBError(event, err, encounter) } pl.SetLogInfo(event, nil, "complete") - return validateExistedSoapi(dataSoapi, &dataAmbulatory, event, mode) + return validateExistedSoapi(dataSoapi, encounter, event, mode) } -func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, event *pl.Event, mode string) error { +func validateExistedSoapi(dataSoapi []es.Soapi, dataEncounter *e.Encounter, event *pl.Event, mode string) error { + var ( + amb = dataEncounter.Ambulatory + rehab = dataEncounter.Rehab + ) + typeExist := make(map[ercl.SoapiTypeCode]bool) for _, s := range dataSoapi { typeExist[s.TypeCode] = true @@ -731,11 +656,11 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e required := []ercl.SoapiTypeCode{} switch { - case dataAmbulatory.Class_Code == ere.ACCReg: + case amb.Class_Code == ere.ACCReg: required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic} - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCAdm: required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab} - case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries: + case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCSeries: required = []ercl.SoapiTypeCode{ercl.STCEarlyRehab} } @@ -762,6 +687,231 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e return nil } +func identifyPatientStatus(input e.CreateDto) (isNewPatient bool, err error) { + dataPatient, err := ReadList(e.ReadListDto{ + FilterDto: e.FilterDto{Patient_Id: input.Patient_Id}, + AuthInfo: authhelper.AuthInfo{User_Id: input.User_Id}}) + if err != nil { + return + } + + if list, ok := dataPatient.Data.([]e.ResponseDto); ok { + if len(list) < 1 { + isNewPatient = true + } + } + + return +} + +func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl.Event) (ere.VisitModeCode, e.Encounter, error) { + var ( + visitModeCode ere.VisitModeCode + recentAdmEncounterData e.Encounter + isQuotaValid bool + err error + ) + + switch *recentRehabData.Status_Code { + case erc.DSCProcess: + visitModeCode = ere.VMCSeries + + // verify whether the allocated visit count has not exceeded the limit + recentAdmEncounterData, isQuotaValid, err = verifyAllocatedVisitCount(input, event) + if err != nil { + return "", e.Encounter{}, err + } + + if !isQuotaValid || recentRehabData.ExpiredAt.Before(*pu.GetTimeNow()) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "visit-limit-exceeded", + Detail: "Encounter has exceeded the allowed number of visits or expired", + Raw: errors.New("visit count exceeds allowed limit"), + } + return "", e.Encounter{}, pl.SetLogError(event, input) + } + + case erc.DSCDone: + visitModeCode = ere.VMCAdm + + default: + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "invalid-status", + Detail: fmt.Sprintf("Unknown rehab status: %v", *recentRehabData.Status_Code), + Raw: errors.New("unsupported rehab status"), + } + return "", e.Encounter{}, pl.SetLogError(event, input) + } + + return visitModeCode, recentAdmEncounterData, nil +} + +func insertdataClassCode(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) { + switch input.Class_Code { + case ere.ECAmbulatory: + subCode := ere.AmbulatoryClassCode(*input.SubClass_Code) + ambCreate := ea.CreateDto{ + Encounter_Id: &input.Id, + Class_Code: subCode, + } + + // create data Ambulatory + _, err = ua.CreateData(ambCreate, event, tx) + if err != nil { + return err + } + + // insert chemo/rehab + err = insertDataSubClassAmbulatory(input, soapiData, event, tx) + if err != nil { + return err + } + + case ere.ECEmergency: + subCode := ere.EmergencyClassCode(*input.SubClass_Code) + emerCreate := ee.CreateDto{ + Encounter_Id: &input.Id, + Class_Code: subCode, + } + + // create data emergency + _, err = ue.CreateData(emerCreate, event, tx) + if err != nil { + return err + } + case ere.ECInpatient: + subCode := ere.InpatientClassCode(*input.SubClass_Code) + inpCreate := ei.CreateDto{ + Encounter_Id: &input.Id, + Class_Code: subCode, + Infra_Id: input.Infra_Id, + } + + // create data inpatient + _, err = ui.CreateData(inpCreate, event, tx) + if err != nil { + return err + } + default: + return errors.New("invalid encounter class code") + } + + return +} + +func insertDataSubClassAmbulatory(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) { + subCode := ere.AmbulatoryClassCode(*input.SubClass_Code) + + switch { + case subCode == ere.ACCChemo: + chemoCreate := ec.CreateDto{ + Encounter_Id: &input.Id, + Status_Code: erc.DVCNew, + SrcUnit_Id: input.Unit_Id, + } + + // create data chemo + _, err = uc.CreateData(chemoCreate, event, tx) + if err != nil { + return err + } + + case subCode == ere.ACCRehab: + rehabData := er.CreateDto{ + Encounter_Id: &input.Id, + VisitMode_Code: input.VisitMode_Code, + Status_Code: erc.DSCProcess, + } + + // if visitMode_code is series, then bulk insert soapi + if input.VisitMode_Code == ere.VMCSeries { + rehabData.Parent_Encounter_Id = &input.RecentEncounterAdm.Id + + // Insert Soapi + if err = us.CreateBulkData(soapiData, input.Id, event, tx); err != nil { + return err + } + } + + // create rehab + if _, err = ur.CreateData(rehabData, event, tx); err != nil { + return err + } + } + + return +} + +func verifyRehabLimit(data *e.Encounter, event *pl.Event, tx *gorm.DB) error { + // get data encounter adm + encounterAdmData, _, err := verifyAllocatedVisitCount(e.CreateDto{Patient_Id: data.Patient_Id}, event) + if err != nil { + return err + } + + // Check if the visit count has reached the allowed limit + // Mark rehab status as 'done' if exceeded. + if len(*encounterAdmData.RehabChildren) >= *encounterAdmData.Rehab.AllocatedVisitCount { + err = updateRehabStatus(er.UpdateDto{ + Id: uint16(encounterAdmData.Rehab.Id), + CreateDto: er.CreateDto{Status_Code: erc.DSCDone}}, event, tx) + if err != nil { + return err + } + } + + return nil +} + +func updateRehabStatus(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, "started", "DBUpdate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + result := tx. + Model(&er.Rehab{}). + Where("\"Id\" = (?)", input.Id). + Update("\"Status_Code\"", input.Status_Code) + + if result.Error != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: result.Error, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, nil, "complete") + return nil +} + +func validateForeignKey(input e.CheckinDto) error { + // validate employee_Id + if input.Adm_Employee_Id != nil { + if _, err := uem.ReadDetail(eem.ReadDetailDto{Id: uint16(*input.Adm_Employee_Id)}); err != nil { + return err + } + } + + // validate doctor_id + if input.Responsible_Doctor_Id != nil { + if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Responsible_Doctor_Id)}); err != nil { + return err + } + } + + return nil +} + func setSoapiError(event *pl.Event, detail string) error { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -781,31 +931,82 @@ func setDBError(event *pl.Event, err error, ctx any) error { return pl.SetLogError(event, ctx) } -//func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error { -// pl.SetLogInfo(event, "started", "DBUpdate") -// -// var tx *gorm.DB -// if len(dbx) > 0 { -// tx = dbx[0] -// } else { -// tx = dg.I -// } -// -// result := tx. -// Model(&er.Rehab{}). -// Where("\"Encounter_Id\" = (?)", input.Encounter_Id). -// Update("\"Doctor_Id\"", input.Doctor_Id) -// -// if result.Error != nil { -// event.Status = "failed" -// event.ErrInfo = pl.ErrorInfo{ -// Code: "data-update-fail", -// Detail: "Database update failed", -// Raw: result.Error, -// } -// return pl.SetLogError(event, input) -// } -// -// pl.SetLogInfo(event, nil, "complete") -// return nil -//} +func getUnits(unitIds []uint16, event *pl.Event) ([]eu.Unit, error) { + pl.SetLogInfo(event, nil, "started", "getUnits") + var units []eu.Unit + err := dg.I.Where("\"Id\" IN ?", unitIds).Find(&units).Error + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-get-fail", + Detail: "get units", + Raw: err, + } + return nil, pl.SetLogError(event, nil) + } + return units, nil +} + +func getDoctors(doctorIds []uint, event *pl.Event) ([]ed.Doctor, error) { + pl.SetLogInfo(event, nil, "started", "getDoctors") + var doctors []ed.Doctor + err := dg.I.Where("\"Id\" IN ?", doctorIds).Find(&doctors).Error + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-get-fail", + Detail: "get doctors", + Raw: err, + } + return nil, pl.SetLogError(event, nil) + } + return doctors, nil +} + +func validateUnitIds(unitIDs map[uint16]struct{}, event *pl.Event) error { + if len(unitIDs) > 0 { + var ids []uint16 + for id := range unitIDs { + ids = append(ids, id) + } + + units, err := getUnits(ids, event) + if err != nil { + return fmt.Errorf("failed to fetch units: %w", err) + } + if len(units) != len(ids) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-validation-fail", + Detail: "unit_id not found", + } + return pl.SetLogError(event, nil) + } + } + + return nil +} + +func validateDoctorIds(doctorIDs map[uint]struct{}, event *pl.Event) error { + if len(doctorIDs) > 0 { + var ids []uint + for id := range doctorIDs { + ids = append(ids, id) + } + + doctors, err := getDoctors(ids, event) + if err != nil { + return fmt.Errorf("failed to fetch doctors: %w", err) + } + if len(doctors) != len(ids) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-validation-fail", + Detail: "doctor_id not found", + } + return pl.SetLogError(event, nil) + } + } + + return nil +} diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 88c50113..5f41bf8c 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -3,7 +3,7 @@ package encounter import ( // std "errors" - ere "simrs-vx/internal/domain/references/encounter" + eir "simrs-vx/internal/domain/main-entities/internal-reference" // external dg "github.com/karincake/apem/db-gorm-pg" gh "github.com/karincake/getuk" @@ -13,9 +13,14 @@ import ( pl "simrs-vx/pkg/logger" pu "simrs-vx/pkg/use-case-helper" + ere "simrs-vx/internal/domain/references/encounter" + e "simrs-vx/internal/domain/main-entities/encounter" + er "simrs-vx/internal/domain/main-entities/rehab" ) +const ErrorReadFailed = "Database read failed" + func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encounter, error) { pl.SetLogInfo(event, nil, "started", "DBCreate") @@ -249,20 +254,49 @@ func updateCheckInData(input e.CheckinDto, data *e.Encounter, event *pl.Event, d return nil } +func identifyVisitModeCode(i e.CreateDto, event *pl.Event) (recentRehabData *er.Rehab, err error) { + pl.SetLogInfo(event, nil, "started", "DBGetLatestRehab") + + var ( + tx = dg.I + ) + + err = tx. + Joins("JOIN \"Encounter\" ON \"Encounter\".\"Id\" = \"Rehab\".\"Encounter_Id\""). + Where("\"Encounter\".\"Patient_Id\" = ?", i.Patient_Id). + Order("\"CreatedAt\" DESC"). + First(&recentRehabData).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, nil + } + + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "read-recentRehab-fail", + Detail: ErrorReadFailed, + Raw: err, + } + return nil, pl.SetLogError(event, i) + } + + return +} + func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, bool, error) { pl.SetLogInfo(event, nil, "started", "DBGetRecentEncounterAdm") var ( - tx = dg.I - recentEncounterAdm e.Encounter - countEncounterSeries int64 + tx = dg.I + recentEncounterAdm e.Encounter + valid = true ) err := tx. - Scopes(gh.Preload("Rehab,Responsible_Doctor")). - Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). - Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCAdm). + Scopes(gh.Preload("RehabChildren,Rehab,Responsible_Doctor")). + Joins("JOIN \"Rehab\" ON \"Rehab\".\"Encounter_Id\" = \"Encounter\".\"Id\""). + Where("\"Encounter\".\"Patient_Id\" = ?", i.Patient_Id). + Where("\"Rehab\".\"VisitMode_Code\" = ?", ere.VMCAdm). Order("\"CreatedAt\" DESC"). First(&recentEncounterAdm).Error if err != nil { @@ -275,22 +309,41 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo return e.Encounter{}, false, pl.SetLogError(event, i) } - err = tx. - Model(&e.Encounter{}). - Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\""). - Where("\"Patient_Id\" = ?", i.Patient_Id). - Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCSeries). - Where("\"Encounter\".\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt). - Count(&countEncounterSeries).Error - if err != nil { - event.Status = "failed" - event.ErrInfo = pl.ErrorInfo{ - Code: "read-countEncounter-fail", - Detail: "Database read failed", - Raw: err, - } - return e.Encounter{}, false, pl.SetLogError(event, i) + // validate count rehab children + if recentEncounterAdm.RehabChildren != nil { + valid = len(*recentEncounterAdm.RehabChildren) < *recentEncounterAdm.Rehab.AllocatedVisitCount } - return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab_Adm.AllocatedVisitCount), nil + return recentEncounterAdm, valid, nil +} + +func updateEncounterApproveSwitchUnit(input eir.InternalReference, event *pl.Event, dbx ...*gorm.DB) (err error) { + pl.SetLogInfo(event, nil, "started", "DBCreate") + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx.Model(&e.Encounter{}). + Where("\"Id\" = ?", input.Encounter_Id). + Updates(map[string]interface{}{ + "Responsible_Doctor_Id": input.Doctor_Id, + "Unit_Id": input.Unit_Id, + "Specialist_Id": input.Doctor.Specialist_Id, + "Subspecialist_Id": input.Doctor.Subspecialist_Id, + }).Error; err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "update-fail", + Detail: "Failed to update encounter approve switch unit", + Raw: err, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, input, "complete") + return nil } diff --git a/internal/use-case/main-use-case/internal-reference/helper.go b/internal/use-case/main-use-case/internal-reference/helper.go index dbd92f73..36c28540 100644 --- a/internal/use-case/main-use-case/internal-reference/helper.go +++ b/internal/use-case/main-use-case/internal-reference/helper.go @@ -6,6 +6,7 @@ package internal_reference import ( ir "simrs-vx/internal/domain/main-entities/internal-reference" + erc "simrs-vx/internal/domain/references/common" ) func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReference) { @@ -20,16 +21,19 @@ func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReferenc data.Encounter_Id = inputSrc.Encounter_Id data.Unit_Id = inputSrc.Unit_Id data.Doctor_Id = inputSrc.Doctor_Id + data.Status_Code = &inputSrc.Status_Code } func setBulkData(input []ir.CreateDto, encounterId uint) []ir.InternalReference { var data []ir.InternalReference for _, v := range input { + statusCode := erc.DACNew data = append(data, ir.InternalReference{ Encounter_Id: &encounterId, Unit_Id: v.Unit_Id, Doctor_Id: v.Doctor_Id, + Status_Code: &statusCode, }) } From 49922a6b7213c9365051bf74806084278c118ec8 Mon Sep 17 00:00:00 2001 From: vanilia Date: Sun, 9 Nov 2025 23:12:09 +0700 Subject: [PATCH 07/22] adjustment update rehab in checkout --- internal/use-case/main-use-case/encounter/case.go | 15 ++++++++------- .../use-case/main-use-case/encounter/helper.go | 15 ++++++++------- internal/use-case/main-use-case/encounter/lib.go | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 9798a28b..533b2264 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -52,15 +52,15 @@ func Create(input e.CreateDto) (*d.Data, error) { // validate rehab bpjs if input.RefTypeCode == ere.RTCBpjs && input.Class_Code == ere.ECAmbulatory && ere.AmbulatoryClassCode(*input.SubClass_Code) == ere.ACCRehab { - // identify visit mode from latest rehab data - recentRehabData, err := identifyVisitModeCode(input, &event) + // get latest rehab data + recentRehabData, err := getLatestRehabData(input, &event) if err != nil { return nil, err } if recentRehabData != nil { // determine VisitModeCode - input.VisitMode_Code, *input.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input, &event) + input.VisitMode_Code, input.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input, &event) if err != nil { return nil, err } @@ -397,11 +397,12 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { return err } - // verify and update rehabData if visit count has reached the allowed limit - if err = verifyRehabLimit(data, &event, tx); err != nil { - return err + if data.Ambulatory.Class_Code == ere.ACCRehab { + // verify and update rehabData if visit count has reached the allowed limit + if err = verifyRehabLimit(data, &event, tx); err != nil { + return err + } } - } else { // chemo TBC if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil { diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index dc825348..1d313d5f 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -559,6 +559,7 @@ func getSoapiByResponsibleDoctor(enc e.Encounter, event *pl.Event) (data []es.So } err = dg.I. + Debug(). Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). Where("\"Encounter_Id\" = ?", enc.Id). @@ -704,7 +705,7 @@ func identifyPatientStatus(input e.CreateDto) (isNewPatient bool, err error) { return } -func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl.Event) (ere.VisitModeCode, e.Encounter, error) { +func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl.Event) (ere.VisitModeCode, *e.Encounter, error) { var ( visitModeCode ere.VisitModeCode recentAdmEncounterData e.Encounter @@ -719,7 +720,7 @@ func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl. // verify whether the allocated visit count has not exceeded the limit recentAdmEncounterData, isQuotaValid, err = verifyAllocatedVisitCount(input, event) if err != nil { - return "", e.Encounter{}, err + return "", nil, err } if !isQuotaValid || recentRehabData.ExpiredAt.Before(*pu.GetTimeNow()) { @@ -729,7 +730,7 @@ func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl. Detail: "Encounter has exceeded the allowed number of visits or expired", Raw: errors.New("visit count exceeds allowed limit"), } - return "", e.Encounter{}, pl.SetLogError(event, input) + return "", nil, pl.SetLogError(event, input) } case erc.DSCDone: @@ -742,10 +743,10 @@ func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl. Detail: fmt.Sprintf("Unknown rehab status: %v", *recentRehabData.Status_Code), Raw: errors.New("unsupported rehab status"), } - return "", e.Encounter{}, pl.SetLogError(event, input) + return "", nil, pl.SetLogError(event, input) } - return visitModeCode, recentAdmEncounterData, nil + return visitModeCode, &recentAdmEncounterData, nil } func insertdataClassCode(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) { @@ -852,10 +853,10 @@ func verifyRehabLimit(data *e.Encounter, event *pl.Event, tx *gorm.DB) error { } // Check if the visit count has reached the allowed limit - // Mark rehab status as 'done' if exceeded. + // Mark latest rehab status as 'done' if exceeded. if len(*encounterAdmData.RehabChildren) >= *encounterAdmData.Rehab.AllocatedVisitCount { err = updateRehabStatus(er.UpdateDto{ - Id: uint16(encounterAdmData.Rehab.Id), + Id: uint16(data.Rehab.Id), CreateDto: er.CreateDto{Status_Code: erc.DSCDone}}, event, tx) if err != nil { return err diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 5f41bf8c..373ce7f2 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -254,7 +254,7 @@ func updateCheckInData(input e.CheckinDto, data *e.Encounter, event *pl.Event, d return nil } -func identifyVisitModeCode(i e.CreateDto, event *pl.Event) (recentRehabData *er.Rehab, err error) { +func getLatestRehabData(i e.CreateDto, event *pl.Event) (recentRehabData *er.Rehab, err error) { pl.SetLogInfo(event, nil, "started", "DBGetLatestRehab") var ( From d7c62f62876257b33c4e595f414a6cb8d4f19d0f Mon Sep 17 00:00:00 2001 From: vanilia Date: Mon, 10 Nov 2025 08:01:07 +0700 Subject: [PATCH 08/22] back to 0 --- cmd/main-migration/migrations/20251106054706.sql | 6 ------ cmd/main-migration/migrations/20251106054849.sql | 2 -- 2 files changed, 8 deletions(-) delete mode 100644 cmd/main-migration/migrations/20251106054706.sql delete mode 100644 cmd/main-migration/migrations/20251106054849.sql diff --git a/cmd/main-migration/migrations/20251106054706.sql b/cmd/main-migration/migrations/20251106054706.sql deleted file mode 100644 index dd292709..00000000 --- a/cmd/main-migration/migrations/20251106054706.sql +++ /dev/null @@ -1,6 +0,0 @@ --- Modify "Ambulatory" table -ALTER TABLE "public"."Ambulatory" DROP COLUMN "VisitMode_Code"; --- Modify "InternalReference" table -ALTER TABLE "public"."InternalReference" ADD COLUMN "Status_Code" text NULL; --- Modify "Rehab" table -ALTER TABLE "public"."Rehab" ADD COLUMN "Parent_Encounter_Id" bigint NULL, ADD COLUMN "ExpiredAt" timestamptz NULL, ADD COLUMN "VisitMode_Code" text NULL, ADD COLUMN "Status_Code" text NULL; diff --git a/cmd/main-migration/migrations/20251106054849.sql b/cmd/main-migration/migrations/20251106054849.sql deleted file mode 100644 index 45e5f4e4..00000000 --- a/cmd/main-migration/migrations/20251106054849.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Modify "Rehab" table -ALTER TABLE "public"."Rehab" DROP COLUMN "Doctor_Id"; From 3e5889574cb9dc22334bb04e810fee57adbe1b0e Mon Sep 17 00:00:00 2001 From: vanilia Date: Mon, 10 Nov 2025 08:43:19 +0700 Subject: [PATCH 09/22] delete comment --- .../encounter/request-validation.go | 27 ------------------- .../use-case/main-use-case/encounter/case.go | 5 ---- 2 files changed, 32 deletions(-) diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index 6f448661..ab00a711 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -19,33 +19,6 @@ func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid boo }) return } - - //case ere.DMCConsulPoly, ere.DMCConsulExecutive: - // if i.InternalReferences == nil { - // rw.DataResponse(w, nil, d.FieldError{ - // Code: dataValidationFail, - // Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code), - // }) - // return - // } - // - // for _, v := range *i.InternalReferences { - // if v.Unit_Id == nil { - // rw.DataResponse(w, nil, d.FieldError{ - // Code: dataValidationFail, - // Message: "internalReferences.unit_id required", - // }) - // return - // } - // - // if v.Doctor_Id == nil { - // rw.DataResponse(w, nil, d.FieldError{ - // Code: dataValidationFail, - // Message: "internalReferences.doctor_id required", - // }) - // return - // } - // } return true } diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 63b2832f..96f59a89 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -513,11 +513,6 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { } } - //// bulk insert internal-references - //if err = createInternalReferences(input, &event, tx); err != nil { - // return err - //} - pl.SetLogInfo(&event, nil, "complete") return nil From d564e2e330325e4dc04607e8a601a9bf7e458fc4 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 08:45:42 +0700 Subject: [PATCH 10/22] update hash --- cmd/main-migration/migrations/atlas.sum | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index ca12c2ae..1a259164 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:VjwYayb6y4kUl9K9WTTwmXExlHijchOCRwnUYcRlhRI= +h1:nxld1x0gKb2nqU+0YPNq5FaAhodpZwnaSuBWyZrPO+0= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -95,5 +95,5 @@ h1:VjwYayb6y4kUl9K9WTTwmXExlHijchOCRwnUYcRlhRI= 20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= 20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= 20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= -20251110012217.sql h1:+4ZcAtlZobLY/iTU1hwVEuqCCYtbiDs2N75jTBz1eQM= -20251110012306.sql h1:w3ZvpG2IaS4sZ9WxKcaMAjmy1JhsOPg8zmwjDv4tv7Y= +20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= +20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= From 1c46354206b1b1c3633239a4e2d0fb7793e5bcdb Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 08:50:46 +0700 Subject: [PATCH 11/22] fix (auth): extract code --- .../use-case/main-use-case/authentication/case.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 6cf94142..c162c56c 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -313,12 +313,12 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err data.User_ContractPosition_code = checkStrClaims(claims, "contractPosition_code") data.Employee_Position_Code = checkStrPtrClaims(claims, "employee_position_code") - data.Doctor_Code = checkStrPtrClaims(claims, "doctor_string") - data.Nurse_Code = checkStrPtrClaims(claims, "nurse_string") - data.Midwife_Code = checkStrPtrClaims(claims, "midwife_string") - data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_string") - data.Laborant_Code = checkStrPtrClaims(claims, "laborant_string") - data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_string") + data.Doctor_Code = checkStrPtrClaims(claims, "doctor_code") + data.Nurse_Code = checkStrPtrClaims(claims, "nurse_code") + data.Midwife_Code = checkStrPtrClaims(claims, "midwife_code") + data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_code") + data.Laborant_Code = checkStrPtrClaims(claims, "laborant_code") + data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_code") data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code") data.Employee_Id = checkUntPtrClaims(claims, "employee_id") return From 3c7b35ef04578eb3a119e47c77dfae5b7b8a5422 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 12:29:58 +0700 Subject: [PATCH 12/22] several tables ids into codes --- .../migrations/20251110052049.sql | 14 ++++++++++ cmd/main-migration/migrations/atlas.sum | 3 +- .../main-entities/consultation/entity.go | 16 ++++++----- .../main-entities/control-letter/entity.go | 28 +++++++++++-------- .../domain/main-entities/encounter/entity.go | 4 +++ .../internal-reference/entity.go | 2 ++ .../main-entities/practice-schedule/entity.go | 17 +++++------ .../responsible-doctor-hist/entity.go | 1 + .../main-entities/therapy-protocol/entity.go | 5 ++-- .../use-case/main-use-case/encounter/case.go | 4 +-- .../use-case/main-use-case/encounter/lib.go | 5 ++-- 11 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 cmd/main-migration/migrations/20251110052049.sql diff --git a/cmd/main-migration/migrations/20251110052049.sql b/cmd/main-migration/migrations/20251110052049.sql new file mode 100644 index 00000000..4a1d74d7 --- /dev/null +++ b/cmd/main-migration/migrations/20251110052049.sql @@ -0,0 +1,14 @@ +-- Modify "Consultation" table +ALTER TABLE "public"."Consultation" ADD COLUMN "DstUnit_Code" text NULL, ADD COLUMN "DstDoctor_Code" text NULL; +-- Modify "ControlLetter" table +ALTER TABLE "public"."ControlLetter" ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "Specialist_Code" text NULL, ADD COLUMN "Subspecialist_Code" text NULL, ADD COLUMN "Doctor_Code" text NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "Specialist_Code" text NULL, ADD COLUMN "Subspecialist_Code" text NULL, ADD COLUMN "Appointment_Doctor_Code" text NULL, ADD COLUMN "Responsible_Doctor_Code" text NULL; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "Doctor_Code" text NULL; +-- Modify "PracticeSchedule" table +ALTER TABLE "public"."PracticeSchedule" ADD COLUMN "Doctor_Code" text NULL; +-- Modify "ResponsibleDoctorHist" table +ALTER TABLE "public"."ResponsibleDoctorHist" ADD COLUMN "Doctor_Code" text NULL; +-- Modify "TherapyProtocol" table +ALTER TABLE "public"."TherapyProtocol" ADD COLUMN "Doctor_Code" text NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 1a259164..176a43a0 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:nxld1x0gKb2nqU+0YPNq5FaAhodpZwnaSuBWyZrPO+0= +h1:O5HiMUpKZtVkRc3VxZfFYuLYjUJhPepU5bMnO87FdPI= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -97,3 +97,4 @@ h1:nxld1x0gKb2nqU+0YPNq5FaAhodpZwnaSuBWyZrPO+0= 20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= 20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= 20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= +20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= diff --git a/internal/domain/main-entities/consultation/entity.go b/internal/domain/main-entities/consultation/entity.go index 2fda8bd0..06a44d57 100644 --- a/internal/domain/main-entities/consultation/entity.go +++ b/internal/domain/main-entities/consultation/entity.go @@ -15,11 +15,13 @@ type Consultation struct { Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` Date *time.Time `json:"date"` - Problem *string `json:"case" gorm:"size:10240"` - Solution *string `json:"solution" gorm:"size:10240"` - DstUnit_Id *uint `json:"dstUnit_id"` - DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Id;references:Id"` - DstDoctor_Id *uint `json:"dstDoctor_id"` - DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Id;references:Id"` - RepliedAt *time.Time `json:"repliedAt"` + Problem *string `json:"case" gorm:"size:10240"` + Solution *string `json:"solution" gorm:"size:10240"` + DstUnit_Id *uint `json:"dstUnit_id"` + DstUnit_Code *string `json:"dstUnit_code"` + DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Id;references:Id"` + DstDoctor_Id *uint `json:"dstDoctor_id"` + DstDoctor_Code *string `json:"dstDoctor_code"` + DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Id;references:Id"` + RepliedAt *time.Time `json:"repliedAt"` } diff --git a/internal/domain/main-entities/control-letter/entity.go b/internal/domain/main-entities/control-letter/entity.go index abaf4a72..d0bc0a45 100644 --- a/internal/domain/main-entities/control-letter/entity.go +++ b/internal/domain/main-entities/control-letter/entity.go @@ -12,16 +12,20 @@ import ( ) type ControlLetter struct { - ecore.Main // adjust this according to the needs - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` - Unit_Id *uint `json:"unit_id"` - Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` - Specialist_Id *uint `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` - Subspecialist_Id *uint `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Id;references:Id"` - Date *time.Time `json:"date"` + ecore.Main // adjust this according to the needs + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` + Unit_Id *uint `json:"unit_id"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` + Specialist_Id *uint `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` + Subspecialist_Id *uint `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Id;references:Id"` + Date *time.Time `json:"date"` } diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index bfd70333..d3436c7a 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -32,9 +32,11 @@ type Encounter struct { Unit_Id *uint `json:"unit_id"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` Specialist_Id *uint16 `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` Subspecialist_Id *uint16 `json:"subspecialist_id"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Subspecialist_Code *string `json:"subspecialist_code"` VisitDate time.Time `json:"visitDate"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` @@ -46,10 +48,12 @@ type Encounter struct { Ref_Number *string `json:"refNumber" gorm:"unique;size:20"` Trx_Number *string `json:"trxNumber" gorm:"unique;size:20"` Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` + Appointment_Doctor_Code *string `json:"appointment_doctor_code"` Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Id;references:Id"` Adm_Employee_Id *uint `json:"adm_employee_id"` Adm_Employee *ee.Employee `json:"adm_employee,omitempty" gorm:"foreignKey:Adm_Employee_Id;references:Id"` Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Id;references:Id"` Discharge_Method_Code *ere.DischargeMethodCode `json:"discharge_method_code" gorm:"size:16"` RefSource_Name *string `json:"refSource_name" gorm:"size:100"` diff --git a/internal/domain/main-entities/internal-reference/entity.go b/internal/domain/main-entities/internal-reference/entity.go index 060b21aa..71045b09 100644 --- a/internal/domain/main-entities/internal-reference/entity.go +++ b/internal/domain/main-entities/internal-reference/entity.go @@ -12,8 +12,10 @@ type InternalReference struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_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"` Status_Code *erc.DataApprovalCode `json:"status_code"` } diff --git a/internal/domain/main-entities/practice-schedule/entity.go b/internal/domain/main-entities/practice-schedule/entity.go index 524867c8..213d4495 100644 --- a/internal/domain/main-entities/practice-schedule/entity.go +++ b/internal/domain/main-entities/practice-schedule/entity.go @@ -8,12 +8,13 @@ import ( ) type PracticeSchedule struct { - ecore.Main // adjust this according to the needs - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` - Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime" gorm:"size:5"` - EndTime *string `json:"endTime" gorm:"size:5"` + ecore.Main // adjust this according to the needs + Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime" gorm:"size:5"` + EndTime *string `json:"endTime" gorm:"size:5"` } diff --git a/internal/domain/main-entities/responsible-doctor-hist/entity.go b/internal/domain/main-entities/responsible-doctor-hist/entity.go index c9df2c13..75aa90f6 100644 --- a/internal/domain/main-entities/responsible-doctor-hist/entity.go +++ b/internal/domain/main-entities/responsible-doctor-hist/entity.go @@ -10,6 +10,7 @@ type ResponsibleDoctorHist struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_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"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` diff --git a/internal/domain/main-entities/therapy-protocol/entity.go b/internal/domain/main-entities/therapy-protocol/entity.go index f5ec318a..a91e18eb 100644 --- a/internal/domain/main-entities/therapy-protocol/entity.go +++ b/internal/domain/main-entities/therapy-protocol/entity.go @@ -13,8 +13,9 @@ type TherapyProtocol struct { Encounter_Id *uint `json:"encounter_id" gorm:"not null"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_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"` Anamnesis *string `json:"anamnesis" gorm:"size:2048"` MedicalDiagnoses *string `json:"medicalDiagnoses"` diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 533b2264..e1643d83 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -802,8 +802,8 @@ func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { // update data response data.Responsible_Doctor_Id = irData.Doctor_Id data.Unit = irData.Unit - data.Specialist_Id = irData.Doctor.Specialist_Id - data.Subspecialist_Id = irData.Doctor.Subspecialist_Id + data.Specialist_Code = irData.Doctor.Specialist_Code + data.Subspecialist_Code = irData.Doctor.Subspecialist_Code pl.SetLogInfo(&event, nil, "complete") return nil diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 134f5594..8772a2f4 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -4,6 +4,7 @@ import ( // std "errors" eir "simrs-vx/internal/domain/main-entities/internal-reference" + // external dg "github.com/karincake/apem/db-gorm-pg" gh "github.com/karincake/getuk" @@ -333,8 +334,8 @@ func updateEncounterApproveSwitchUnit(input eir.InternalReference, event *pl.Eve Updates(map[string]interface{}{ "Responsible_Doctor_Id": input.Doctor_Id, "Unit_Id": input.Unit_Id, - "Specialist_Id": input.Doctor.Specialist_Id, - "Subspecialist_Id": input.Doctor.Subspecialist_Id, + "Specialist_Code": input.Doctor.Specialist_Code, + "Subspecialist_Code": input.Doctor.Subspecialist_Code, }).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ From 363467a8cb7facc2e260c4e39ac1d5f57a96e4b8 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 10 Nov 2025 12:39:13 +0700 Subject: [PATCH 13/22] migration from server --- cmd/main-migration/migrations/atlas.sum | 48 ++++++++++++------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 176a43a0..3db34cf7 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:O5HiMUpKZtVkRc3VxZfFYuLYjUJhPepU5bMnO87FdPI= +h1:hb81CPD5BxIB57EVCP5A2oI+LHYxKAQkq+Q7yeGhbiw= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,26 +75,26 @@ h1:O5HiMUpKZtVkRc3VxZfFYuLYjUJhPepU5bMnO87FdPI= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= -20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= -20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= -20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= -20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= -20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= -20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= -20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= -20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= -20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= -20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= -20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= -20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= +20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= +20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= +20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= +20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= +20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= From 6d49dca9253be238e0d9ccb21e7521573ab7b775 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 13:25:00 +0700 Subject: [PATCH 14/22] remove several ids and fix constraint --- .../migrations/20251110062042.sql | 14 ++++ cmd/main-migration/migrations/atlas.sum | 49 ++++++------ .../domain/main-entities/consultation/dto.go | 46 +++++------ .../main-entities/consultation/entity.go | 6 +- .../main-entities/control-letter/dto.go | 76 +++++++++---------- .../main-entities/control-letter/entity.go | 12 +-- internal/domain/main-entities/doctor/dto.go | 7 +- .../domain/main-entities/encounter/dto.go | 76 +++++++++---------- .../domain/main-entities/encounter/entity.go | 14 ++-- .../main-entities/internal-reference/dto.go | 16 ++-- .../internal-reference/entity.go | 6 +- internal/domain/main-entities/nurse/dto.go | 7 +- .../main-entities/practice-schedule/dto.go | 40 +++++----- .../main-entities/practice-schedule/entity.go | 3 +- .../responsible-doctor-hist/dto.go | 8 +- .../responsible-doctor-hist/entity.go | 3 +- .../main-entities/therapy-protocol/dto.go | 10 +-- .../main-entities/therapy-protocol/entity.go | 3 +- .../interface/main-handler/doctor/handler.go | 18 ++--- .../encounter/request-validation.go | 12 +-- .../interface/main-handler/nurse/handler.go | 18 ++--- .../main-use-case/consultation/case.go | 11 +-- .../main-use-case/consultation/helper.go | 2 +- .../main-use-case/control-letter/helper.go | 8 +- .../use-case/main-use-case/doctor/case.go | 4 +- internal/use-case/main-use-case/doctor/lib.go | 2 +- .../use-case/main-use-case/encounter/case.go | 30 ++++---- .../main-use-case/encounter/helper.go | 64 ++++++++-------- .../use-case/main-use-case/encounter/lib.go | 8 +- .../internal-reference/helper.go | 8 +- internal/use-case/main-use-case/nurse/case.go | 4 +- internal/use-case/main-use-case/nurse/lib.go | 2 +- .../main-use-case/practice-schedule/helper.go | 2 +- .../responsible-doctor-hist/helper.go | 2 +- .../main-use-case/therapy-protocol/case.go | 6 +- .../main-use-case/therapy-protocol/helper.go | 2 +- 36 files changed, 294 insertions(+), 305 deletions(-) create mode 100644 cmd/main-migration/migrations/20251110062042.sql diff --git a/cmd/main-migration/migrations/20251110062042.sql b/cmd/main-migration/migrations/20251110062042.sql new file mode 100644 index 00000000..9ec62cf7 --- /dev/null +++ b/cmd/main-migration/migrations/20251110062042.sql @@ -0,0 +1,14 @@ +-- Modify "Consultation" table +ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_DstDoctor", DROP CONSTRAINT "fk_Consultation_DstUnit", DROP COLUMN "DstUnit_Id", DROP COLUMN "DstDoctor_Id", ALTER COLUMN "DstUnit_Code" TYPE character varying(10), ALTER COLUMN "DstDoctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_Consultation_DstDoctor" FOREIGN KEY ("DstDoctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_DstUnit" FOREIGN KEY ("DstUnit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ControlLetter" table +ALTER TABLE "public"."ControlLetter" DROP CONSTRAINT "fk_ControlLetter_Doctor", DROP CONSTRAINT "fk_ControlLetter_Specialist", DROP CONSTRAINT "fk_ControlLetter_Subspecialist", DROP CONSTRAINT "fk_ControlLetter_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", DROP COLUMN "Doctor_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "Specialist_Code" TYPE character varying(10), ALTER COLUMN "Subspecialist_Code" TYPE character varying(10), ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_ControlLetter_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP CONSTRAINT "fk_Encounter_Appointment_Doctor", DROP CONSTRAINT "fk_Encounter_Responsible_Doctor", DROP CONSTRAINT "fk_Encounter_Specialist", DROP CONSTRAINT "fk_Encounter_Subspecialist", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", DROP COLUMN "Responsible_Doctor_Id", DROP COLUMN "Appointment_Doctor_Id", ALTER COLUMN "Specialist_Code" TYPE character varying(10), ALTER COLUMN "Subspecialist_Code" TYPE character varying(10), ALTER COLUMN "Appointment_Doctor_Code" TYPE character varying(20), ALTER COLUMN "Responsible_Doctor_Code" TYPE character varying(20), ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "InsuranceCompany_Code" text NULL, ADD CONSTRAINT "fk_Encounter_Appointment_Doctor" FOREIGN KEY ("Appointment_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Responsible_Doctor" FOREIGN KEY ("Responsible_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Doctor", DROP CONSTRAINT "fk_InternalReference_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Doctor_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_InternalReference_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_InternalReference_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "PracticeSchedule" table +ALTER TABLE "public"."PracticeSchedule" DROP CONSTRAINT "fk_PracticeSchedule_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_PracticeSchedule_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "ResponsibleDoctorHist" table +ALTER TABLE "public"."ResponsibleDoctorHist" DROP CONSTRAINT "fk_ResponsibleDoctorHist_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_ResponsibleDoctorHist_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "TherapyProtocol" table +ALTER TABLE "public"."TherapyProtocol" DROP CONSTRAINT "fk_TherapyProtocol_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_TherapyProtocol_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 3db34cf7..c64990da 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:hb81CPD5BxIB57EVCP5A2oI+LHYxKAQkq+Q7yeGhbiw= +h1:BX21/eygPEF+JaTDfxN/z3+7YAe6EYWa1EK9N2PKhAE= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,26 +75,27 @@ h1:hb81CPD5BxIB57EVCP5A2oI+LHYxKAQkq+Q7yeGhbiw= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= -20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= -20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= -20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= -20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= -20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= -20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= -20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= -20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= -20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= -20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= -20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= +20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= +20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= +20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= +20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= +20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= +20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= +20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= +20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= +20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= +20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= +20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= +20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= +20251110062042.sql h1:yUUNX3EekfedaGTt5Q89a0bgZoCu/kfdXLU4iljN5Xw= diff --git a/internal/domain/main-entities/consultation/dto.go b/internal/domain/main-entities/consultation/dto.go index 33868dd0..1b83df77 100644 --- a/internal/domain/main-entities/consultation/dto.go +++ b/internal/domain/main-entities/consultation/dto.go @@ -20,7 +20,7 @@ type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Date *time.Time `json:"date"` Problem *string `json:"problem" validate:"maxLength=10240"` - DstUnit_Id *uint `json:"dstUnit_id"` + DstUnit_Code *string `json:"dstUnit_code"` } type ReadListDto struct { @@ -30,9 +30,9 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - DstUnit_Id *uint `json:"dstUnit-id"` - DstDoctor_Id *uint `json:"dstDoctor-id"` + Encounter_Id *uint `json:"encounter-id"` + DstUnit_Code *string `json:"dstUnit-code"` + DstDoctor_Code *string `json:"dstDoctor-code"` } type ReadDetailDto struct { @@ -63,29 +63,29 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Date *time.Time `json:"date"` - Problem *string `json:"problem"` - Solution *string `json:"solution"` - DstUnit_Id *uint `json:"dstUnit_id"` - DstUnit *eu.Unit `json:"dstUnit,omitempty"` - DstDoctor_Id *uint `json:"dstDoctor_id"` - DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"` - RepliedAt *time.Time `json:"repliedAt"` + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Date *time.Time `json:"date"` + Problem *string `json:"problem"` + Solution *string `json:"solution"` + DstUnit_Code *string `json:"dstUnit_code"` + DstUnit *eu.Unit `json:"dstUnit,omitempty"` + DstDoctor_Code *string `json:"dstDoctor_code"` + DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"` + RepliedAt *time.Time `json:"repliedAt"` } func (d Consultation) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Date: d.Date, - Problem: d.Problem, - Solution: d.Solution, - DstUnit_Id: d.DstUnit_Id, - DstUnit: d.DstUnit, - DstDoctor_Id: d.DstDoctor_Id, - DstDoctor: d.DstDoctor, + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Date: d.Date, + Problem: d.Problem, + Solution: d.Solution, + DstUnit_Code: d.DstUnit_Code, + DstUnit: d.DstUnit, + DstDoctor_Code: d.DstDoctor_Code, + DstDoctor: d.DstDoctor, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/consultation/entity.go b/internal/domain/main-entities/consultation/entity.go index 06a44d57..b8be3596 100644 --- a/internal/domain/main-entities/consultation/entity.go +++ b/internal/domain/main-entities/consultation/entity.go @@ -17,11 +17,9 @@ type Consultation struct { Problem *string `json:"case" gorm:"size:10240"` Solution *string `json:"solution" gorm:"size:10240"` - DstUnit_Id *uint `json:"dstUnit_id"` DstUnit_Code *string `json:"dstUnit_code"` - DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Id;references:Id"` - DstDoctor_Id *uint `json:"dstDoctor_id"` + DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Code;references:Code"` DstDoctor_Code *string `json:"dstDoctor_code"` - DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Id;references:Id"` + DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Code;references:Code"` RepliedAt *time.Time `json:"repliedAt"` } diff --git a/internal/domain/main-entities/control-letter/dto.go b/internal/domain/main-entities/control-letter/dto.go index c2bab776..87b82366 100644 --- a/internal/domain/main-entities/control-letter/dto.go +++ b/internal/domain/main-entities/control-letter/dto.go @@ -5,7 +5,6 @@ import ( "time" // internal - lib - pa "simrs-vx/internal/lib/auth" // internal - domain - base-entities ecore "simrs-vx/internal/domain/base-entities/core" @@ -20,12 +19,12 @@ import ( ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint `json:"unit_id"` - Specialist_Id *uint `json:"specialist_id"` - Subspecialist_Id *uint `json:"subspecialist_id"` - Doctor_Id *uint `json:"doctor_id"` - Date *time.Time `json:"date"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Doctor_Code *string `json:"doctor_code"` + Date *time.Time `json:"date"` } type ReadListDto struct { @@ -35,12 +34,12 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Unit_Id *uint `json:"unit-id"` - Specialist_Id *uint `json:"specialist-id"` - Subspecialist_Id *uint `json:"subspecialist-id"` - Doctor_Id *uint `json:"doctor-id"` - Date *time.Time `json:"date"` + Encounter_Id *uint `json:"encounter-id"` + Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` + Doctor_Code *string `json:"doctor-code"` + Date *time.Time `json:"date"` } type ReadDetailDto struct { @@ -57,13 +56,6 @@ type DeleteDto struct { Id uint `json:"id"` } -type ReplyDto struct { - Id uint `json:"id"` - Solution *string `json:"solution"` - - pa.AuthInfo -} - type MetaDto struct { PageNumber int `json:"page_number"` PageSize int `json:"page_size"` @@ -72,32 +64,32 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Encounter *ee.Encounter `json:"encounter,omitempty"` - Unit_Id *uint `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Specialist_Id *uint `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` - Doctor_Id *uint `json:"doctor_id"` - Doctor *ed.Doctor `json:"doctor,omitempty"` - Date *time.Time `json:"date"` + Encounter_Id *uint `json:"encounter_id"` + Encounter *ee.Encounter `json:"encounter,omitempty"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + Doctor_Code *string `json:"doctor_code"` + Doctor *ed.Doctor `json:"doctor,omitempty"` + Date *time.Time `json:"date"` } func (d ControlLetter) ToResponse() ResponseDto { resp := ResponseDto{ - Encounter_Id: d.Encounter_Id, - Encounter: d.Encounter, - Unit_Id: d.Unit_Id, - Unit: d.Unit, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, - Doctor_Id: d.Doctor_Id, - Doctor: d.Doctor, - Date: d.Date, + Encounter_Id: d.Encounter_Id, + Encounter: d.Encounter, + Unit_Code: d.Unit_Code, + Unit: d.Unit, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, + Doctor_Code: d.Doctor_Code, + Doctor: d.Doctor, + Date: d.Date, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/control-letter/entity.go b/internal/domain/main-entities/control-letter/entity.go index d0bc0a45..2b8019b4 100644 --- a/internal/domain/main-entities/control-letter/entity.go +++ b/internal/domain/main-entities/control-letter/entity.go @@ -15,17 +15,13 @@ type ControlLetter struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"` - Unit_Id *uint `json:"unit_id"` Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"` - Specialist_Id *uint `json:"specialist_id"` + Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Code;references:Code"` Specialist_Code *string `json:"specialist_code"` - Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"` - Subspecialist_Id *uint `json:"subspecialist_id"` + Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code"` - Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` + Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Code;references:Code"` Doctor_Code *string `json:"doctor_code"` - Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Id;references:Id"` + Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Code;references:Code"` Date *time.Time `json:"date"` } diff --git a/internal/domain/main-entities/doctor/dto.go b/internal/domain/main-entities/doctor/dto.go index 67290551..e3d1f3ee 100644 --- a/internal/domain/main-entities/doctor/dto.go +++ b/internal/domain/main-entities/doctor/dto.go @@ -38,7 +38,7 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` @@ -46,12 +46,13 @@ type ReadDetailDto struct { } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 966a53d3..7ac57b07 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -33,27 +33,27 @@ import ( ) type CreateDto struct { - Patient_Id *uint `json:"patient_id"` - 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 - Unit_Id *uint `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - VisitDate time.Time `json:"visitDate"` - PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` - Member_Number *string `json:"member_number" validate:"maxLength=20"` - Ref_Number *string `json:"ref_number" validate:"maxLength=20"` - Trx_Number *string `json:"trx_number" validate:"maxLength=20"` - Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` - Adm_Employee_Id *uint `json:"-"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` - RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"` - Appointment_Id *uint `json:"appointment_id"` - RefTypeCode ere.RefTypeCode `json:"refTypeCode"` - NewStatus bool `json:"newStatus"` + Patient_Id *uint `json:"patient_id"` + 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 + Unit_Id *uint `json:"unit_id"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + VisitDate time.Time `json:"visitDate"` + PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` + InsuranceCompany_Id *uint `json:"insuranceCompany_id"` + Member_Number *string `json:"member_number" validate:"maxLength=20"` + Ref_Number *string `json:"ref_number" validate:"maxLength=20"` + Trx_Number *string `json:"trx_number" validate:"maxLength=20"` + Appointment_Doctor_Code *string `json:"appointment_doctor_code"` + Adm_Employee_Id *uint `json:"-"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` + RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"` + Appointment_Id *uint `json:"appointment_id"` + RefTypeCode ere.RefTypeCode `json:"refTypeCode"` + NewStatus bool `json:"newStatus"` Id uint `json:"-"` RecentEncounterAdm *Encounter `json:"-"` // if subClass_Code is rehab @@ -76,11 +76,11 @@ type FilterDto struct { RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"` Unit_Id *uint `json:"unit-id"` - Specialist_Id *uint16 `json:"specialist-id"` - Subspecialist_Id *uint16 `json:"subspecialist-id"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` VisitDate time.Time `json:"visitDate"` - Appoinment_Doctor_Id *uint `json:"appointment-doctor-id"` - Responsible_Doctor_Id *uint `json:"responsible-doctor-id"` + Appoinment_Doctor_Code *string `json:"appointment-doctor-code"` + Responsible_Doctor_Code *string `json:"responsible-doctor-code"` DischargeMethod_Code ere.DischargeMethodCode `json:"dischargeMethod-code" validate:"maxLength=10"` RefSource_Name *string `json:"refSource-name" validate:"maxLength=100"` Appointment_Id *uint `json:"appointment-id"` @@ -125,11 +125,11 @@ type DischargeDto struct { } type CheckinDto struct { - Id uint `json:"id"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` - Adm_Employee_Id *uint `json:"adm_employee_id"` - StartedAt *time.Time `json:"startedAt"` - FinishedAt *time.Time `json:"finishedAt"` + Id uint `json:"id"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` + Adm_Employee_Id *uint `json:"adm_employee_id"` + StartedAt *time.Time `json:"startedAt"` + FinishedAt *time.Time `json:"finishedAt"` } type SwitchUnitDto struct { @@ -150,9 +150,9 @@ type ResponseDto struct { RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code"` Unit_Id *uint `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` + Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` Unit *eu.Unit `json:"unit,omitempty"` VisitDate time.Time `json:"visitDate"` @@ -161,9 +161,9 @@ type ResponseDto struct { Member_Number *string `json:"member_number"` Ref_Number *string `json:"ref_number"` Trx_Number *string `json:"trx_number"` - Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` + Appointment_Doctor_Code *string `json:"appointment_doctor_code"` Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` + Responsible_Doctor_Code *string `json:"responsible_doctor_code"` Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty"` Adm_Employee_Id *uint `json:"adm_employee_id"` Adm_Employee *ee.Employee `json:"adm_employee,omitempty"` @@ -198,9 +198,9 @@ func (d Encounter) ToResponse() ResponseDto { Class_Code: d.Class_Code, Unit_Id: d.Unit_Id, Unit: d.Unit, - Specialist_Id: d.Specialist_Id, + Specialist_Code: d.Specialist_Code, Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, + Subspecialist_Code: d.Subspecialist_Code, Subspecialist: d.Subspecialist, VisitDate: d.VisitDate, PaymentMethod_Code: d.PaymentMethod_Code, @@ -208,11 +208,11 @@ func (d Encounter) ToResponse() ResponseDto { Member_Number: d.Member_Number, Ref_Number: d.Ref_Number, Trx_Number: d.Trx_Number, - Appointment_Doctor_Id: d.Appointment_Doctor_Id, + Appointment_Doctor_Code: d.Appointment_Doctor_Code, Appointment_Doctor: d.Appointment_Doctor, Adm_Employee_Id: d.Adm_Employee_Id, Adm_Employee: d.Adm_Employee, - Responsible_Doctor_Id: d.Responsible_Doctor_Id, + Responsible_Doctor_Code: d.Responsible_Doctor_Code, Responsible_Doctor: d.Responsible_Doctor, Discharge_Method_Code: d.Discharge_Method_Code, RefSource_Name: d.RefSource_Name, diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index d3436c7a..e07b2263 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -30,31 +30,29 @@ type Encounter struct { RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code" gorm:"not null;size:10"` Unit_Id *uint `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Specialist_Id *uint16 `json:"specialist_id"` Specialist_Code *string `json:"specialist_code"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` VisitDate time.Time `json:"visitDate"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` InsuranceCompany_Id *uint `json:"insuranceCompany_id"` + InsuranceCompany_Code *string `json:"insuranceCompany_code"` InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"` Member_Number *string `json:"memberNumber" gorm:"unique;size:20"` RefType_Code *ere.RefTypeCode `json:"refType_code"` Ref_Number *string `json:"refNumber" gorm:"unique;size:20"` Trx_Number *string `json:"trxNumber" gorm:"unique;size:20"` - Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` Appointment_Doctor_Code *string `json:"appointment_doctor_code"` - Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Id;references:Id"` + Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Code;references:Code"` Adm_Employee_Id *uint `json:"adm_employee_id"` Adm_Employee *ee.Employee `json:"adm_employee,omitempty" gorm:"foreignKey:Adm_Employee_Id;references:Id"` - Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` Responsible_Doctor_Code *string `json:"responsible_doctor_code"` - Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Id;references:Id"` + Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Code;references:Code"` Discharge_Method_Code *ere.DischargeMethodCode `json:"discharge_method_code" gorm:"size:16"` RefSource_Name *string `json:"refSource_name" gorm:"size:100"` Appointment_Id *uint `json:"appointment_id"` diff --git a/internal/domain/main-entities/internal-reference/dto.go b/internal/domain/main-entities/internal-reference/dto.go index c957d60b..08eaaac2 100644 --- a/internal/domain/main-entities/internal-reference/dto.go +++ b/internal/domain/main-entities/internal-reference/dto.go @@ -10,8 +10,8 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"-"` - Unit_Id *uint16 `json:"unit_id"` - Doctor_Id *uint `json:"doctor_Id"` + Unit_Code *string `json:"unit_code"` + Doctor_Code *string `json:"doctor_code"` Status_Code erc.DataApprovalCode `json:"status_code"` } @@ -23,8 +23,8 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` - Unit_Id *uint `json:"unit-id"` - Doctor_Id *uint `json:"doctor-id"` + Unit_Code *uint `json:"unit-code"` + Doctor_Code *uint `json:"doctor-code"` Status_Code erc.DataApprovalCode `json:"status-code"` } @@ -51,9 +51,9 @@ type MetaDto struct { type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_id"` Unit *eu.Unit `json:"unit,omitempty"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_id"` Doctor *ed.Doctor `json:"doctor,omitempty"` Status_Code *erc.DataApprovalCode `json:"status_code"` } @@ -61,9 +61,9 @@ type ResponseDto struct { func (d InternalReference) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, Status_Code: d.Status_Code, } diff --git a/internal/domain/main-entities/internal-reference/entity.go b/internal/domain/main-entities/internal-reference/entity.go index 71045b09..ae6307bb 100644 --- a/internal/domain/main-entities/internal-reference/entity.go +++ b/internal/domain/main-entities/internal-reference/entity.go @@ -11,11 +11,9 @@ import ( type InternalReference struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` - Unit_Id *uint16 `json:"unit_id"` Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` - Doctor_Id *uint `json:"doctor_id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` 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.DataApprovalCode `json:"status_code"` } diff --git a/internal/domain/main-entities/nurse/dto.go b/internal/domain/main-entities/nurse/dto.go index f48014dd..b0cd6104 100644 --- a/internal/domain/main-entities/nurse/dto.go +++ b/internal/domain/main-entities/nurse/dto.go @@ -29,19 +29,20 @@ type FilterDto struct { Infra_Code *string `json:"infra-code"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Employee_Id *uint `json:"employee_id"` IHS_Number *string `json:"ihs_number"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { diff --git a/internal/domain/main-entities/practice-schedule/dto.go b/internal/domain/main-entities/practice-schedule/dto.go index 00eea2ad..832bc29d 100644 --- a/internal/domain/main-entities/practice-schedule/dto.go +++ b/internal/domain/main-entities/practice-schedule/dto.go @@ -6,11 +6,11 @@ import ( ) type CreateDto struct { - Doctor_Id *uint `json:"doctor_id"` - Unit_Code *string `json:"unit_code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime" validate:"maxLength=5"` - EndTime *string `json:"endTime" validate:"maxLength=5"` + Doctor_Code *string `json:"doctor_code"` + Unit_Code *string `json:"unit_code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime" validate:"maxLength=5"` + EndTime *string `json:"endTime" validate:"maxLength=5"` } type ReadListDto struct { @@ -20,11 +20,11 @@ type ReadListDto struct { } type FilterDto struct { - Doctor_Id *uint `json:"doctor-id"` - Unit_Code *string `json:"unit-code"` - Day_Code *erc.DayCode `json:"day-code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Doctor_Code *string `json:"doctor-code"` + Unit_Code *string `json:"unit-code"` + Day_Code *erc.DayCode `json:"day-code"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` } type ReadDetailDto struct { @@ -48,20 +48,20 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Doctor_Id *uint `json:"doctor_id"` - Unit_Code *string `json:"unit_code"` - Day_Code *erc.DayCode `json:"day_code"` - StartTime *string `json:"startTime"` - EndTime *string `json:"endTime"` + Doctor_Code *string `json:"doctor_code"` + Unit_Code *string `json:"unit_code"` + Day_Code *erc.DayCode `json:"day_code"` + StartTime *string `json:"startTime"` + EndTime *string `json:"endTime"` } func (d PracticeSchedule) ToResponse() ResponseDto { resp := ResponseDto{ - Doctor_Id: d.Doctor_Id, - Unit_Code: d.Unit_Code, - Day_Code: d.Day_Code, - StartTime: d.StartTime, - EndTime: d.EndTime, + Doctor_Code: d.Doctor_Code, + Unit_Code: d.Unit_Code, + Day_Code: d.Day_Code, + StartTime: d.StartTime, + EndTime: d.EndTime, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/practice-schedule/entity.go b/internal/domain/main-entities/practice-schedule/entity.go index 213d4495..84ea3296 100644 --- a/internal/domain/main-entities/practice-schedule/entity.go +++ b/internal/domain/main-entities/practice-schedule/entity.go @@ -9,9 +9,8 @@ import ( type PracticeSchedule struct { ecore.Main // adjust this according to the needs - 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"` Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Day_Code *erc.DayCode `json:"day_code"` diff --git a/internal/domain/main-entities/responsible-doctor-hist/dto.go b/internal/domain/main-entities/responsible-doctor-hist/dto.go index 68c8dd21..c96c588c 100644 --- a/internal/domain/main-entities/responsible-doctor-hist/dto.go +++ b/internal/domain/main-entities/responsible-doctor-hist/dto.go @@ -8,7 +8,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` } @@ -22,7 +22,7 @@ type ReadListDto struct { type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Doctor_Code *string `json:"doctor-code"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` } @@ -50,7 +50,7 @@ type MetaDto struct { type ResponseDto struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Doctor *ed.Doctor `json:"doctor,omitempty"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` @@ -59,7 +59,7 @@ type ResponseDto struct { func (d ResponsibleDoctorHist) ToResponse() ResponseDto { resp := ResponseDto{ Encounter_Id: d.Encounter_Id, - Doctor_Id: d.Doctor_Id, + Doctor_Code: d.Doctor_Code, Doctor: d.Doctor, StartedAt: d.StartedAt, FinishedAt: d.FinishedAt, diff --git a/internal/domain/main-entities/responsible-doctor-hist/entity.go b/internal/domain/main-entities/responsible-doctor-hist/entity.go index 75aa90f6..d9b4946c 100644 --- a/internal/domain/main-entities/responsible-doctor-hist/entity.go +++ b/internal/domain/main-entities/responsible-doctor-hist/entity.go @@ -9,9 +9,8 @@ import ( type ResponsibleDoctorHist struct { ecore.Main // adjust this according to the needs Encounter_Id *uint `json:"encounter_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"` StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` } diff --git a/internal/domain/main-entities/therapy-protocol/dto.go b/internal/domain/main-entities/therapy-protocol/dto.go index f7a5f2e4..40633b89 100644 --- a/internal/domain/main-entities/therapy-protocol/dto.go +++ b/internal/domain/main-entities/therapy-protocol/dto.go @@ -9,7 +9,7 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` - Doctor_Id *uint `json:"doctor_id"` + Doctor_Code *string `json:"doctor_code"` Anamnesis *string `json:"anamnesis" validate:"maxLength=2048"` MedicalDiagnoses *string `json:"medicalDiagnoses"` FunctionDiagnoses *string `json:"functionDiagnoses"` @@ -31,8 +31,8 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Doctor_Id *uint `json:"doctor-id"` + Encounter_Id *uint `json:"encounter-id"` + Doctor_Code *string `json:"doctor-code"` } type ReadDetailDto struct { @@ -59,7 +59,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"` Anamnesis *string `json:"anamnesis"` MedicalDiagnoses *string `json:"medicalDiagnoses"` @@ -79,7 +79,7 @@ func (d TherapyProtocol) 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, Anamnesis: d.Anamnesis, MedicalDiagnoses: d.MedicalDiagnoses, diff --git a/internal/domain/main-entities/therapy-protocol/entity.go b/internal/domain/main-entities/therapy-protocol/entity.go index a91e18eb..7caaf0a6 100644 --- a/internal/domain/main-entities/therapy-protocol/entity.go +++ b/internal/domain/main-entities/therapy-protocol/entity.go @@ -13,9 +13,8 @@ type TherapyProtocol struct { Encounter_Id *uint `json:"encounter_id" gorm:"not null"` 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"` Anamnesis *string `json:"anamnesis" gorm:"size:2048"` MedicalDiagnoses *string `json:"medicalDiagnoses"` diff --git a/internal/interface/main-handler/doctor/handler.go b/internal/interface/main-handler/doctor/handler.go index ee1252ad..f62495d6 100644 --- a/internal/interface/main-handler/doctor/handler.go +++ b/internal/interface/main-handler/doctor/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ 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.Code = &code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/encounter/request-validation.go b/internal/interface/main-handler/encounter/request-validation.go index be370074..79cc832c 100644 --- a/internal/interface/main-handler/encounter/request-validation.go +++ b/internal/interface/main-handler/encounter/request-validation.go @@ -47,10 +47,10 @@ func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid boo } func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) { - if i.Responsible_Doctor_Id == nil { + if i.Responsible_Doctor_Code == nil { rw.DataResponse(w, nil, d.FieldError{ Code: dataValidationFail, - Message: "responsible_doctor_id required", + Message: "responsible_doctor_code required", }) return } @@ -68,18 +68,18 @@ func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid } for _, v := range *i.InternalReferences { - if v.Unit_Id == nil { + if v.Unit_Code == nil { rw.DataResponse(w, nil, d.FieldError{ Code: dataValidationFail, - Message: "internalReferences.unit_id required", + Message: "internalReferences.unit_code required", }) return } - if v.Doctor_Id == nil { + if v.Doctor_Code == nil { rw.DataResponse(w, nil, d.FieldError{ Code: dataValidationFail, - Message: "internalReferences.doctor_id required", + Message: "internalReferences.doctor_code required", }) return } diff --git a/internal/interface/main-handler/nurse/handler.go b/internal/interface/main-handler/nurse/handler.go index 8817ae14..b8252892 100644 --- a/internal/interface/main-handler/nurse/handler.go +++ b/internal/interface/main-handler/nurse/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ 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.Code = &code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "code", r.PathValue("code")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/consultation/case.go b/internal/use-case/main-use-case/consultation/case.go index 3cda31d9..25306169 100644 --- a/internal/use-case/main-use-case/consultation/case.go +++ b/internal/use-case/main-use-case/consultation/case.go @@ -7,8 +7,6 @@ import ( e "simrs-vx/internal/domain/main-entities/consultation" ue "simrs-vx/internal/use-case/main-use-case/encounter" - ud "simrs-vx/internal/use-case/main-use-case/doctor" - dg "github.com/karincake/apem/db-gorm-pg" d "github.com/karincake/dodol" @@ -314,12 +312,7 @@ func Reply(input e.ReplyDto) (*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.DstDoctor_Id != nil && data.DstDoctor_Id != doctor_id { + if data.DstDoctor_Code != nil && data.DstDoctor_Code != input.AuthInfo.Doctor_Code { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-handled-mismatch", @@ -329,7 +322,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) { return pl.SetLogError(&event, input) } - data.DstDoctor_Id = doctor_id + data.DstDoctor_Code = input.AuthInfo.Doctor_Code data.Solution = input.Solution data.RepliedAt = pu.GetTimeNow() err = tx.Save(&data).Error diff --git a/internal/use-case/main-use-case/consultation/helper.go b/internal/use-case/main-use-case/consultation/helper.go index 519c3c91..3a518c77 100644 --- a/internal/use-case/main-use-case/consultation/helper.go +++ b/internal/use-case/main-use-case/consultation/helper.go @@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Consultation) { data.Encounter_Id = inputSrc.Encounter_Id data.Date = inputSrc.Date data.Problem = inputSrc.Problem - data.DstUnit_Id = inputSrc.DstUnit_Id + data.DstUnit_Code = inputSrc.DstUnit_Code } diff --git a/internal/use-case/main-use-case/control-letter/helper.go b/internal/use-case/main-use-case/control-letter/helper.go index 5cc943c5..8ae71d3c 100644 --- a/internal/use-case/main-use-case/control-letter/helper.go +++ b/internal/use-case/main-use-case/control-letter/helper.go @@ -18,9 +18,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code + data.Doctor_Code = inputSrc.Doctor_Code data.Date = inputSrc.Date } diff --git a/internal/use-case/main-use-case/doctor/case.go b/internal/use-case/main-use-case/doctor/case.go index 74337056..cab7facc 100644 --- a/internal/use-case/main-use-case/doctor/case.go +++ b/internal/use-case/main-use-case/doctor/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Doctor var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Doctor var err error diff --git a/internal/use-case/main-use-case/doctor/lib.go b/internal/use-case/main-use-case/doctor/lib.go index 3355bb3c..12b62176 100644 --- a/internal/use-case/main-use-case/doctor/lib.go +++ b/internal/use-case/main-use-case/doctor/lib.go @@ -84,7 +84,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e if input.Employee_Id != nil { tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id) } - if input.Id > 0 { + if input.Id != nil { tx = tx.Where("\"Id\" = ?", input.Id) } if err := tx.First(&data).Error; err != nil { diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index e1643d83..3a8c3b82 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -574,11 +574,11 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } // Upsert responsible_doctor_hist if responsible_doctor_id has changed - if data.Responsible_Doctor_Id == nil || *input.Responsible_Doctor_Id != *data.Responsible_Doctor_Id { + if data.Responsible_Doctor_Code == nil || *input.Responsible_Doctor_Code != *data.Responsible_Doctor_Code { // upsert responsibleDoctorHist if err = upsertResponsibleDoctorHist(erdh.CreateDto{ Encounter_Id: &data.Id, - Doctor_Id: input.Responsible_Doctor_Id, + Doctor_Code: input.Responsible_Doctor_Code, StartedAt: input.StartedAt, }, &event, tx); err != nil { return err @@ -634,24 +634,24 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { // Start log pl.SetLogInfo(&event, input, "started", "checkOut") - unitIDs := make(map[uint16]struct{}) - doctorIDs := make(map[uint]struct{}) + unitCodes := make(map[string]struct{}) + doctorCodes := make(map[string]struct{}) for _, ref := range *input.InternalReferences { - if ref.Unit_Id != nil { - unitIDs[*ref.Unit_Id] = struct{}{} + if ref.Unit_Code != nil { + unitCodes[*ref.Unit_Code] = struct{}{} } - if ref.Doctor_Id != nil { - doctorIDs[*ref.Doctor_Id] = struct{}{} + if ref.Doctor_Code != nil { + doctorCodes[*ref.Doctor_Code] = struct{}{} } } // validate unit - if err = validateUnitIds(unitIDs, &event); err != nil { + if err = validateUnitCodes(unitCodes, &event); err != nil { return nil, err } // validate doctor - if err = validateDoctorIds(doctorIDs, &event); err != nil { + if err = validateDoctorCodes(doctorCodes, &event); err != nil { return nil, err } @@ -773,8 +773,8 @@ func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { Id: input.InternalReferences_Id, CreateDto: eir.CreateDto{ Encounter_Id: &input.Id, - Doctor_Id: irData.Doctor_Id, - Unit_Id: irData.Unit_Id, + Doctor_Code: irData.Doctor_Code, + Unit_Code: irData.Unit_Code, Status_Code: erc.DACApproved, }}, irData, &event, tx); err != nil { return err @@ -793,15 +793,15 @@ func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { // create responsible doctor based on internal reference data if _, err = urdh.CreateData(erdh.CreateDto{ Encounter_Id: &input.Id, - Doctor_Id: irData.Doctor_Id, + Doctor_Code: irData.Doctor_Code, StartedAt: &now, }, &event, tx); err != nil { return err } // update data response - data.Responsible_Doctor_Id = irData.Doctor_Id - data.Unit = irData.Unit + data.Responsible_Doctor_Code = irData.Doctor_Code + data.Unit = irData.Unit // TODO: check if this is correct data.Specialist_Code = irData.Doctor.Specialist_Code data.Subspecialist_Code = irData.Doctor.Subspecialist_Code diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 1d313d5f..793b5305 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -77,17 +77,17 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { data.RegisteredAt = inputSrc.RegisteredAt data.Class_Code = inputSrc.Class_Code data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code data.VisitDate = inputSrc.VisitDate data.PaymentMethod_Code = inputSrc.PaymentMethod_Code data.InsuranceCompany_Id = inputSrc.InsuranceCompany_Id data.Member_Number = inputSrc.Member_Number data.Ref_Number = inputSrc.Ref_Number data.Trx_Number = inputSrc.Trx_Number - data.Appointment_Doctor_Id = inputSrc.Appointment_Doctor_Id + data.Appointment_Doctor_Code = inputSrc.Appointment_Doctor_Code data.Adm_Employee_Id = inputSrc.Adm_Employee_Id - data.Responsible_Doctor_Id = inputSrc.Responsible_Doctor_Id + data.Responsible_Doctor_Code = inputSrc.Responsible_Doctor_Code data.RefSource_Name = inputSrc.RefSource_Name data.Appointment_Id = inputSrc.Appointment_Id data.Status_Code = erc.DSCProcess @@ -96,11 +96,11 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { } func setDataUpdate(src e.UpdateDto, dst *e.Encounter) { - dst.Appointment_Doctor_Id = src.Appointment_Doctor_Id - dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id + dst.Appointment_Doctor_Code = src.Appointment_Doctor_Code + dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code dst.Unit_Id = src.Unit_Id - dst.Specialist_Id = src.Specialist_Id - dst.Subspecialist_Id = src.Subspecialist_Id + dst.Specialist_Code = src.Specialist_Code + dst.Subspecialist_Code = src.Subspecialist_Code dst.VisitDate = src.VisitDate } @@ -126,7 +126,7 @@ func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) { dst.Adm_Employee_Id = src.Adm_Employee_Id } - dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id + dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code dst.StartedAt = src.StartedAt } @@ -395,9 +395,9 @@ func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...* default: // Update if err := tx.Model(&latest).Updates(map[string]interface{}{ - "Doctor_Id": input.Doctor_Id, - "StartedAt": input.StartedAt, - "UpdatedAt": time.Now(), + "Doctor_Code": input.Doctor_Code, + "StartedAt": input.StartedAt, + "UpdatedAt": time.Now(), }).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -904,8 +904,8 @@ func validateForeignKey(input e.CheckinDto) error { } // validate doctor_id - if input.Responsible_Doctor_Id != nil { - if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Responsible_Doctor_Id)}); err != nil { + if input.Responsible_Doctor_Code != nil { + if _, err := ud.ReadDetail(ed.ReadDetailDto{Code: input.Responsible_Doctor_Code}); err != nil { return err } } @@ -932,10 +932,10 @@ func setDBError(event *pl.Event, err error, ctx any) error { return pl.SetLogError(event, ctx) } -func getUnits(unitIds []uint16, event *pl.Event) ([]eu.Unit, error) { +func getUnits(unitIds []string, event *pl.Event) ([]eu.Unit, error) { pl.SetLogInfo(event, nil, "started", "getUnits") var units []eu.Unit - err := dg.I.Where("\"Id\" IN ?", unitIds).Find(&units).Error + err := dg.I.Where("\"Code\" IN ?", unitIds).Find(&units).Error if err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -948,10 +948,10 @@ func getUnits(unitIds []uint16, event *pl.Event) ([]eu.Unit, error) { return units, nil } -func getDoctors(doctorIds []uint, event *pl.Event) ([]ed.Doctor, error) { +func getDoctors(doctorIds []string, event *pl.Event) ([]ed.Doctor, error) { pl.SetLogInfo(event, nil, "started", "getDoctors") var doctors []ed.Doctor - err := dg.I.Where("\"Id\" IN ?", doctorIds).Find(&doctors).Error + err := dg.I.Where("\"Id\" Code ?", doctorIds).Find(&doctors).Error if err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -964,18 +964,18 @@ func getDoctors(doctorIds []uint, event *pl.Event) ([]ed.Doctor, error) { return doctors, nil } -func validateUnitIds(unitIDs map[uint16]struct{}, event *pl.Event) error { - if len(unitIDs) > 0 { - var ids []uint16 - for id := range unitIDs { - ids = append(ids, id) +func validateUnitCodes(unitCodes map[string]struct{}, event *pl.Event) error { + if len(unitCodes) > 0 { + var codes []string + for code := range unitCodes { + codes = append(codes, code) } - units, err := getUnits(ids, event) + units, err := getUnits(codes, event) if err != nil { return fmt.Errorf("failed to fetch units: %w", err) } - if len(units) != len(ids) { + if len(units) != len(codes) { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-validation-fail", @@ -988,18 +988,18 @@ func validateUnitIds(unitIDs map[uint16]struct{}, event *pl.Event) error { return nil } -func validateDoctorIds(doctorIDs map[uint]struct{}, event *pl.Event) error { - if len(doctorIDs) > 0 { - var ids []uint - for id := range doctorIDs { - ids = append(ids, id) +func validateDoctorCodes(doctorCodes map[string]struct{}, event *pl.Event) error { + if len(doctorCodes) > 0 { + var codes []string + for code := range doctorCodes { + codes = append(codes, code) } - doctors, err := getDoctors(ids, event) + doctors, err := getDoctors(codes, event) if err != nil { return fmt.Errorf("failed to fetch doctors: %w", err) } - if len(doctors) != len(ids) { + if len(doctors) != len(codes) { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-validation-fail", diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 8772a2f4..840fefac 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -332,10 +332,10 @@ func updateEncounterApproveSwitchUnit(input eir.InternalReference, event *pl.Eve if err := tx.Model(&e.Encounter{}). Where("\"Id\" = ?", input.Encounter_Id). Updates(map[string]interface{}{ - "Responsible_Doctor_Id": input.Doctor_Id, - "Unit_Id": input.Unit_Id, - "Specialist_Code": input.Doctor.Specialist_Code, - "Subspecialist_Code": input.Doctor.Subspecialist_Code, + "Responsible_Doctor_Code": input.Doctor_Code, + "Unit_Code": input.Unit_Code, + "Specialist_Code": input.Doctor.Specialist_Code, + "Subspecialist_Code": input.Doctor.Subspecialist_Code, }).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ diff --git a/internal/use-case/main-use-case/internal-reference/helper.go b/internal/use-case/main-use-case/internal-reference/helper.go index 36c28540..234eb770 100644 --- a/internal/use-case/main-use-case/internal-reference/helper.go +++ b/internal/use-case/main-use-case/internal-reference/helper.go @@ -19,8 +19,8 @@ func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReferenc } data.Encounter_Id = inputSrc.Encounter_Id - data.Unit_Id = inputSrc.Unit_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Unit_Code = inputSrc.Unit_Code + data.Doctor_Code = inputSrc.Doctor_Code data.Status_Code = &inputSrc.Status_Code } @@ -31,8 +31,8 @@ func setBulkData(input []ir.CreateDto, encounterId uint) []ir.InternalReference statusCode := erc.DACNew data = append(data, ir.InternalReference{ Encounter_Id: &encounterId, - Unit_Id: v.Unit_Id, - Doctor_Id: v.Doctor_Id, + Unit_Code: v.Unit_Code, + Doctor_Code: v.Doctor_Code, Status_Code: &statusCode, }) } diff --git a/internal/use-case/main-use-case/nurse/case.go b/internal/use-case/main-use-case/nurse/case.go index 6201e15b..e7d0ce0c 100644 --- a/internal/use-case/main-use-case/nurse/case.go +++ b/internal/use-case/main-use-case/nurse/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Nurse var err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Nurse var err error diff --git a/internal/use-case/main-use-case/nurse/lib.go b/internal/use-case/main-use-case/nurse/lib.go index a59cc692..e0ce8ba6 100644 --- a/internal/use-case/main-use-case/nurse/lib.go +++ b/internal/use-case/main-use-case/nurse/lib.go @@ -84,7 +84,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e if input.Employee_Id != nil { tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id) } - if input.Id > 0 { + if input.Id != nil { tx = tx.Where("\"Id\" = ?", input.Id) } if err := tx.First(&data).Error; err != nil { diff --git a/internal/use-case/main-use-case/practice-schedule/helper.go b/internal/use-case/main-use-case/practice-schedule/helper.go index 5c9f7815..ba61b691 100644 --- a/internal/use-case/main-use-case/practice-schedule/helper.go +++ b/internal/use-case/main-use-case/practice-schedule/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PracticeSchedule) { inputSrc = &inputTemp.CreateDto } - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.Unit_Code = inputSrc.Unit_Code data.Day_Code = inputSrc.Day_Code data.StartTime = inputSrc.StartTime diff --git a/internal/use-case/main-use-case/responsible-doctor-hist/helper.go b/internal/use-case/main-use-case/responsible-doctor-hist/helper.go index 6efd1097..33ee9da4 100644 --- a/internal/use-case/main-use-case/responsible-doctor-hist/helper.go +++ b/internal/use-case/main-use-case/responsible-doctor-hist/helper.go @@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ResponsibleDoctorHi } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.StartedAt = inputSrc.StartedAt data.FinishedAt = inputSrc.FinishedAt } diff --git a/internal/use-case/main-use-case/therapy-protocol/case.go b/internal/use-case/main-use-case/therapy-protocol/case.go index 93cf05a4..bc65325f 100644 --- a/internal/use-case/main-use-case/therapy-protocol/case.go +++ b/internal/use-case/main-use-case/therapy-protocol/case.go @@ -299,9 +299,9 @@ func validateForeignKey(input e.CreateDto) error { } } - // validate doctor_id - if input.Doctor_Id != nil { - if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Doctor_Id)}); err != nil { + // validate doctor_code + if input.Doctor_Code != nil { + if _, err := ud.ReadDetail(ed.ReadDetailDto{Code: input.Doctor_Code}); err != nil { return err } } diff --git a/internal/use-case/main-use-case/therapy-protocol/helper.go b/internal/use-case/main-use-case/therapy-protocol/helper.go index 12e48747..021c89ed 100644 --- a/internal/use-case/main-use-case/therapy-protocol/helper.go +++ b/internal/use-case/main-use-case/therapy-protocol/helper.go @@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.TherapyProtocol) { } data.Encounter_Id = inputSrc.Encounter_Id - data.Doctor_Id = inputSrc.Doctor_Id + data.Doctor_Code = inputSrc.Doctor_Code data.Anamnesis = inputSrc.Anamnesis data.MedicalDiagnoses = inputSrc.MedicalDiagnoses data.FunctionDiagnoses = inputSrc.FunctionDiagnoses From 9a5516a1e9d726dafa8bfd24e51b85a956827500 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 10 Nov 2025 13:27:04 +0700 Subject: [PATCH 15/22] migration from server --- cmd/main-migration/migrations/atlas.sum | 50 ++++++++++++------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index c64990da..73bcddde 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:BX21/eygPEF+JaTDfxN/z3+7YAe6EYWa1EK9N2PKhAE= +h1:CY3tmVMc8TOrAWeo+JbrRmrP/i5EAJ+c/ZA5/PEgxho= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,27 +75,27 @@ h1:BX21/eygPEF+JaTDfxN/z3+7YAe6EYWa1EK9N2PKhAE= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= -20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= -20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= -20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= -20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= -20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= -20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= -20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= -20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= -20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= -20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= -20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= -20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= -20251110062042.sql h1:yUUNX3EekfedaGTt5Q89a0bgZoCu/kfdXLU4iljN5Xw= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= +20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= +20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= +20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= +20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= +20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= +20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= From be8acefeff331aa1bb741b055966ebe3a5a8cb2c Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 13:34:04 +0700 Subject: [PATCH 16/22] change unit_id, insurance_company_id into code --- .../migrations/20251110063202.sql | 4 ++ cmd/main-migration/migrations/atlas.sum | 51 ++++++++++--------- internal/domain/main-entities/chemo/dto.go | 4 ++ internal/domain/main-entities/chemo/entity.go | 1 + .../domain/main-entities/encounter/dto.go | 14 ++--- .../domain/main-entities/encounter/entity.go | 6 +-- .../main-use-case/encounter/helper.go | 8 +-- 7 files changed, 48 insertions(+), 40 deletions(-) create mode 100644 cmd/main-migration/migrations/20251110063202.sql diff --git a/cmd/main-migration/migrations/20251110063202.sql b/cmd/main-migration/migrations/20251110063202.sql new file mode 100644 index 00000000..90c55b4d --- /dev/null +++ b/cmd/main-migration/migrations/20251110063202.sql @@ -0,0 +1,4 @@ +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" ADD COLUMN "SrcUnit_Code" text NULL; +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" DROP CONSTRAINT "fk_Encounter_InsuranceCompany", DROP CONSTRAINT "fk_Encounter_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "InsuranceCompany_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "InsuranceCompany_Code" TYPE character varying(20), ADD CONSTRAINT "fk_Encounter_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Code") REFERENCES "public"."InsuranceCompany" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 73bcddde..5b16d0e3 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:CY3tmVMc8TOrAWeo+JbrRmrP/i5EAJ+c/ZA5/PEgxho= +h1:o5Hy+7GMNij47fSD0WmODLv/+50U8aJ5oI2zZ657Bm4= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,27 +75,28 @@ h1:CY3tmVMc8TOrAWeo+JbrRmrP/i5EAJ+c/ZA5/PEgxho= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= -20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= -20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= -20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= -20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= -20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= -20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= -20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= -20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= -20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= -20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= -20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= -20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= +20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= +20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= +20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= +20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= +20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= +20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= +20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= +20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= +20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= +20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= +20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= +20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= +20251110062042.sql h1:yUUNX3EekfedaGTt5Q89a0bgZoCu/kfdXLU4iljN5Xw= +20251110063202.sql h1:z/eZpUGtTKzG0D9erH5FEg0YqXU3d/Nou5IW0IjIA9E= diff --git a/internal/domain/main-entities/chemo/dto.go b/internal/domain/main-entities/chemo/dto.go index 653b5409..31660ef8 100644 --- a/internal/domain/main-entities/chemo/dto.go +++ b/internal/domain/main-entities/chemo/dto.go @@ -21,6 +21,7 @@ type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Status_Code erc.DataVerifiedCode `json:"status_code"` SrcUnit_Id *uint `json:"srcUnit_id"` + SrcUnit_Code *string `json:"srcUnit_code"` } type ReadListDto struct { @@ -34,6 +35,7 @@ type FilterDto struct { Status_Code *erc.DataVerifiedCode `json:"status-code"` VerifiedBy_User_Id *uint `json:"verifiedBy-user-id"` SrcUnit_Id *uint `json:"srcUnit-id"` + SrcUnit_Code *string `json:"srcUnit-code"` } type ReadDetailDto struct { @@ -73,6 +75,7 @@ type ResponseDto struct { VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty"` SrcUnit_Id *uint `json:"srcUnit_id"` + SrcUnit_Code *string `json:"srcUnit_code"` SrcUnit *eun.Unit `json:"srcUnit,omitempty"` } @@ -85,6 +88,7 @@ func (d Chemo) ToResponse() ResponseDto { VerifiedBy_User_Id: d.VerifiedBy_User_Id, VerifiedBy: d.VerifiedBy, SrcUnit_Id: d.SrcUnit_Id, + SrcUnit_Code: d.SrcUnit_Code, SrcUnit: d.SrcUnit, } resp.Main = d.Main diff --git a/internal/domain/main-entities/chemo/entity.go b/internal/domain/main-entities/chemo/entity.go index a56dae76..60a0f9f1 100644 --- a/internal/domain/main-entities/chemo/entity.go +++ b/internal/domain/main-entities/chemo/entity.go @@ -20,6 +20,7 @@ type Chemo struct { VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"` SrcUnit_Id *uint `json:"src_unit_id"` + SrcUnit_Code *string `json:"src_unit_code"` SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Id;references:Id"` Bed *string `json:"bed" gorm:"size:1024"` Needs *string `json:"needs" gorm:"size:2048"` diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 7ac57b07..af8c1336 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -38,12 +38,12 @@ type CreateDto struct { 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 - Unit_Id *uint `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Specialist_Code *string `json:"specialist_code"` Subspecialist_Code *string `json:"subspecialist_code"` VisitDate time.Time `json:"visitDate"` PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` + InsuranceCompany_Code *string `json:"insuranceCompany_code"` Member_Number *string `json:"member_number" validate:"maxLength=20"` Ref_Number *string `json:"ref_number" validate:"maxLength=20"` Trx_Number *string `json:"trx_number" validate:"maxLength=20"` @@ -75,7 +75,7 @@ type FilterDto struct { Patient *ep.Patient `json:"patient,omitempty"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"` - Unit_Id *uint `json:"unit-id"` + Unit_Code *string `json:"unit-code"` Specialist_Code *string `json:"specialist-code"` Subspecialist_Code *string `json:"subspecialist-code"` VisitDate time.Time `json:"visitDate"` @@ -149,7 +149,7 @@ type ResponseDto struct { Patient *ep.Patient `json:"patient,omitempty"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code"` - Unit_Id *uint `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty"` Subspecialist_Code *string `json:"subspecialist_code"` @@ -157,7 +157,7 @@ type ResponseDto struct { Unit *eu.Unit `json:"unit,omitempty"` VisitDate time.Time `json:"visitDate"` PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` + InsuranceCompany_Code *string `json:"insuranceCompany_code"` Member_Number *string `json:"member_number"` Ref_Number *string `json:"ref_number"` Trx_Number *string `json:"trx_number"` @@ -196,7 +196,7 @@ func (d Encounter) ToResponse() ResponseDto { Patient: d.Patient, RegisteredAt: d.RegisteredAt, Class_Code: d.Class_Code, - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, Specialist_Code: d.Specialist_Code, Specialist: d.Specialist, @@ -204,7 +204,7 @@ func (d Encounter) ToResponse() ResponseDto { Subspecialist: d.Subspecialist, VisitDate: d.VisitDate, PaymentMethod_Code: d.PaymentMethod_Code, - InsuranceCompany_Id: d.InsuranceCompany_Id, + InsuranceCompany_Code: d.InsuranceCompany_Code, Member_Number: d.Member_Number, Ref_Number: d.Ref_Number, Trx_Number: d.Trx_Number, diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index e07b2263..c9e9bb95 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -29,9 +29,8 @@ type Encounter struct { Patient *ep.Patient `json:"patient,omitempty" gorm:"foreignKey:Patient_Id;references:Id"` RegisteredAt *time.Time `json:"registeredAt"` Class_Code ere.EncounterClassCode `json:"class_code" gorm:"not null;size:10"` - Unit_Id *uint `json:"unit_id"` Unit_Code *string `json:"unit_code"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` Specialist_Code *string `json:"specialist_code"` Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` Subspecialist_Code *string `json:"subspecialist_code"` @@ -40,9 +39,8 @@ type Encounter struct { StartedAt *time.Time `json:"startedAt"` FinishedAt *time.Time `json:"finishedAt"` PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` - InsuranceCompany_Id *uint `json:"insuranceCompany_id"` InsuranceCompany_Code *string `json:"insuranceCompany_code"` - InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"` + InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Code;references:Code"` Member_Number *string `json:"memberNumber" gorm:"unique;size:20"` RefType_Code *ere.RefTypeCode `json:"refType_code"` Ref_Number *string `json:"refNumber" gorm:"unique;size:20"` diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 793b5305..be187bea 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -76,12 +76,12 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { data.Patient_Id = inputSrc.Patient_Id data.RegisteredAt = inputSrc.RegisteredAt data.Class_Code = inputSrc.Class_Code - data.Unit_Id = inputSrc.Unit_Id + data.Unit_Code = inputSrc.Unit_Code data.Specialist_Code = inputSrc.Specialist_Code data.Subspecialist_Code = inputSrc.Subspecialist_Code data.VisitDate = inputSrc.VisitDate data.PaymentMethod_Code = inputSrc.PaymentMethod_Code - data.InsuranceCompany_Id = inputSrc.InsuranceCompany_Id + data.InsuranceCompany_Code = inputSrc.InsuranceCompany_Code data.Member_Number = inputSrc.Member_Number data.Ref_Number = inputSrc.Ref_Number data.Trx_Number = inputSrc.Trx_Number @@ -98,7 +98,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { func setDataUpdate(src e.UpdateDto, dst *e.Encounter) { dst.Appointment_Doctor_Code = src.Appointment_Doctor_Code dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code - dst.Unit_Id = src.Unit_Id + dst.Unit_Code = src.Unit_Code dst.Specialist_Code = src.Specialist_Code dst.Subspecialist_Code = src.Subspecialist_Code dst.VisitDate = src.VisitDate @@ -810,7 +810,7 @@ func insertDataSubClassAmbulatory(input e.CreateDto, soapiData []es.CreateDto, e chemoCreate := ec.CreateDto{ Encounter_Id: &input.Id, Status_Code: erc.DVCNew, - SrcUnit_Id: input.Unit_Id, + SrcUnit_Code: input.Unit_Code, } // create data chemo From 156cb0fd931a9c96b41c231e864ca0ba6440927f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 10 Nov 2025 13:34:56 +0700 Subject: [PATCH 17/22] migration from server --- cmd/main-migration/migrations/atlas.sum | 52 ++++++++++++------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 5b16d0e3..dad233fe 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:o5Hy+7GMNij47fSD0WmODLv/+50U8aJ5oI2zZ657Bm4= +h1:wRvp5REHLDtGi/6Rlwwc2eOHIhe0oJQVJSmeFCvfyb8= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,28 +75,28 @@ h1:o5Hy+7GMNij47fSD0WmODLv/+50U8aJ5oI2zZ657Bm4= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= -20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= -20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= -20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= -20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= -20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= -20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= -20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= -20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= -20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= -20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= -20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= -20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= -20251110062042.sql h1:yUUNX3EekfedaGTt5Q89a0bgZoCu/kfdXLU4iljN5Xw= -20251110063202.sql h1:z/eZpUGtTKzG0D9erH5FEg0YqXU3d/Nou5IW0IjIA9E= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= +20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= +20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= +20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= +20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= +20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= +20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= +20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= From 9417ff07051d4b09d470ed6bca491ddde7556f07 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 13:37:15 +0700 Subject: [PATCH 18/22] change srcUnit_id into code --- .../migrations/20251110063633.sql | 2 + cmd/main-migration/migrations/atlas.sum | 53 ++++++++++--------- internal/domain/main-entities/chemo/dto.go | 4 -- internal/domain/main-entities/chemo/entity.go | 3 +- .../use-case/main-use-case/chemo/helper.go | 2 +- 5 files changed, 31 insertions(+), 33 deletions(-) create mode 100644 cmd/main-migration/migrations/20251110063633.sql diff --git a/cmd/main-migration/migrations/20251110063633.sql b/cmd/main-migration/migrations/20251110063633.sql new file mode 100644 index 00000000..de41516f --- /dev/null +++ b/cmd/main-migration/migrations/20251110063633.sql @@ -0,0 +1,2 @@ +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" DROP CONSTRAINT "fk_Chemo_SrcUnit", DROP COLUMN "SrcUnit_Id", ALTER COLUMN "SrcUnit_Code" TYPE character varying(10), ADD CONSTRAINT "fk_Chemo_SrcUnit" FOREIGN KEY ("SrcUnit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index dad233fe..c27f97c1 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:wRvp5REHLDtGi/6Rlwwc2eOHIhe0oJQVJSmeFCvfyb8= +h1:bONKXih1Woh8TA4X9FVhqYCV+ZT5wGRr4g5xkpKLI2o= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,28 +75,29 @@ h1:wRvp5REHLDtGi/6Rlwwc2eOHIhe0oJQVJSmeFCvfyb8= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= -20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= -20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= -20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= -20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= -20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= -20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= -20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= -20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= -20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= -20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= -20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= -20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= -20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= +20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= +20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= +20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= +20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= +20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= +20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= +20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= +20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= +20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= +20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= +20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= +20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= +20251110062042.sql h1:yUUNX3EekfedaGTt5Q89a0bgZoCu/kfdXLU4iljN5Xw= +20251110063202.sql h1:z/eZpUGtTKzG0D9erH5FEg0YqXU3d/Nou5IW0IjIA9E= +20251110063633.sql h1:81jDaSXtmWBCe64LiEASCNK0AuPeC+6js5srhLmRji8= diff --git a/internal/domain/main-entities/chemo/dto.go b/internal/domain/main-entities/chemo/dto.go index 31660ef8..5d8b9501 100644 --- a/internal/domain/main-entities/chemo/dto.go +++ b/internal/domain/main-entities/chemo/dto.go @@ -20,7 +20,6 @@ import ( type CreateDto struct { Encounter_Id *uint `json:"encounter_id"` Status_Code erc.DataVerifiedCode `json:"status_code"` - SrcUnit_Id *uint `json:"srcUnit_id"` SrcUnit_Code *string `json:"srcUnit_code"` } @@ -34,7 +33,6 @@ type FilterDto struct { Encounter_Id *uint `json:"encounter-id"` Status_Code *erc.DataVerifiedCode `json:"status-code"` VerifiedBy_User_Id *uint `json:"verifiedBy-user-id"` - SrcUnit_Id *uint `json:"srcUnit-id"` SrcUnit_Code *string `json:"srcUnit-code"` } @@ -74,7 +72,6 @@ type ResponseDto struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty"` - SrcUnit_Id *uint `json:"srcUnit_id"` SrcUnit_Code *string `json:"srcUnit_code"` SrcUnit *eun.Unit `json:"srcUnit,omitempty"` } @@ -87,7 +84,6 @@ func (d Chemo) ToResponse() ResponseDto { VerifiedAt: d.VerifiedAt, VerifiedBy_User_Id: d.VerifiedBy_User_Id, VerifiedBy: d.VerifiedBy, - SrcUnit_Id: d.SrcUnit_Id, SrcUnit_Code: d.SrcUnit_Code, SrcUnit: d.SrcUnit, } diff --git a/internal/domain/main-entities/chemo/entity.go b/internal/domain/main-entities/chemo/entity.go index 60a0f9f1..6f5180aa 100644 --- a/internal/domain/main-entities/chemo/entity.go +++ b/internal/domain/main-entities/chemo/entity.go @@ -19,9 +19,8 @@ type Chemo struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"` - SrcUnit_Id *uint `json:"src_unit_id"` SrcUnit_Code *string `json:"src_unit_code"` - SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Id;references:Id"` + SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Code;references:Code"` Bed *string `json:"bed" gorm:"size:1024"` Needs *string `json:"needs" gorm:"size:2048"` } diff --git a/internal/use-case/main-use-case/chemo/helper.go b/internal/use-case/main-use-case/chemo/helper.go index bb60a39b..51a09a3a 100644 --- a/internal/use-case/main-use-case/chemo/helper.go +++ b/internal/use-case/main-use-case/chemo/helper.go @@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Chemo) { data.Encounter_Id = inputSrc.Encounter_Id data.Status_Code = inputSrc.Status_Code - data.SrcUnit_Id = inputSrc.SrcUnit_Id + data.SrcUnit_Code = inputSrc.SrcUnit_Code } From 9d8f09c0de2d55862ef056c7d89938efd18dcd24 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Mon, 10 Nov 2025 13:37:58 +0700 Subject: [PATCH 19/22] migration from server --- cmd/main-migration/migrations/atlas.sum | 54 ++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index c27f97c1..ee8bafbe 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:bONKXih1Woh8TA4X9FVhqYCV+ZT5wGRr4g5xkpKLI2o= +h1:Cs+1IkfoV4LHZgT4hNYw7jF73tuz6WesEZdT1xmIvBA= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,29 +75,29 @@ h1:bONKXih1Woh8TA4X9FVhqYCV+ZT5wGRr4g5xkpKLI2o= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= -20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= -20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= -20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= -20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= -20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= -20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= -20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= -20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= -20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= -20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= -20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= -20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= -20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= -20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= -20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= -20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= -20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= -20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= -20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= -20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= -20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= -20251110052049.sql h1:1LkEGCWPe04T3D8F3VMnBP8eJgskrvCggsybNxJ7GuU= -20251110062042.sql h1:yUUNX3EekfedaGTt5Q89a0bgZoCu/kfdXLU4iljN5Xw= -20251110063202.sql h1:z/eZpUGtTKzG0D9erH5FEg0YqXU3d/Nou5IW0IjIA9E= -20251110063633.sql h1:81jDaSXtmWBCe64LiEASCNK0AuPeC+6js5srhLmRji8= +20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= +20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= +20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= +20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= +20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= +20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= +20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= +20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= +20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= +20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= +20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= +20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= +20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= +20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= +20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= +20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= +20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= +20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= +20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= +20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= +20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= +20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= +20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= +20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= +20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= +20251110063633.sql h1:qTiC0F19JnhUIXF4LGJQ21jEV6kKGyhTr1x2kimFqPQ= From d5d9182ad65a14b040c68a96ba33adcd320fee21 Mon Sep 17 00:00:00 2001 From: vanilia Date: Mon, 10 Nov 2025 14:17:56 +0700 Subject: [PATCH 20/22] revise refactor --- internal/domain/main-entities/internal-reference/dto.go | 2 +- .../domain/main-entities/subspecialist-position/dto.go | 2 +- internal/use-case/main-use-case/encounter/case.go | 4 ++-- internal/use-case/main-use-case/encounter/helper.go | 8 ++++---- internal/use-case/main-use-case/encounter/lib.go | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/domain/main-entities/internal-reference/dto.go b/internal/domain/main-entities/internal-reference/dto.go index 08eaaac2..6ce50a77 100644 --- a/internal/domain/main-entities/internal-reference/dto.go +++ b/internal/domain/main-entities/internal-reference/dto.go @@ -51,7 +51,7 @@ type MetaDto struct { type ResponseDto struct { ecore.Main Encounter_Id *uint `json:"encounter_id"` - Unit_Code *string `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty"` Doctor_Code *string `json:"doctor_id"` Doctor *ed.Doctor `json:"doctor,omitempty"` diff --git a/internal/domain/main-entities/subspecialist-position/dto.go b/internal/domain/main-entities/subspecialist-position/dto.go index 13532ab8..1c37a859 100644 --- a/internal/domain/main-entities/subspecialist-position/dto.go +++ b/internal/domain/main-entities/subspecialist-position/dto.go @@ -53,7 +53,7 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Subspecialist_Code *string `json:"subspecialist_id"` + Subspecialist_Code *string `json:"subspecialist_code"` Subspecialist *es.Subspecialist `json:"subspecialist,omitempty"` Code string `json:"code"` Name string `json:"name"` diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 3a8c3b82..d387fcc2 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -573,7 +573,7 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } } - // Upsert responsible_doctor_hist if responsible_doctor_id has changed + // Upsert responsible_doctor_hist if responsible_doctor_code has changed if data.Responsible_Doctor_Code == nil || *input.Responsible_Doctor_Code != *data.Responsible_Doctor_Code { // upsert responsibleDoctorHist if err = upsertResponsibleDoctorHist(erdh.CreateDto{ @@ -801,7 +801,7 @@ func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { // update data response data.Responsible_Doctor_Code = irData.Doctor_Code - data.Unit = irData.Unit // TODO: check if this is correct + data.Unit_Code = irData.Unit_Code // data.Specialist_Code = irData.Doctor.Specialist_Code data.Subspecialist_Code = irData.Doctor.Subspecialist_Code diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index be187bea..1f78d73e 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -903,7 +903,7 @@ func validateForeignKey(input e.CheckinDto) error { } } - // validate doctor_id + // validate doctor_Code if input.Responsible_Doctor_Code != nil { if _, err := ud.ReadDetail(ed.ReadDetailDto{Code: input.Responsible_Doctor_Code}); err != nil { return err @@ -951,7 +951,7 @@ func getUnits(unitIds []string, event *pl.Event) ([]eu.Unit, error) { func getDoctors(doctorIds []string, event *pl.Event) ([]ed.Doctor, error) { pl.SetLogInfo(event, nil, "started", "getDoctors") var doctors []ed.Doctor - err := dg.I.Where("\"Id\" Code ?", doctorIds).Find(&doctors).Error + err := dg.I.Where("\"Code\" IN ?", doctorIds).Find(&doctors).Error if err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -979,7 +979,7 @@ func validateUnitCodes(unitCodes map[string]struct{}, event *pl.Event) error { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-validation-fail", - Detail: "unit_id not found", + Detail: "unit_code not found", } return pl.SetLogError(event, nil) } @@ -1003,7 +1003,7 @@ func validateDoctorCodes(doctorCodes map[string]struct{}, event *pl.Event) error event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-validation-fail", - Detail: "doctor_id not found", + Detail: "doctor_code not found", } return pl.SetLogError(event, nil) } diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 840fefac..22259c09 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -64,7 +64,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.En tx = tx.Model(&e.Encounter{}) if input.AuthInfo.Doctor_Code != nil { - tx.Where("\"Responsible_Doctor_Id\" = ?", *input.AuthInfo.Doctor_Code) // TODO: fix this + tx.Where("\"Responsible_Doctor_Code\" = ?", *input.AuthInfo.Doctor_Code) // } tx.Scopes(gh.Preload(input.Includes)). From 008bbfcc8c9bbd588df4754818d11edf3a938409 Mon Sep 17 00:00:00 2001 From: vanilia Date: Mon, 10 Nov 2025 14:28:52 +0700 Subject: [PATCH 21/22] refactor encounter --- cmd/main-migration/migrations/atlas.sum | 54 ++++++++++++------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index ee8bafbe..ef1f8795 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:Cs+1IkfoV4LHZgT4hNYw7jF73tuz6WesEZdT1xmIvBA= +h1:4mUEGaMHpVG5OAo3DgtsqGkPtWwCZDAk0H5y2cG1QP4= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,29 +75,29 @@ h1:Cs+1IkfoV4LHZgT4hNYw7jF73tuz6WesEZdT1xmIvBA= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= -20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= -20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= -20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= -20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= -20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= -20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= -20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= -20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= -20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= -20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= -20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= -20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= -20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= -20251110063633.sql h1:qTiC0F19JnhUIXF4LGJQ21jEV6kKGyhTr1x2kimFqPQ= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= +20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= +20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= +20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= +20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= +20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= +20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= +20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= +20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= +20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= +20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= +20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= +20251110052049.sql h1:232T2x8xTczJl9nk4jxJpZXhoOGYthhxjJ7nK8Jd8vg= +20251110062042.sql h1:WnfVUXrzYoj8qdkkjO9/JQQ8agGd4GfSHQdMjo7LDAg= +20251110063202.sql h1:hSzGfwVMWa6q3vwIQZUkxKgBNCzHjB+6GKy54zfV+oQ= +20251110063633.sql h1:/VpofIAqNS1CnazEnpW/+evbzn9Kew3xDW48r57M+Xg= From 850dce87cd899c19f5add0c756b604f745125d26 Mon Sep 17 00:00:00 2001 From: vanilia Date: Mon, 10 Nov 2025 15:42:15 +0700 Subject: [PATCH 22/22] revise encounter --- .../use-case/main-use-case/encounter/helper.go | 15 ++++++++++++--- internal/use-case/main-use-case/encounter/lib.go | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 1f78d73e..99b080ab 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -559,7 +559,6 @@ func getSoapiByResponsibleDoctor(enc e.Encounter, event *pl.Event) (data []es.So } err = dg.I. - Debug(). Model(&es.Soapi{}). Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\""). Where("\"Encounter_Id\" = ?", enc.Id). @@ -723,16 +722,26 @@ func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl. return "", nil, err } - if !isQuotaValid || recentRehabData.ExpiredAt.Before(*pu.GetTimeNow()) { + if !isQuotaValid { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "visit-limit-exceeded", - Detail: "Encounter has exceeded the allowed number of visits or expired", + Detail: "Encounter has exceeded the allowed number of visits", Raw: errors.New("visit count exceeds allowed limit"), } return "", nil, pl.SetLogError(event, input) } + if recentRehabData.ExpiredAt != nil && recentRehabData.ExpiredAt.Before(*pu.GetTimeNow()) { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "visit-limit-exceeded", + Detail: "Encounter period has expired", + Raw: errors.New("encounter expired"), + } + return "", nil, pl.SetLogError(event, input) + } + case erc.DSCDone: visitModeCode = ere.VMCAdm diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index 22259c09..d3cc544e 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -312,7 +312,7 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo } // validate count rehab children - if recentEncounterAdm.RehabChildren != nil { + if recentEncounterAdm.RehabChildren != nil && len(*recentEncounterAdm.RehabChildren) > 0 { valid = len(*recentEncounterAdm.RehabChildren) < *recentEncounterAdm.Rehab.AllocatedVisitCount }