From 04312afceeaeb76bdd8c26d550461ffd6630dd85 Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 25 Nov 2025 19:47:47 +0700 Subject: [PATCH 1/7] testing --- .../domain/main-entities/encounter/dto.go | 22 ++--- .../domain/references/encounter/encounter.go | 8 +- .../simgos-entities/m-polihfis/entity.go | 2 +- .../domain/simgos-entities/m-poly/entity.go | 2 +- .../simgos-entities/t-pendaftaran/entity.go | 1 - .../main-handler/encounter/handler.go | 14 +-- .../new/encounter/handler.go | 2 +- .../use-case/main-use-case/doctor/helper.go | 4 +- .../main-use-case/edu-assessment/case.go | 2 +- .../use-case/main-use-case/encounter/case.go | 21 ++-- .../main-use-case/encounter/helper.go | 3 +- .../main-use-case/therapy-protocol/case.go | 2 +- internal/use-case/main-use-case/unit/case.go | 16 +++- .../new/encounter/case.go | 54 +++++------ .../new/encounter/helper.go | 95 ++++++++++++------- .../simgos-sync-use-case/new/encounter/lib.go | 8 +- .../new/patient/helper.go | 15 +-- .../new/specialist/helper.go | 2 +- .../new/specialist/lib.go | 9 +- .../simgos-sync-use-case/new/unit/helper.go | 3 + 20 files changed, 165 insertions(+), 120 deletions(-) diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 849a5834..d4eeda3f 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -65,15 +65,15 @@ type CreateDto struct { } type TRujukan struct { - NoSep string `json:"noSep"` + NoSep string `json:"noSep"` // Surat Eligibilitas Peserta TglRujukan string `json:"tglRujukan"` - PpkDirujuk string `json:"ppkDirujuk"` - JnsPelayanan string `json:"jnsPelayanan"` + PpkDirujuk string `json:"ppkDirujuk"` // PPK (Provider Pelayanan Kesehatan) -> kode RS tujuan + JnsPelayanan string `json:"jnsPelayanan"` // Jenis pelayanan yang dimintakan; 1 = RawatInap; 2 = RawatJalan Catatan string `json:"catatan"` - DiagRujukan string `json:"diagRujukan"` - TipeRujukan string `json:"tipeRujukan"` - PoliRujukan string `json:"poliRujukan"` - User string `json:"user"` + DiagRujukan string `json:"diagRujukan"` // Kode Diagnosa + TipeRujukan string `json:"tipeRujukan"` // 0 = Rujukan Penuh; 1 = Rujukan Partial (hanya untuk tindakan tertentu); 2 = Balik (dikembalikan ke faskes asal) + PoliRujukan string `json:"poliRujukan"` // Kode Poli Tujuan + User string `json:"user"` // user yang membuat rujukan } type ReadListDto struct { @@ -105,24 +105,24 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id uint `json:"id"` Includes string `json:"includes"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id uint `json:"id"` CreateDto } type UpdateStatusDto struct { - Id uint16 `json:"id"` + Id uint `json:"id"` StatusCode erc.DataStatusCode `json:"status_code"` pa.AuthInfo } type DeleteDto struct { - Id uint16 `json:"id"` + Id uint `json:"id"` pa.AuthInfo } diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index ca600246..a1fc3b31 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -95,10 +95,10 @@ const ( RTCPrivate RefTypeCode = "private" // Swasta RTCBpjs RefTypeCode = "bpjs" // BPJS - APMCJkn AllPaymentMethodCode = "jkn" // JKN - APMCJkmm AllPaymentMethodCode = "jkmm" // JKMM - APMCSpm AllPaymentMethodCode = "spm" // SPM - APMCPks AllPaymentMethodCode = "pks" // PKS + APMCJkn AllPaymentMethodCode = "jkn" // JKN -> Jaminan Kesehatan Nasional -> BPJS Kesehatan + APMCJkmm AllPaymentMethodCode = "jkmm" // JKMM -> Jaminan Kesehatan Masyarakat Miskin -> Dibiayai oleh APBD daerah + APMCSpm AllPaymentMethodCode = "spm" // SPM -> Surat Pernyataan Miskin + APMCPks AllPaymentMethodCode = "pks" // PKS -> Perjanjian Kerjasama -> Pembayaran melalui instansi atau perusahaan yang memiliki kontrak dengan rumah sakit APMCUmum AllPaymentMethodCode = "umum" SRTCInternal SEPRefTypeCode = "internal" // Rujukan Internal diff --git a/internal/domain/simgos-entities/m-polihfis/entity.go b/internal/domain/simgos-entities/m-polihfis/entity.go index b9eb7b56..8bed236d 100644 --- a/internal/domain/simgos-entities/m-polihfis/entity.go +++ b/internal/domain/simgos-entities/m-polihfis/entity.go @@ -1,4 +1,4 @@ -package division +package m_polihfis type MPolihfis struct { Id uint `json:"id" gorm:"primaryKey;autoIncrement;column:id"` diff --git a/internal/domain/simgos-entities/m-poly/entity.go b/internal/domain/simgos-entities/m-poly/entity.go index 52fe20eb..aff4bc1e 100644 --- a/internal/domain/simgos-entities/m-poly/entity.go +++ b/internal/domain/simgos-entities/m-poly/entity.go @@ -1,7 +1,7 @@ package m_poly type MPoly struct { - Kode uint `json:"kode" gorm:"primaryKey;autoIncrement;column:kode"` + Kode uint `json:"kode" gorm:"primaryKey;column:kode"` Nama string `json:"nama" gorm:"column:nama"` Jenispoly uint `json:"jenispoly" gorm:"column:jenispoly"` } diff --git a/internal/domain/simgos-entities/t-pendaftaran/entity.go b/internal/domain/simgos-entities/t-pendaftaran/entity.go index 682aabeb..08222653 100644 --- a/internal/domain/simgos-entities/t-pendaftaran/entity.go +++ b/internal/domain/simgos-entities/t-pendaftaran/entity.go @@ -82,7 +82,6 @@ type TPendaftaran struct { DokterNameHfis *string `json:"dokter_name_hfis" gorm:"column:dokter_name_hfis"` DokterIdHfis *string `json:"dokter_id_hfis" gorm:"column:dokter_id_hfis"` StatusBridging *string `json:"status_bridging" gorm:"column:status_bridging"` - NoSpri *string `json:"no_spri" gorm:"column:no_spri"` } func (TPendaftaran) TableName() string { diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index 0c87b7b2..688d6904 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -64,7 +64,7 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { } dto := e.ReadDetailDto{} sf.UrlQueryParam(&dto, *r.URL) - dto.Id = uint16(id) + dto.Id = uint(id) res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } @@ -84,7 +84,7 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Id = uint(id) dto.AuthInfo = *authInfo res, err := u.Update(dto) @@ -103,7 +103,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Id = uint(id) dto.AuthInfo = *authInfo res, err := u.Delete(dto) @@ -175,7 +175,7 @@ func (obj myBase) Process(w http.ResponseWriter, r *http.Request) { } dto := e.UpdateStatusDto{ - Id: uint16(id), + Id: uint(id), StatusCode: erc.DSCProcess, } @@ -195,7 +195,7 @@ func (obj myBase) Cancel(w http.ResponseWriter, r *http.Request) { } dto := e.UpdateStatusDto{ - Id: uint16(id), + Id: uint(id), StatusCode: erc.DSCCancel, } @@ -211,7 +211,7 @@ func (obj myBase) Reject(w http.ResponseWriter, r *http.Request) { } dto := e.UpdateStatusDto{ - Id: uint16(id), + Id: uint(id), StatusCode: erc.DSCRejected, } @@ -226,7 +226,7 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) { } dto := e.UpdateStatusDto{ - Id: uint16(id), + Id: uint(id), StatusCode: erc.DSCSkipped, } diff --git a/internal/interface/simgos-sync-handler/new/encounter/handler.go b/internal/interface/simgos-sync-handler/new/encounter/handler.go index e6b0515a..bec44cd4 100644 --- a/internal/interface/simgos-sync-handler/new/encounter/handler.go +++ b/internal/interface/simgos-sync-handler/new/encounter/handler.go @@ -51,7 +51,7 @@ func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Id = uint(id) res, err := u.Delete(dto) rw.DataResponse(w, res, err) diff --git a/internal/use-case/main-use-case/doctor/helper.go b/internal/use-case/main-use-case/doctor/helper.go index 344d1c0e..9ddc2027 100644 --- a/internal/use-case/main-use-case/doctor/helper.go +++ b/internal/use-case/main-use-case/doctor/helper.go @@ -22,6 +22,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Doctor) { data.IHS_Number = inputSrc.IHS_Number data.SIP_Number = inputSrc.SIP_Number data.Unit_Code = inputSrc.Unit_Code - data.Specialist_Code = inputSrc.Code - data.Subspecialist_Code = inputSrc.Code + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code } diff --git a/internal/use-case/main-use-case/edu-assessment/case.go b/internal/use-case/main-use-case/edu-assessment/case.go index 230f0679..525274ca 100644 --- a/internal/use-case/main-use-case/edu-assessment/case.go +++ b/internal/use-case/main-use-case/edu-assessment/case.go @@ -37,7 +37,7 @@ func Create(input e.CreateDto) (*d.Data, error) { } // validate encounter_id - _, err := ue.ReadDetail(ee.ReadDetailDto{Id: uint16(*input.Encounter_Id)}) + _, err := ue.ReadDetail(ee.ReadDetailDto{Id: *input.Encounter_Id}) if err != nil { return err } diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 25d74859..2a8ee1ba 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -118,7 +118,6 @@ func Create(input e.CreateDto) (*d.Data, error) { // insert vclaimReference if vr := input.VclaimReference; vr != nil { t, _ := time.Parse("2006-01-02", vr.TglRujukan) - _, err = uv.CreateData(ev.CreateDto{ Encounter_Id: &data.Id, Date: &t, @@ -136,8 +135,10 @@ func Create(input e.CreateDto) (*d.Data, error) { } dataEncounter, err := ReadDetailData(e.ReadDetailDto{ - Id: uint16(data.Id), - Includes: "Adm_Employee.User,Patient.Person.Relatives,Patient.Person.VclaimMember,VclaimReference"}, + Id: data.Id, + Includes: "Adm_Employee.User,Patient.Person.Relatives," + + "Patient.Person.VclaimMember,VclaimReference," + + "Patient.Person.Contacts,Patient.Person.Addresses"}, &event, tx) if err != nil { return err @@ -311,7 +312,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } dataEncounter, err := ReadDetailData(e.ReadDetailDto{ - Id: uint16(data.Id), + Id: data.Id, Includes: "Adm_Employee.User,Patient.Person.Relatives,Patient.Person.VclaimMember"}, &event, tx) if err != nil { @@ -429,7 +430,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,Rehab"} + rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Ambulatory,Rehab"} var data *e.Encounter var err error @@ -516,7 +517,7 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { } dataEncounter, err := ReadDetailData(e.ReadDetailDto{ - Id: uint16(data.Id), + Id: data.Id, Includes: "DeathCause"}, &event, tx) if err != nil { @@ -658,7 +659,7 @@ func UpdateStatusCode(input e.UpdateStatusDto) (*d.Data, error) { } func CheckIn(input e.CheckinDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Rehab,Ambulatory"} + rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Rehab,Ambulatory"} var data *e.Encounter var err error @@ -743,7 +744,7 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } dataEncounter, err := ReadDetailData(e.ReadDetailDto{ - Id: uint16(data.Id), + Id: data.Id, Includes: "Adm_Employee.User"}, &event, tx) if err != nil { @@ -776,7 +777,7 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) { } func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"} + rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Responsible_Doctor"} var data *e.Encounter var err error @@ -865,7 +866,7 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) { } func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"} + rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Responsible_Doctor"} var data *e.Encounter var err error diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 3b215c36..73b053e5 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -68,6 +68,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { var inputSrc *e.CreateDto if inputT, ok := any(input).(*e.CreateDto); ok { inputSrc = inputT + data.Status_Code = erc.DSCNew } else { inputTemp := any(input).(*e.UpdateDto) inputSrc = &inputTemp.CreateDto @@ -90,7 +91,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { 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 data.RefType_Code = &inputSrc.RefTypeCode data.NewStatus = inputSrc.NewStatus } @@ -556,6 +556,7 @@ func getSoapiByResponsibleDoctor(enc e.Encounter, event *pl.Event) (data []es.So Code: "no responsible-doctor found", Detail: "Encounter does not have responsible-doctor", } + return nil, pl.SetLogError(event, enc) } err = dg.I. 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 ed4f3a21..a332d675 100644 --- a/internal/use-case/main-use-case/therapy-protocol/case.go +++ b/internal/use-case/main-use-case/therapy-protocol/case.go @@ -359,7 +359,7 @@ func Verify(input e.VerifyDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // validate encounter if input.Encounter_Id != nil { - if _, err := ue.ReadDetail(ee.ReadDetailDto{Id: uint16(*input.Encounter_Id)}); err != nil { + if _, err := ue.ReadDetail(ee.ReadDetailDto{Id: *input.Encounter_Id}); err != nil { return err } } diff --git a/internal/use-case/main-use-case/unit/case.go b/internal/use-case/main-use-case/unit/case.go index 1db6fb79..c73c2c1d 100644 --- a/internal/use-case/main-use-case/unit/case.go +++ b/internal/use-case/main-use-case/unit/case.go @@ -1,6 +1,7 @@ package unit import ( + "errors" e "simrs-vx/internal/domain/main-entities/unit" erc "simrs-vx/internal/domain/references/common" esync "simrs-vx/internal/domain/sync-entities/log" @@ -27,9 +28,22 @@ func Create(input e.CreateDto) (*d.Data, error) { // Start log pl.SetLogInfo(&event, input, "started", "create") + + // validate unit_code + _, err := strconv.Atoi(input.Code) + if err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "invalid_code_format", + Detail: "unit_code must be a valid integer", + Raw: errors.New("invalid unit_code format"), + } + return nil, pl.SetLogError(&event, input) + } + mwRunner := newMiddlewareRunner(&event) - err := dg.I.Transaction(func(tx *gorm.DB) error { + err = dg.I.Transaction(func(tx *gorm.DB) error { if resData, err := CreateData(input, &event, tx); err != nil { return err } else { diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/case.go b/internal/use-case/simgos-sync-use-case/new/encounter/case.go index 6b4f7ab4..f9f48c11 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/case.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/case.go @@ -12,8 +12,6 @@ import ( etp "simrs-vx/internal/domain/simgos-entities/t-pendaftaran" esync "simrs-vx/internal/domain/sync-entities/encounter" elog "simrs-vx/internal/domain/sync-entities/log" - - up "simrs-vx/internal/use-case/simgos-sync-use-case/new/patient" ) const source = "encounter" @@ -46,14 +44,8 @@ func Create(input e.Encounter) (*d.Data, error) { return err } - // STEP: 3 Get MPasien - dataPatient, err := up.ReadDetailSimgosByNomrData(sgData.Nomr, &event, tx.Simgos) - if err != nil { - return err - } - - // STEP 4: Update MPasien - err = updatePatient(*dataPatient, &event, tx.Simgos) + // STEP 3: Update MPasien + err = updatePatientCaraBayar(*sgData, &event, tx.Simgos) if err != nil { return err } @@ -123,13 +115,13 @@ func Update(input e.Encounter) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "update") // STEP 1: Get Link - syncLink, err := ReadDetailLinkData(uint16(input.Id), &event) + syncLink, err := ReadDetailLinkData(input.Id, &event) if err != nil { return nil, err } // STEP 2: Get Simgos - simgos, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + simgos, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -137,7 +129,7 @@ func Update(input e.Encounter) (*d.Data, error) { tx := db.NewTx() err = tx.Simgos.Transaction(func(tx *gorm.DB) error { // Step 2: Update Simgos - if err = UpdateTPendaftaranData(input, *simgos, "update", &event, tx); err != nil { + if err = UpdateTPendaftaranData(input, simgos, "update", &event, tx); err != nil { return err } @@ -173,7 +165,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { } // STEP 2: Get Simgos - sgData, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + sgData, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -226,13 +218,13 @@ func CheckIn(input e.Encounter) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "check-in") // STEP 1: Get Link - syncLink, err := ReadDetailLinkData(uint16(input.Id), &event) + syncLink, err := ReadDetailLinkData(input.Id, &event) if err != nil { return nil, err } // STEP 2: Get Simgos - simgos, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + simgos, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -240,7 +232,7 @@ func CheckIn(input e.Encounter) (*d.Data, error) { tx := db.NewTx() err = tx.Simgos.Transaction(func(tx *gorm.DB) error { // Step 2: Update Simgos - if err = UpdateTPendaftaranData(input, *simgos, "check-in", &event, tx); err != nil { + if err = UpdateTPendaftaranData(input, simgos, "check-in", &event, tx); err != nil { return err } @@ -268,13 +260,13 @@ func CheckOut(input e.Encounter) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "check-out") // STEP 1: Get Link - syncLink, err := ReadDetailLinkData(uint16(input.Id), &event) + syncLink, err := ReadDetailLinkData(input.Id, &event) if err != nil { return nil, err } // STEP 2: Get Simgos - simgos, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + simgos, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -282,7 +274,7 @@ func CheckOut(input e.Encounter) (*d.Data, error) { tx := db.NewTx() err = tx.Simgos.Transaction(func(tx *gorm.DB) error { // Step 2: Update Simgos - if err = UpdateTPendaftaranData(input, *simgos, "check-out", &event, tx); err != nil { + if err = UpdateTPendaftaranData(input, simgos, "check-out", &event, tx); err != nil { return err } @@ -310,13 +302,13 @@ func Cancel(input e.Encounter) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "cancel") // STEP 1: Get Link - syncLink, err := ReadDetailLinkData(uint16(input.Id), &event) + syncLink, err := ReadDetailLinkData(input.Id, &event) if err != nil { return nil, err } // STEP 2: Get Simgos - simgos, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + simgos, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -324,7 +316,7 @@ func Cancel(input e.Encounter) (*d.Data, error) { tx := db.NewTx() err = tx.Simgos.Transaction(func(tx *gorm.DB) error { // Step 2: Update Simgos - if err = UpdateTPendaftaranData(input, *simgos, "update-status", &event, tx); err != nil { + if err = UpdateTPendaftaranData(input, simgos, "update-status", &event, tx); err != nil { return err } @@ -352,13 +344,13 @@ func RequestSwitchUnit(input e.Encounter) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "request-switch-unit") // STEP 1: Get Link - syncLink, err := ReadDetailLinkData(uint16(input.Id), &event) + syncLink, err := ReadDetailLinkData(input.Id, &event) if err != nil { return nil, err } // STEP 2: Get Simgos - tpendaftaran, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + tpendaftaran, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -366,12 +358,12 @@ func RequestSwitchUnit(input e.Encounter) (*d.Data, error) { tx := db.NewTx() err = tx.Simgos.Transaction(func(tx *gorm.DB) error { // Step 2: Update TPendaftaran - if err = UpdateTPendaftaranData(input, *tpendaftaran, "update-status", &event, tx); err != nil { + if err = UpdateTPendaftaranData(input, tpendaftaran, "update-status", &event, tx); err != nil { return err } // Step 3: Insert TPemeriksaanHist - if _, err := CreateBulkTPemeriksaanHistData(input, *tpendaftaran, &event, tx); err != nil { + if _, err := CreateBulkTPemeriksaanHistData(input, tpendaftaran, &event, tx); err != nil { return err } @@ -399,13 +391,13 @@ func ApproveSwitchUnit(input e.Encounter) (*d.Data, error) { pl.SetLogInfo(&event, input, "started", "request-switch-unit") // STEP 1: Get Link - syncLink, err := ReadDetailLinkData(uint16(input.Id), &event) + syncLink, err := ReadDetailLinkData(input.Id, &event) if err != nil { return nil, err } // STEP 2: Get Simgos - tpendaftaran, err := ReadTPendaftaranDetailData(uint16(syncLink.Simgos_Id), &event) + tpendaftaran, err := ReadTPendaftaranDetailData(syncLink.Simgos_Id, &event) if err != nil { return nil, err } @@ -413,12 +405,12 @@ func ApproveSwitchUnit(input e.Encounter) (*d.Data, error) { tx := db.NewTx() err = tx.Simgos.Transaction(func(tx *gorm.DB) error { // Step 2: Update TPendaftaran - if err = UpdateTPendaftaranData(input, *tpendaftaran, "update-status", &event, tx); err != nil { + if err = UpdateTPendaftaranData(input, tpendaftaran, "update-status", &event, tx); err != nil { return err } // Step 3: Insert TPemeriksaanHist - if _, err := CreateBulkTPemeriksaanHistData(input, *tpendaftaran, &event, tx); err != nil { + if _, err := CreateBulkTPemeriksaanHistData(input, tpendaftaran, &event, tx); err != nil { return err } diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go index a64a0c4e..fe1d5b42 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go @@ -6,7 +6,7 @@ package encounter import ( "encoding/json" - epr "simrs-vx/internal/domain/main-entities/person-relative" + epa "simrs-vx/internal/domain/main-entities/person-address" erc "simrs-vx/internal/domain/references/common" ere "simrs-vx/internal/domain/references/encounter" erp "simrs-vx/internal/domain/references/person" @@ -14,6 +14,8 @@ import ( "strconv" e "simrs-vx/internal/domain/main-entities/encounter" + epc "simrs-vx/internal/domain/main-entities/person-contact" + epr "simrs-vx/internal/domain/main-entities/person-relative" ep "simrs-vx/internal/domain/simgos-entities/m-pasien" etph "simrs-vx/internal/domain/simgos-entities/t-pemeriksaan-hist" etp "simrs-vx/internal/domain/simgos-entities/t-pendaftaran" @@ -47,20 +49,29 @@ func setDataCreateTPendaftaran(input *e.Encounter) (data etp.TPendaftaran, err e } data.NoKunjung = uint(noKunjung) - setDataTPendaftaran(input, data) + if p := input.Patient.Person; p != nil { + mapRelative(p.Relatives, &data) + + if data.PenanggungjawabNama == "" { + data.PenanggungjawabHubungan = "DIRI SENDIRI" + data.PenanggungjawabNama = p.Name + mapContact(p.Contacts, &data) + mapAddress(p.Addresses, &data) + } + + if bpjs := p.VclaimMember; bpjs != nil { + data.Nokartu = *bpjs.CardNumber + } + } + + setDataTPendaftaran(input, &data) return } -func setDataTPendaftaran(input *e.Encounter, data etp.TPendaftaran) { +func setDataTPendaftaran(input *e.Encounter, data *etp.TPendaftaran) { data.Tglreg = input.RegisteredAt - // set kddokter - if d := input.Appointment_Doctor_Code; d != nil { - kddokter, _ := strconv.Atoi(*input.Appointment_Doctor_Code) - data.Kddokter = uint(kddokter) - } - // set kdpoly if p := input.Unit_Code; p != nil { kdpoly, _ := strconv.Atoi(*input.Unit_Code) @@ -82,22 +93,18 @@ func setDataTPendaftaran(input *e.Encounter, data etp.TPendaftaran) { } } - if ref := input.VclaimReference; ref != nil { - data.Ketrujuk = *ref.SrcCode - data.Norujukan = *ref.Number - data.Tglrujukan = ref.Date + // set data if payment_method bpjs + if input.RefSource_Name != nil { + data.Ketrujuk = *input.RefSource_Name data.Strujukan = 1 } else { data.Ketrujuk = "TR" data.Strujukan = 0 } - if p := input.Patient.Person; p != nil { - mapRelative(p.Relatives, data) - - if bpjs := p.VclaimMember; bpjs != nil { - data.Nokartu = *bpjs.CardNumber - } + if ref := input.VclaimReference; ref != nil { + data.Norujukan = *ref.Number + data.Tglrujukan = ref.Date } data.Jamreg = input.RegisteredAt @@ -107,7 +114,7 @@ func setDataTPendaftaran(input *e.Encounter, data etp.TPendaftaran) { return } -func setDataCheckIn(input e.Encounter, data etp.TPendaftaran) { +func setDataCheckIn(input e.Encounter, data *etp.TPendaftaran) { // set kddokter kddokter, _ := strconv.Atoi(*input.Responsible_Doctor_Code) data.Kddokter = uint(kddokter) @@ -125,7 +132,7 @@ func setDataCheckIn(input e.Encounter, data etp.TPendaftaran) { return } -func setDataRequestSwitchUnit(input e.Encounter, data etp.TPendaftaran) (hist []etph.TPemeriksaanHist) { +func setDataRequestSwitchUnit(input e.Encounter, data *etp.TPendaftaran) (hist []etph.TPemeriksaanHist) { if enc := input.InternalReferences; enc != nil { for i, ref := range *enc { hist = append(hist, etph.TPemeriksaanHist{ @@ -151,7 +158,7 @@ func setDataRequestSwitchUnit(input e.Encounter, data etp.TPendaftaran) (hist [] return } -func setDataCheckOut(input e.Encounter, data etp.TPendaftaran) { +func setDataCheckOut(input e.Encounter, data *etp.TPendaftaran) { data.Keluarpoly = input.Discharge_Date // set status @@ -169,13 +176,13 @@ func setDataCheckOut(input e.Encounter, data etp.TPendaftaran) { return } -func setDataUpdateStatus(input e.Encounter, data etp.TPendaftaran) { +func setDataUpdateStatus(input e.Encounter, data *etp.TPendaftaran) { if input.Status_Code == erc.DSCCancel { data.Status = 11 } } -func setKdrujuk(input *ere.RefTypeCode, data etp.TPendaftaran) { +func setKdrujuk(input *ere.RefTypeCode, data *etp.TPendaftaran) { switch *input { case ere.RTCGov: data.Kdrujuk = 1 @@ -188,7 +195,7 @@ func setKdrujuk(input *ere.RefTypeCode, data etp.TPendaftaran) { } } -func setKdcarabayar(input ere.AllPaymentMethodCode, data etp.TPendaftaran) { +func setKdcarabayar(input ere.AllPaymentMethodCode, data *etp.TPendaftaran) { switch input { case ere.APMCPks: data.Kdcarabayar = 12 @@ -203,7 +210,7 @@ func setKdcarabayar(input ere.AllPaymentMethodCode, data etp.TPendaftaran) { } } -func setStatus(code *ere.DischargeMethodCode, data etp.TPendaftaran) { +func setStatus(code *ere.DischargeMethodCode, data *etp.TPendaftaran) { switch *code { case ere.DMCHome: data.Status = 1 @@ -250,7 +257,7 @@ func setStatus(code *ere.DischargeMethodCode, data etp.TPendaftaran) { } } -func mapRelative(relative *[]epr.PersonRelative, data etp.TPendaftaran) { +func mapRelative(relative *[]epr.PersonRelative, data *etp.TPendaftaran) { if relative == nil || len(*relative) == 0 { return } @@ -322,10 +329,11 @@ func generateNoKunjung() (int, error) { // Lock rows for this prefix → prevents race condition if err := dg.IS["simrs"]. Table("t_pendaftaran"). - Select("COALESCE(MAX(no_kunjung),0)"). + Select("no_kunjung"). Where("tglreg = CURRENT_DATE"). Order("no_kunjung DESC"). Clauses(clause.Locking{Strength: "UPDATE"}). + Limit(1). Scan(&lastNumber).Error; err != nil { return 0, err } @@ -339,7 +347,7 @@ func stringtouint(v string) *uint { return &point } -func updatePatient(patient ep.MPasien, event *pl.Event, dbx ...*gorm.DB) error { +func updatePatientCaraBayar(input etp.TPendaftaran, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, nil, "started", "DBUpdate") var tx *gorm.DB @@ -350,9 +358,9 @@ func updatePatient(patient ep.MPasien, event *pl.Event, dbx ...*gorm.DB) error { } if err := tx.Model(&ep.MPasien{}). - Where("\"nomr\" = ?", patient.Nomr). + Where("\"nomr\" = ?", input.Nomr). Updates(map[string]interface{}{ - "kdcarabayar": patient.Kdcarabayar, + "kdcarabayar": input.Kdcarabayar, }).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ @@ -360,9 +368,30 @@ func updatePatient(patient ep.MPasien, event *pl.Event, dbx ...*gorm.DB) error { Detail: "Failed to update patient", Raw: err, } - return pl.SetLogError(event, patient) + return pl.SetLogError(event, input) } - pl.SetLogInfo(event, patient, "complete") + pl.SetLogInfo(event, input, "complete") return nil } + +func mapContact(contact *[]epc.PersonContact, data *etp.TPendaftaran) { + if contact == nil || len(*contact) == 0 { + return + } + + for _, c := range *contact { + if c.Type_Code == erp.CTPhone || c.Type_Code == erp.CTMPhone { + data.PenanggungjawabPhone = c.Value + break + } + } +} + +func mapAddress(addresses *[]epa.PersonAddress, data *etp.TPendaftaran) { + if addresses == nil || len(*addresses) == 0 { + return + } + a := (*addresses)[0] + data.PenanggungjawabAlamat = a.Address +} diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/lib.go b/internal/use-case/simgos-sync-use-case/new/encounter/lib.go index 064131e5..3312193d 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/lib.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/lib.go @@ -41,7 +41,7 @@ func CreateTPendaftaranData(input e.Encounter, event *pl.Event, dbx ...*gorm.DB) return &data, nil } -func ReadTPendaftaranDetailData(simgosId uint16, event *pl.Event) (*etp.TPendaftaran, error) { +func ReadTPendaftaranDetailData(simgosId uint, event *pl.Event) (*etp.TPendaftaran, error) { pl.SetLogInfo(event, simgosId, "started", "DBReadDetail") data := etp.TPendaftaran{} @@ -59,7 +59,7 @@ func ReadTPendaftaranDetailData(simgosId uint16, event *pl.Event) (*etp.TPendaft return &data, nil } -func UpdateTPendaftaranData(input e.Encounter, data etp.TPendaftaran, method string, event *pl.Event, dbx ...*gorm.DB) error { +func UpdateTPendaftaranData(input e.Encounter, data *etp.TPendaftaran, method string, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, input, "started", "DBUpdate") switch method { @@ -138,7 +138,7 @@ func CreateLinkData(simxId, simgosId uint, event *pl.Event, dbx ...*gorm.DB) (*e return &data, nil } -func ReadDetailLinkData(simxId uint16, event *pl.Event) (*esync.EncounterLink, error) { +func ReadDetailLinkData(simxId uint, event *pl.Event) (*esync.EncounterLink, error) { pl.SetLogInfo(event, simxId, "started", "DBReadDetail") data := esync.EncounterLink{} @@ -199,7 +199,7 @@ func CreateLogData(input esynclog.SimxLogDto, event *pl.Event, dbx ...*gorm.DB) return nil } -func CreateBulkTPemeriksaanHistData(input e.Encounter, data etp.TPendaftaran, event *pl.Event, dbx ...*gorm.DB) (hist []etph.TPemeriksaanHist, err error) { +func CreateBulkTPemeriksaanHistData(input e.Encounter, data *etp.TPendaftaran, event *pl.Event, dbx ...*gorm.DB) (hist []etph.TPemeriksaanHist, err error) { pl.SetLogInfo(event, nil, "started", "DBCreate") hist = setDataRequestSwitchUnit(input, data) diff --git a/internal/use-case/simgos-sync-use-case/new/patient/helper.go b/internal/use-case/simgos-sync-use-case/new/patient/helper.go index 14f516d5..532574b2 100644 --- a/internal/use-case/simgos-sync-use-case/new/patient/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/patient/helper.go @@ -37,12 +37,15 @@ func setDataSimgos(input *e.Patient) (data esimgos.MPasien) { mapContact(input.Person.Contacts, &data) } - data.PenanggungjawabHubungan = "DIRI SENDIRI" - data.PenanggungjawabNama = input.Person.Name - data.PenanggungjawabPhone = data.Notelp - data.PenanggungjawabAlamat = data.Alamat - if input.Person != nil || input.Person.Relatives != nil { - mapRelative(input.Person.Relatives, &data) + if input.Person != nil { + data.PenanggungjawabHubungan = "DIRI SENDIRI" + data.PenanggungjawabNama = input.Person.Name + data.PenanggungjawabPhone = data.Notelp + data.PenanggungjawabAlamat = data.Alamat + + if input.Person.Relatives != nil { + mapRelative(input.Person.Relatives, &data) + } } data.Nip = input.RegisteredBy_User_Name diff --git a/internal/use-case/simgos-sync-use-case/new/specialist/helper.go b/internal/use-case/simgos-sync-use-case/new/specialist/helper.go index 4a155496..adce079f 100644 --- a/internal/use-case/simgos-sync-use-case/new/specialist/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/specialist/helper.go @@ -14,7 +14,7 @@ import ( esync "simrs-vx/internal/domain/sync-entities/specialist" ) -func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MPolihfis) { +func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T, data *esimgos.MPolihfis) { var inputSrc *e.CreateDto if inputT, ok := any(input).(*e.CreateDto); ok { inputSrc = inputT diff --git a/internal/use-case/simgos-sync-use-case/new/specialist/lib.go b/internal/use-case/simgos-sync-use-case/new/specialist/lib.go index c796af73..0aee2ceb 100644 --- a/internal/use-case/simgos-sync-use-case/new/specialist/lib.go +++ b/internal/use-case/simgos-sync-use-case/new/specialist/lib.go @@ -20,7 +20,8 @@ var now = time.Now() func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esimgos.MPolihfis, error) { pl.SetLogInfo(event, nil, "started", "DBCreate") - data := setDataSimgos(&input) + data := esimgos.MPolihfis{} + setDataSimgos(&input, &data) var tx *gorm.DB if len(dbx) > 0 { @@ -29,7 +30,7 @@ func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esi tx = dg.IS["simrs"] } - if err := tx.Create(&data).Error; err != nil { + if err := tx.Debug().Create(&data).Error; err != nil { return nil, plh.HandleCreateError(input, event, err) } @@ -58,7 +59,9 @@ func ReadDetailSimgosData(simgosId uint16, event *pl.Event) (*esimgos.MPolihfis, func UpdateSimgosData(input e.UpdateDto, dataSimgos *esync.SpecialistLink, event *pl.Event, dbx ...*gorm.DB) error { pl.SetLogInfo(event, input, "started", "DBUpdate") - data := setDataSimgos(&input) + data := esimgos.MPolihfis{} + + setDataSimgos(&input, &data) data.Id = dataSimgos.Simgos_Id var tx *gorm.DB diff --git a/internal/use-case/simgos-sync-use-case/new/unit/helper.go b/internal/use-case/simgos-sync-use-case/new/unit/helper.go index 667bb7f0..d7dfb1f6 100644 --- a/internal/use-case/simgos-sync-use-case/new/unit/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/unit/helper.go @@ -7,6 +7,7 @@ package unit import ( "encoding/json" erc "simrs-vx/internal/domain/references/common" + "strconv" e "simrs-vx/internal/domain/main-entities/unit" @@ -27,6 +28,8 @@ func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MPoly) data.Nama = inputSrc.Name data.Jenispoly = 0 + kodePoly, _ := strconv.Atoi(inputSrc.Code) + data.Kode = uint(kodePoly) return } From dfce53946bba40a46f8047f6755fe376e914fbc6 Mon Sep 17 00:00:00 2001 From: vanilia Date: Tue, 25 Nov 2025 19:53:37 +0700 Subject: [PATCH 2/7] add nurse in encounter --- cmd/main-migration/migrations/20251125125303.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 5 +++-- internal/domain/main-entities/encounter/entity.go | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 cmd/main-migration/migrations/20251125125303.sql diff --git a/cmd/main-migration/migrations/20251125125303.sql b/cmd/main-migration/migrations/20251125125303.sql new file mode 100644 index 00000000..56d16371 --- /dev/null +++ b/cmd/main-migration/migrations/20251125125303.sql @@ -0,0 +1,2 @@ +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "Responsible_Nurse_Code" character varying(20) NULL, ADD CONSTRAINT "fk_Encounter_Responsible_Nurse" FOREIGN KEY ("Responsible_Nurse_Code") REFERENCES "public"."Nurse" ("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 707ee3ca..719dffff 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:87NyL1nIRuVvOiLbfdC1+PF+v2R/joAnBYyh2CrlGdU= +h1:u2pc+PayIbiG5HRFUzun7cApIwlt9SMNTl74DtPz1xg= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -128,4 +128,5 @@ h1:87NyL1nIRuVvOiLbfdC1+PF+v2R/joAnBYyh2CrlGdU= 20251120005512.sql h1:Ek6qpacAI/qVuTYxKno+uJyzn7s5z9pf3t7VA8gTzm4= 20251120074415.sql h1:NNUeJVA03EeBHJhHqPXEZoDv/PnC6yK1/cRhmukyaJo= 20251121033803.sql h1:/vfvFX/3pzSCIHnSbMUT9EMBDykOpVkvyfeTEle9Vas= -20251124071457.sql h1:HBaNJQIzUe6wK8CgBxamuKor7ZiAASzgkkXzL6kWsjY= +20251124071457.sql h1:qg2dhCL9YwD13xnfJ175lW/p6MGfzFKaBqd908FByRc= +20251125125303.sql h1:P94UsZOeo7b0r2yLoSGBfj0+PcMTf4Y10lF+Rl9FxAE= diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index 61496f9e..08f3aa89 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -20,6 +20,7 @@ import ( eip "simrs-vx/internal/domain/main-entities/inpatient" ei "simrs-vx/internal/domain/main-entities/insurance-company" eir "simrs-vx/internal/domain/main-entities/internal-reference" + en "simrs-vx/internal/domain/main-entities/nurse" ep "simrs-vx/internal/domain/main-entities/patient" er "simrs-vx/internal/domain/main-entities/rehab/base" es "simrs-vx/internal/domain/main-entities/specialist" @@ -77,6 +78,8 @@ type Encounter struct { EncounterDocuments *[]eed.EncounterDocument `json:"encounterDocuments,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` GeneralConsents *[]egc.GeneralConsent `json:"generalConsents,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` VclaimReference *evr.VclaimReference `json:"vclaimReference,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` + Responsible_Nurse_Code *string `json:"responsible_nurse_code"` + Responsible_Nurse *en.Nurse `json:"responsible_nurse,omitempty" gorm:"foreignKey:Responsible_Nurse_Code;references:Code"` } func (d Encounter) IsDone() bool { From 94dbb8624f431daab0b0499fb0a0ffc450752346 Mon Sep 17 00:00:00 2001 From: vanilia Date: Wed, 26 Nov 2025 13:41:26 +0700 Subject: [PATCH 3/7] adjust table internalreference --- .../migrations/20251126064057.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 5 +++-- .../internal-reference/entity.go | 19 +++++++++++++------ internal/domain/references/common/common.go | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 cmd/main-migration/migrations/20251126064057.sql diff --git a/cmd/main-migration/migrations/20251126064057.sql b/cmd/main-migration/migrations/20251126064057.sql new file mode 100644 index 00000000..fd823ff9 --- /dev/null +++ b/cmd/main-migration/migrations/20251126064057.sql @@ -0,0 +1,2 @@ +-- Modify "InternalReference" table +ALTER TABLE "public"."InternalReference" ADD COLUMN "SrcDoctor_Code" character varying(20) NULL, ADD COLUMN "SrcNurse_Code" character varying(20) NULL, ADD COLUMN "Nurse_Code" character varying(20) NULL, ADD CONSTRAINT "fk_InternalReference_Nurse" FOREIGN KEY ("Nurse_Code") REFERENCES "public"."Nurse" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_InternalReference_SrcDoctor" FOREIGN KEY ("SrcDoctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_InternalReference_SrcNurse" FOREIGN KEY ("SrcNurse_Code") REFERENCES "public"."Nurse" ("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 719dffff..363efe04 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:u2pc+PayIbiG5HRFUzun7cApIwlt9SMNTl74DtPz1xg= +h1:U9vdficFramvwnH40psSuRxzUuq6EPJwLcr9MvVTq7s= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -129,4 +129,5 @@ h1:u2pc+PayIbiG5HRFUzun7cApIwlt9SMNTl74DtPz1xg= 20251120074415.sql h1:NNUeJVA03EeBHJhHqPXEZoDv/PnC6yK1/cRhmukyaJo= 20251121033803.sql h1:/vfvFX/3pzSCIHnSbMUT9EMBDykOpVkvyfeTEle9Vas= 20251124071457.sql h1:qg2dhCL9YwD13xnfJ175lW/p6MGfzFKaBqd908FByRc= -20251125125303.sql h1:P94UsZOeo7b0r2yLoSGBfj0+PcMTf4Y10lF+Rl9FxAE= +20251125125303.sql h1:4JSFv1Pmhbe9tqpLXgO63OwYnGsalStgUXKVWPyc1YE= +20251126064057.sql h1:+lByIo0zAsHVSFzQGVMuymFQajyl7fRNqgs9d/76y+E= diff --git a/internal/domain/main-entities/internal-reference/entity.go b/internal/domain/main-entities/internal-reference/entity.go index ae6307bb..90859710 100644 --- a/internal/domain/main-entities/internal-reference/entity.go +++ b/internal/domain/main-entities/internal-reference/entity.go @@ -5,15 +5,22 @@ import ( ecore "simrs-vx/internal/domain/base-entities/core" ed "simrs-vx/internal/domain/main-entities/doctor" + en "simrs-vx/internal/domain/main-entities/nurse" eu "simrs-vx/internal/domain/main-entities/unit" ) type InternalReference struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Unit_Code *string `json:"unit_code"` - 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_Code;references:Code"` - Status_Code *erc.DataApprovalCode `json:"status_code"` + Encounter_Id *uint `json:"encounter_id"` + Unit_Code *string `json:"unit_code"` + 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_Code;references:Code"` + Status_Code *erc.DataApprovalCode `json:"status_code"` + SrcDoctor_Code *string `json:"srcDoctor_code"` + SrcDoctor *ed.Doctor `json:"srcDoctor,omitempty" gorm:"foreignKey:SrcDoctor_Code;references:Code"` + SrcNurse_Code *string `json:"srcNurse_code"` + SrcNurse *en.Nurse `json:"srcNurse,omitempty" gorm:"foreignKey:SrcNurse_Code;references:Code"` + Nurse_Code *string `json:"nurse_code"` + Nurse *en.Nurse `json:"nurse,omitempty" gorm:"foreignKey:Nurse_Code;references:Code"` } diff --git a/internal/domain/references/common/common.go b/internal/domain/references/common/common.go index 96febd75..3a449057 100644 --- a/internal/domain/references/common/common.go +++ b/internal/domain/references/common/common.go @@ -106,6 +106,7 @@ const ( DACNew DataApprovalCode = "new" DACApproved DataApprovalCode = "approved" DACRejected DataApprovalCode = "rejected" + DACCanceled DataApprovalCode = "canceled" PSCSuccess ProcessStatusCode = "success" PSCFailed ProcessStatusCode = "failed" From f2bedd0de88d9506cd67bda027323e5141f40268 Mon Sep 17 00:00:00 2001 From: vanilia Date: Wed, 26 Nov 2025 18:56:30 +0700 Subject: [PATCH 4/7] add internalreference sync --- .../migrations/20251126115527.sql | 36 +++++++++++++++++++ .../migrations/atlas.sum | 7 ++-- .../internal-reference/entity.go | 29 +++++++++++++++ .../migration/simgossync-entities.go | 4 +++ 4 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 cmd/simgos-sync-migration/migrations/20251126115527.sql create mode 100644 internal/domain/sync-entities/internal-reference/entity.go diff --git a/cmd/simgos-sync-migration/migrations/20251126115527.sql b/cmd/simgos-sync-migration/migrations/20251126115527.sql new file mode 100644 index 00000000..49ca1e5c --- /dev/null +++ b/cmd/simgos-sync-migration/migrations/20251126115527.sql @@ -0,0 +1,36 @@ +-- Create "InternalReferenceLink" table +CREATE TABLE "public"."InternalReferenceLink" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Simx_Id" bigint NULL, + "Simgos_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_InternalReferenceLink_Simgos_Id" UNIQUE ("Simgos_Id"), + CONSTRAINT "uni_InternalReferenceLink_Simx_Id" UNIQUE ("Simx_Id") +); +-- Create "InternalReferenceSimgosLog" table +CREATE TABLE "public"."InternalReferenceSimgosLog" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Value" text NULL, + "Date" timestamptz NULL, + "Status" text NULL, + "ErrMessage" text NULL, + PRIMARY KEY ("Id") +); +-- Create "InternalReferenceSimxLog" table +CREATE TABLE "public"."InternalReferenceSimxLog" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Value" text NULL, + "Date" timestamptz NULL, + "Status" text NULL, + "ErrMessage" text NULL, + PRIMARY KEY ("Id") +); diff --git a/cmd/simgos-sync-migration/migrations/atlas.sum b/cmd/simgos-sync-migration/migrations/atlas.sum index 07e5fbaf..497ac414 100644 --- a/cmd/simgos-sync-migration/migrations/atlas.sum +++ b/cmd/simgos-sync-migration/migrations/atlas.sum @@ -1,6 +1,7 @@ -h1:keVmwgYtvwxSqkq+7nB0BA25JFYRAVBpBBu5eA4Q9Hw= +h1:UdPzQZ17yyNN9HVuyrFFHj5KjLj4m6/e7s9frkdpQVU= 20251113035508.sql h1:rjDlu6yDdy5xv6nrCOr7NialrLSLT23pzduYNq29Hf0= 20251114071129.sql h1:Z0GQ5bJo3C+tplaWzxT8n3J9HLkEaVsRVp5nn7bmYow= 20251117041601.sql h1:l/RPG5mObqCSBjO4mzG+wTq2ieSycvlfOSz4czpUdWY= -20251118082246.sql h1:VFnYls2DBC8tJm2aw0iBcbWGLsKezYdOHJJV9iS7MjI= -20251118082915.sql h1:tAm67fXrH+8IJCjKbJroIqc1uQyqCnuGJnQtLmw7D20= +20251118082246.sql h1:xLUwA+EvKWIg3X/TJvu7rqbtBzONiINfag5NJpMV29E= +20251118082915.sql h1:hP6FmUVFuADIN2cDg2Z1l7Wx7PQRb+IYQDvKD7J8VAM= +20251126115527.sql h1:+2bp2nWTTqaPpKKfy5ZYSr6b1nEUXFG3tIw4r3OEnAQ= diff --git a/internal/domain/sync-entities/internal-reference/entity.go b/internal/domain/sync-entities/internal-reference/entity.go new file mode 100644 index 00000000..567e6489 --- /dev/null +++ b/internal/domain/sync-entities/internal-reference/entity.go @@ -0,0 +1,29 @@ +package internal_reference + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + erc "simrs-vx/internal/domain/references/common" + "time" +) + +type InternalReferenceLink struct { + ecore.Main + Simx_Id uint `json:"simx_id" gorm:"unique"` + Simgos_Id uint `json:"simgos_id" gorm:"unique"` +} + +type InternalReferenceSimxLog struct { + ecore.Main + Value *string `json:"value"` + Date *time.Time `json:"date"` + Status erc.ProcessStatusCode `json:"status"` + ErrMessage *string `json:"errMessage"` +} + +type InternalReferenceSimgosLog struct { + ecore.Main + Value *string `json:"value"` + Date *time.Time `json:"date"` + Status erc.ProcessStatusCode `json:"status"` + ErrMessage *string `json:"errMessage"` +} diff --git a/internal/interface/migration/simgossync-entities.go b/internal/interface/migration/simgossync-entities.go index b10c8607..7b37a842 100644 --- a/internal/interface/migration/simgossync-entities.go +++ b/internal/interface/migration/simgossync-entities.go @@ -5,6 +5,7 @@ import ( division "simrs-vx/internal/domain/sync-entities/division" encounter "simrs-vx/internal/domain/sync-entities/encounter" installation "simrs-vx/internal/domain/sync-entities/installation" + internalreference "simrs-vx/internal/domain/sync-entities/internal-reference" patient "simrs-vx/internal/domain/sync-entities/patient" specialist "simrs-vx/internal/domain/sync-entities/specialist" subspecialist "simrs-vx/internal/domain/sync-entities/subspecialist" @@ -34,5 +35,8 @@ func getSyncEntities() []any { &encounter.EncounterLink{}, &encounter.EncounterSimxLog{}, &encounter.EncounterSimgosLog{}, + &internalreference.InternalReferenceLink{}, + &internalreference.InternalReferenceSimxLog{}, + &internalreference.InternalReferenceSimgosLog{}, } } From f13a45119b75446a075e13b8696f60508ac12c73 Mon Sep 17 00:00:00 2001 From: vanilia Date: Thu, 27 Nov 2025 11:43:42 +0700 Subject: [PATCH 5/7] fix import sequential --- internal/use-case/simgos-sync-use-case/new/encounter/helper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go index 1d48ea97..bbbc8687 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go @@ -6,7 +6,6 @@ package encounter import ( "encoding/json" - epa "simrs-vx/internal/domain/main-entities/person-address" erc "simrs-vx/internal/domain/references/common" ere "simrs-vx/internal/domain/references/encounter" erp "simrs-vx/internal/domain/references/person" @@ -14,6 +13,7 @@ import ( "strconv" e "simrs-vx/internal/domain/main-entities/encounter" + epa "simrs-vx/internal/domain/main-entities/person-address" epc "simrs-vx/internal/domain/main-entities/person-contact" epr "simrs-vx/internal/domain/main-entities/person-relative" ep "simrs-vx/internal/domain/simgos-entities/m-pasien" From 7c454a7c0d2c0803f3244b9b2217eb3b6442daba Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 27 Nov 2025 12:04:52 +0700 Subject: [PATCH 6/7] migration from server --- cmd/main-migration/migrations/atlas.sum | 114 ++++++++++++------------ 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 363efe04..449ff1d4 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:U9vdficFramvwnH40psSuRxzUuq6EPJwLcr9MvVTq7s= +h1:Y8m8OmsumTaAfXfYYXHlZS0+OqbAqFfM3a55nmibOUE= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,59 +75,59 @@ h1:U9vdficFramvwnH40psSuRxzUuq6EPJwLcr9MvVTq7s= 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:232T2x8xTczJl9nk4jxJpZXhoOGYthhxjJ7nK8Jd8vg= -20251110062042.sql h1:WnfVUXrzYoj8qdkkjO9/JQQ8agGd4GfSHQdMjo7LDAg= -20251110063202.sql h1:hSzGfwVMWa6q3vwIQZUkxKgBNCzHjB+6GKy54zfV+oQ= -20251110063633.sql h1:/VpofIAqNS1CnazEnpW/+evbzn9Kew3xDW48r57M+Xg= -20251110085551.sql h1:bFZwSmfvVbTUr/enWB82WqjG88gpqcZ6s45btUvO0uo= -20251110091516.sql h1:KkJMwPQuaZQhiqnKrNQrgP12gw9rV8T3P2o3mtGTcvY= -20251110091948.sql h1:I4odAYrJdvNf1jPw6ppDC0XdI7v6vKBACg/ABwUgA7I= -20251110092729.sql h1:l1out8soEmVP6dNjaIOtGYo6QDcoJZRI8X1sjZ5ZGmo= -20251110093522.sql h1:nsz8jCxGjEdr/bz9g+4ozfZzIP803xONjVmucad1GMc= -20251110100258.sql h1:IBqt1VZj5WjQ+l9aAFGHOCCBtzb03KlLLihFLut7itg= -20251110100545.sql h1:6/LV7751iyKxE2xI6vO1zly+aHUwxXD/IBwLcVpKxqM= -20251110155448.sql h1:kFPobJB+cpflsXBAWUwy3lohuWvrb/VRlXnhJWl7i3Y= -20251111072601.sql h1:ch8F+yVhsSM5xY+TwMLY3PxdLa4Wuhtj76oyw79R7Js= -20251111073546.sql h1:cCv0NPscADAOBahRVqtDWFs6G2t7n+4a+RwlF8vk/c4= -20251111074148.sql h1:70TsV83u1gQ5TktI13K7NQiyCCa35Td2aR6CNtKUa4U= -20251111074652.sql h1:ddfQ/sRKMezPM75xBFTGytUQX5AwZ3znrJVpg73gKPA= -20251111082257.sql h1:ZsdLY1ROouos0l3oS0lkeSiuKLEUGbVvBhpcM2AVhkw= -20251111111017.sql h1:qrJ93dNtQwcuAvpsP/lAK/H63C4cinXrsVaPmWsTqkU= -20251113101344.sql h1:xaOZvAUP1fFfnO+syEFOzJUIg5lTfBe5AWHPbBWuCLA= -20251113120533.sql h1:f3/U1Ve2yF2zSMhkt+xtwF8wUYfUKYwgbNeGfE37EW4= -20251114062746.sql h1:FInLaEFQByESEwFJKuKnuUSTKmcDpi3ZXaxkKwz2+D8= -20251117005942.sql h1:wD3BWrUSmo1HlW16V3lkaBkJvbAZ0fNk77te7J9NhOc= -20251117075427.sql h1:TqU9VKZa3I8YNXUGQWY3WVBYN+1FvyyaKy0hB1jgAho= -20251118074929.sql h1:p1KsWqCuR1JXA/jVO5BmOhCcaQ8clT7t0YRszAhPFbg= -20251119063438.sql h1:NVGM0X/LHD37EaPl8SNzkNiZDJ7AB1QR+LLwLh6WRdg= -20251119065730.sql h1:U5lzk1WvMB0bw3kwckou7jkEt4bwdYItwHr2Vxqe7w4= -20251119072302.sql h1:qCuI2WMEMF/XNbjV+RXPjBnuCKLu1Fia+mR9HiLWBIs= -20251119072450.sql h1:Xg+bTwqGyKPNFEQhJylvpz1wifdfmDJvcAq6vmNf0Ng= -20251120005512.sql h1:Ek6qpacAI/qVuTYxKno+uJyzn7s5z9pf3t7VA8gTzm4= -20251120074415.sql h1:NNUeJVA03EeBHJhHqPXEZoDv/PnC6yK1/cRhmukyaJo= -20251121033803.sql h1:/vfvFX/3pzSCIHnSbMUT9EMBDykOpVkvyfeTEle9Vas= -20251124071457.sql h1:qg2dhCL9YwD13xnfJ175lW/p6MGfzFKaBqd908FByRc= -20251125125303.sql h1:4JSFv1Pmhbe9tqpLXgO63OwYnGsalStgUXKVWPyc1YE= -20251126064057.sql h1:+lByIo0zAsHVSFzQGVMuymFQajyl7fRNqgs9d/76y+E= +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= +20251110085551.sql h1:HZcJM0RSC6HBaUSjKBE8MgDG8Vn9f3LmwA/OnT9Cp7I= +20251110091516.sql h1:W3AQhQLgirEWuCObbLl+Prdrbq6k6EEY1xcoWsmbog4= +20251110091948.sql h1:3tsITMrZr/T+L4wqUMz8sHS229jCJl4T0Nu3dMccxH8= +20251110092729.sql h1:uU+k88RH/e0Ns4/SmJl03RVYPscBAPuiLfxR6CJqaf0= +20251110093522.sql h1:O7upSj8VNjzvroL4IU59bfxKATOkAVGBArcUbVNq9aM= +20251110100258.sql h1://JSArUMNI3/gAtYDx2VN94C198SFW0ANjgs+p6eCRM= +20251110100545.sql h1:ENPOqeJYRpMI4e8VCKwaQgaql8se6pIidAhG2cjskBg= +20251110155448.sql h1:VW9KE0jxWy4flZ28sdXmhY6JWd6eKAX/cVL8KWRVii4= +20251111072601.sql h1:99WWzGjcDDFNC2cHRfPu4MBLWNrgPMY5HAYUbmIcVRA= +20251111073546.sql h1:iIGwFNfUgStdczw/PXTH3SD84xAyxrbZICofc3M8TMk= +20251111074148.sql h1:mzkezSKwCV2bTZ/0BHiTCX5qAy4uHpwar1xzwAH15Ko= +20251111074652.sql h1:lYh4/3BHV24pgPC0pP4RUKb+XtL/6AsZGPItRpnzBiQ= +20251111082257.sql h1:+cIZ1lf8HYGSL6t6U88plLKk8nOO1YVdV7h3YOM84ds= +20251111111017.sql h1:xzlhR2xLfOj4ddYlesS+bpEeDrxiAf5ILNOspsbZjBU= +20251113101344.sql h1:vSzThY3p6XYTj0dJ2uFVkHmlytyrFAnGE58CJLx364I= +20251113120533.sql h1:lfjgdqRGo/EohrVw8sWlFbDjh3ASTsfQ6pr3qjafqvc= +20251114062746.sql h1:6DLYjfJ60PkAABZTXvOwSE+xrU25oyoX7gpYlBnA9cw= +20251117005942.sql h1:0XoJKca8IOaB9QKFVF/qPY7jKcIgh6m/LODQuE06SAs= +20251117075427.sql h1:LhY2urosfoSu1/vkHmgsNP4JA4DuWBs9gL59yMqcF8M= +20251118074929.sql h1:3RWBD6BziQVw6WSfthgoVuhTELHER9NrIuZm4hY/F1A= +20251119063438.sql h1:EVTG3ZrHjCmM95YPASZTRPiwHrG6e33A2vO4hLSAaBQ= +20251119065730.sql h1:s98wnZOCW6NbnwDS3H53XIQ60u6B9bDwBLNvy5+Rn64= +20251119072302.sql h1:ZL+VHekLYqgNtOFKlj02WHrAk11dtTxQkmyTKE8IOzY= +20251119072450.sql h1:SiJy2vpSvoPFw4J1SW7HjGSJzrqR62NsjRYAeabV+kc= +20251120005512.sql h1:hJUaWXYJ3HiSquBTw8OKhymjA4O43ehAMGfiOY8W87Q= +20251120074415.sql h1:dNmcqZHqfZwi/wtYvO/pSFgImN2scXL0p/7g0+HLp0s= +20251121033803.sql h1:onlddYGo+tQdGaEdJPqdsx3sncGnwEvqMSCksF6vjjI= +20251124071457.sql h1:ikQLIXFikUbkUd55uJBmEvqLGEC9t0db+Om4TQsWP7M= +20251125125303.sql h1:OLKbNPO36AHtIDursW9AeBvf60sahQKC1iOjHmpx0MA= +20251126064057.sql h1:6al3PTWbw/WGiBcrRrVWppOMLtG+eRaH/qSLbnmh1kQ= From 708bceccdd61348279ed83a6bd4477c7bd29f5af Mon Sep 17 00:00:00 2001 From: vanilia Date: Fri, 28 Nov 2025 16:43:01 +0700 Subject: [PATCH 7/7] validate auth from old app and fill auth info --- cmd/main-api/config.yml-example | 3 +- internal/infra/sync-cfg/tycovar.go | 4 +- internal/infra/sync-consumer-cfg/tycovar.go | 5 +- .../main-handler/authentication/handler.go | 36 +++-- .../simgos-sync-handler.go | 2 +- .../main-use-case/authentication/case.go | 4 +- .../main-use-case/authentication/helper.go | 73 ++++++++- .../simgos-sync-plugin/new/division/plugin.go | 140 +----------------- .../new/installation/plugin.go | 140 +----------------- .../simgos-sync-plugin/new/patient/plugin.go | 135 +---------------- .../new/specialist/plugin.go | 140 +----------------- .../new/subspecialist/plugin.go | 140 +----------------- .../simgos-sync-plugin/new/unit/plugin.go | 140 +----------------- .../new/encounter/helper.go | 4 +- pkg/dualtrx-helper/dualtrx-helper.go | 5 +- 15 files changed, 138 insertions(+), 833 deletions(-) diff --git a/cmd/main-api/config.yml-example b/cmd/main-api/config.yml-example index 3f5caa33..5915c46c 100644 --- a/cmd/main-api/config.yml-example +++ b/cmd/main-api/config.yml-example @@ -72,7 +72,8 @@ syncUrlCfg: enable: false targetHost: prefix: new-to-old - source: new-app + oldSource: new-app + newSource: new-app secretKey: new-world-order!! docsCfg: diff --git a/internal/infra/sync-cfg/tycovar.go b/internal/infra/sync-cfg/tycovar.go index ebc3ca19..a7534f82 100644 --- a/internal/infra/sync-cfg/tycovar.go +++ b/internal/infra/sync-cfg/tycovar.go @@ -1,9 +1,9 @@ package synccfg -var O PartnerCfg = PartnerCfg{} // old +var O SyncPartnerCfg = SyncPartnerCfg{} // old // Used by sync itself, so any partner should be stated here -type PartnerCfg struct { +type SyncPartnerCfg struct { OldSource string `yaml:"oldSource"` OldSecretKey string `yaml:"oldSecretKey"` OldHost string `yaml:"oldHost"` diff --git a/internal/infra/sync-consumer-cfg/tycovar.go b/internal/infra/sync-consumer-cfg/tycovar.go index 1a5cba26..f60cc588 100644 --- a/internal/infra/sync-consumer-cfg/tycovar.go +++ b/internal/infra/sync-consumer-cfg/tycovar.go @@ -1,11 +1,12 @@ package synccfg -var O SyncUrlCfg = SyncUrlCfg{} // old +var O SyncUrlCfg = SyncUrlCfg{} // new type SyncUrlCfg struct { Prefix string `yaml:"prefix"` TargetHost string `yaml:"targetHost"` Enable bool `yaml:"enable"` - Source string `yaml:"source"` + OldSource string `yaml:"oldSource"` + NewSource string `yaml:"newSource"` SecretKey string `yaml:"secretKey"` } diff --git a/internal/interface/main-handler/authentication/handler.go b/internal/interface/main-handler/authentication/handler.go index f0625af7..ffaf145b 100644 --- a/internal/interface/main-handler/authentication/handler.go +++ b/internal/interface/main-handler/authentication/handler.go @@ -9,12 +9,13 @@ import ( sp "github.com/karincake/semprit" sr "github.com/karincake/serabi" + is "simrs-vx/internal/infra/sync-consumer-cfg" + pa "simrs-vx/internal/lib/auth" + m "simrs-vx/internal/domain/main-entities/user" mf "simrs-vx/internal/domain/main-entities/user-fes" - pa "simrs-vx/internal/lib/auth" - s "simrs-vx/internal/use-case/main-use-case/authentication" - esga "simrs-vx/internal/domain/sync-entities/authentication" + s "simrs-vx/internal/use-case/main-use-case/authentication" ) func Login(w http.ResponseWriter, r *http.Request) { @@ -68,6 +69,10 @@ func Logout(w http.ResponseWriter, r *http.Request) { } func GuardMW(next http.Handler) http.Handler { + var ( + accessDetail *pa.AuthInfo + err error + ) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Check if it's from sync credential := esga.CredentialDto{} @@ -75,23 +80,26 @@ func GuardMW(next http.Handler) http.Handler { credential.SecretKey = r.Header.Get("X-Sync-SecretKey") credential.UserName = r.Header.Get("X-Sync-UserName") if credential.Source != "" || credential.SecretKey != "" || credential.UserName != "" { - // TODO: ngecall fungsi untuk dapat dari DB menlengkapi authinfo - accessDetail, err := s.GetAuthInfoByUserName(credential.UserName) + // validate secretKey and source + if credential.SecretKey != is.O.SecretKey || credential.Source != is.O.OldSource { + rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": "invalid consumer credential"}, nil) + return + } + + accessDetail, err = s.GetAuthInfoByUserName(credential.UserName) + if err != nil { + rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil) + return + } + } else { + // Normal flow goes here + accessDetail, err = s.ExtractToken(r, s.AccessToken) if err != nil { rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil) return } - ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail) - next.ServeHTTP(w, r.WithContext(ctx)) - return } - // Normal flow goes here - accessDetail, err := s.ExtractToken(r, s.AccessToken) - if err != nil { - rw.WriteJSON(w, http.StatusUnauthorized, err.(d.FieldError), nil) - return - } ctx := context.WithValue(r.Context(), pa.AuthKey{}, accessDetail) next.ServeHTTP(w, r.WithContext(ctx)) }) diff --git a/internal/interface/simgos-sync-handler/simgos-sync-handler.go b/internal/interface/simgos-sync-handler/simgos-sync-handler.go index 81b1c48b..f120b1cb 100644 --- a/internal/interface/simgos-sync-handler/simgos-sync-handler.go +++ b/internal/interface/simgos-sync-handler/simgos-sync-handler.go @@ -6,7 +6,7 @@ import ( /******************** infra ********************/ gs "simrs-vx/internal/infra/gorm-setting" simgosdb "simrs-vx/internal/infra/simgos-db" - sync "simrs-vx/internal/infra/sync-consumer-cfg" + sync "simrs-vx/internal/infra/sync-cfg" /******************** pkg ********************/ cmw "simrs-vx/pkg/cors-manager-mw" diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 2f47c43d..04a88c9b 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -180,9 +180,7 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode } func GetAuthInfoByUserName(userName string) (data *pa.AuthInfo, err error) { - // disini isi var `data` - // return error jika terjadi apa2 - return + return getAuthByUserName(userName) } func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) { diff --git a/internal/use-case/main-use-case/authentication/helper.go b/internal/use-case/main-use-case/authentication/helper.go index 7af3afa5..d8c54751 100644 --- a/internal/use-case/main-use-case/authentication/helper.go +++ b/internal/use-case/main-use-case/authentication/helper.go @@ -2,6 +2,7 @@ package authentication import ( "fmt" + pa "simrs-vx/internal/lib/auth" "strconv" "time" @@ -10,10 +11,13 @@ import ( dg "github.com/karincake/apem/db-gorm-pg" ms "github.com/karincake/apem/ms-redis" d "github.com/karincake/dodol" + gh "github.com/karincake/getuk" l "github.com/karincake/lepet" pl "simrs-vx/pkg/logger" + erg "simrs-vx/internal/domain/references/organization" + edp "simrs-vx/internal/domain/main-entities/division-position" ed "simrs-vx/internal/domain/main-entities/doctor" ee "simrs-vx/internal/domain/main-entities/employee" @@ -26,7 +30,6 @@ import ( essp "simrs-vx/internal/domain/main-entities/subspecialist-position" eup "simrs-vx/internal/domain/main-entities/unit-position" eu "simrs-vx/internal/domain/main-entities/user" - erg "simrs-vx/internal/domain/references/organization" udp "simrs-vx/internal/use-case/main-use-case/division-position" uip "simrs-vx/internal/use-case/main-use-case/installation-position" @@ -334,3 +337,71 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out return nil } + +func getAuthByUserName(username string) (auth *pa.AuthInfo, err error) { + // get employee + emp := ee.Employee{} + if err = dg.I. + Joins(`JOIN "User" u ON u."Id" = "Employee"."User_Id"`). + Where(`u."Name" = ?`, username). + Scopes(gh.Preload("User")). + First(&emp).Error; err != nil { + return nil, err + } + + auth = &pa.AuthInfo{ + User_Id: *emp.User_Id, + User_Name: emp.User.Name, + User_ContractPosition_Code: string(emp.User.ContractPosition_Code), + Employee_Position_Code: strPtr(string(*emp.Position_Code)), + Employee_Id: &emp.Id, + Sync: true, + } + + // set map table + tableMap := map[erg.EmployeePositionCode]string{ + erg.EPCDoc: "Doctor", + erg.EPCNur: "Nurse", + erg.EPCMwi: "Midwife", + erg.EPCNut: "Nutritionist", + erg.EPCLab: "Laborant", + erg.EPCPha: "Pharmachist", + } + + table := tableMap[*emp.Position_Code] + if table == "" { + return + } + + type CodeResult struct { + Code string + } + var result CodeResult + + err = dg.I.Table(table). + Select("Code"). + Where("\"Employee_Id\" = ?", emp.Id). + First(&result).Error + if err != nil { + return nil, err + } + + // set map for code + setterMap := map[erg.EmployeePositionCode]func(string){ + erg.EPCDoc: func(v string) { auth.Doctor_Code = &v }, + erg.EPCNur: func(v string) { auth.Nurse_Code = &v }, + erg.EPCMwi: func(v string) { auth.Midwife_Code = &v }, + erg.EPCNut: func(v string) { auth.Nutritionist_Code = &v }, + erg.EPCLab: func(v string) { auth.Laborant_Code = &v }, + erg.EPCPha: func(v string) { auth.Pharmachist_Code = &v }, + } + + setter := setterMap[*emp.Position_Code] + setter(result.Code) + + return +} + +func strPtr(s string) *string { + return &s +} diff --git a/internal/use-case/simgos-sync-plugin/new/division/plugin.go b/internal/use-case/simgos-sync-plugin/new/division/plugin.go index b67f19d6..f4d6a34b 100644 --- a/internal/use-case/simgos-sync-plugin/new/division/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/division/plugin.go @@ -1,165 +1,35 @@ package division import ( - "bytes" - "encoding/json" "fmt" - "io" - "net/http" + helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" sync "simrs-vx/internal/infra/sync-consumer-cfg" e "simrs-vx/internal/domain/main-entities/division" elog "simrs-vx/internal/domain/sync-entities/log" - - d "github.com/karincake/dodol" ) func Create(input *e.CreateDto) error { - endpoint := getPrefixEndpoint() - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) } func CreateLog(input *elog.SimxLogDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := prefixEndpoint + "/log" - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", endpoint) } func Update(input *e.UpdateDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "PATCH", endpoint) } func Delete(input *e.DeleteDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "DELETE", endpoint) } func getPrefixEndpoint() string { diff --git a/internal/use-case/simgos-sync-plugin/new/installation/plugin.go b/internal/use-case/simgos-sync-plugin/new/installation/plugin.go index 6f1c12d6..40f0c153 100644 --- a/internal/use-case/simgos-sync-plugin/new/installation/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/installation/plugin.go @@ -1,165 +1,35 @@ package installation import ( - "bytes" - "encoding/json" "fmt" - "io" - "net/http" sync "simrs-vx/internal/infra/sync-consumer-cfg" + helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" e "simrs-vx/internal/domain/main-entities/installation" elog "simrs-vx/internal/domain/sync-entities/log" - - d "github.com/karincake/dodol" ) func Create(input *e.CreateDto) error { - endpoint := getPrefixEndpoint() - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) } func CreateLog(input *elog.SimxLogDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := prefixEndpoint + "/log" - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", endpoint) } func Update(input *e.UpdateDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "PATCH", endpoint) } func Delete(input *e.DeleteDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "DELETE", endpoint) } func getPrefixEndpoint() string { diff --git a/internal/use-case/simgos-sync-plugin/new/patient/plugin.go b/internal/use-case/simgos-sync-plugin/new/patient/plugin.go index 6f03299a..7678da47 100644 --- a/internal/use-case/simgos-sync-plugin/new/patient/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/patient/plugin.go @@ -1,11 +1,11 @@ package patient import ( - "bytes" "encoding/json" "fmt" "io" "net/http" + helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" d "github.com/karincake/dodol" @@ -16,150 +16,25 @@ import ( ) func Create(input *e.Patient) error { - endpoint := getPrefixEndpoint() - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) } func CreateLog(input *elog.SimxLogDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := prefixEndpoint + "/log" - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", endpoint) } func Update(input *e.Patient) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "PATCH", endpoint) } func Delete(input *e.DeleteDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "DELETE", endpoint) } func GenerateNomrPatient() (*string, error) { diff --git a/internal/use-case/simgos-sync-plugin/new/specialist/plugin.go b/internal/use-case/simgos-sync-plugin/new/specialist/plugin.go index 370a66dd..29da9d0a 100644 --- a/internal/use-case/simgos-sync-plugin/new/specialist/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/specialist/plugin.go @@ -1,165 +1,35 @@ package specialist import ( - "bytes" - "encoding/json" "fmt" - "io" - "net/http" + helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" sync "simrs-vx/internal/infra/sync-consumer-cfg" e "simrs-vx/internal/domain/main-entities/specialist" elog "simrs-vx/internal/domain/sync-entities/log" - - d "github.com/karincake/dodol" ) func Create(input *e.CreateDto) error { - endpoint := getPrefixEndpoint() - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) } func CreateLog(input *elog.SimxLogDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := prefixEndpoint + "/log" - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", endpoint) } func Update(input *e.UpdateDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "PATCH", endpoint) } func Delete(input *e.DeleteDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "DELETE", endpoint) } func getPrefixEndpoint() string { diff --git a/internal/use-case/simgos-sync-plugin/new/subspecialist/plugin.go b/internal/use-case/simgos-sync-plugin/new/subspecialist/plugin.go index 5fa831d1..0167936c 100644 --- a/internal/use-case/simgos-sync-plugin/new/subspecialist/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/subspecialist/plugin.go @@ -1,165 +1,35 @@ package subspecialist import ( - "bytes" - "encoding/json" "fmt" - "io" - "net/http" + helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" sync "simrs-vx/internal/infra/sync-consumer-cfg" e "simrs-vx/internal/domain/main-entities/subspecialist" elog "simrs-vx/internal/domain/sync-entities/log" - - d "github.com/karincake/dodol" ) func Create(input *e.CreateDto) error { - endpoint := getPrefixEndpoint() - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) } func CreateLog(input *elog.SimxLogDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := prefixEndpoint + "/log" - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", endpoint) } func Update(input *e.UpdateDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "PATCH", endpoint) } func Delete(input *e.DeleteDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "DELETE", endpoint) } func getPrefixEndpoint() string { diff --git a/internal/use-case/simgos-sync-plugin/new/unit/plugin.go b/internal/use-case/simgos-sync-plugin/new/unit/plugin.go index 36d240b5..f646f450 100644 --- a/internal/use-case/simgos-sync-plugin/new/unit/plugin.go +++ b/internal/use-case/simgos-sync-plugin/new/unit/plugin.go @@ -1,165 +1,35 @@ package unit import ( - "bytes" - "encoding/json" "fmt" - "io" - "net/http" + helper "simrs-vx/internal/use-case/simgos-sync-plugin/new" sync "simrs-vx/internal/infra/sync-consumer-cfg" e "simrs-vx/internal/domain/main-entities/unit" elog "simrs-vx/internal/domain/sync-entities/log" - - d "github.com/karincake/dodol" ) func Create(input *e.CreateDto) error { - endpoint := getPrefixEndpoint() - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", getPrefixEndpoint()) } func CreateLog(input *elog.SimxLogDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := prefixEndpoint + "/log" - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("POST", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "POST", endpoint) } func Update(input *e.UpdateDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("PATCH", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "PATCH", endpoint) } func Delete(input *e.DeleteDto) error { prefixEndpoint := getPrefixEndpoint() endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id) - - jsonData, err := json.Marshal(input) - if err != nil { - return fmt.Errorf("failed to encode JSON: %w", err) - } - - req, err := http.NewRequest("DELETE", endpoint, bytes.NewReader(jsonData)) - if err != nil { - return err - } - - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - if err != nil { - return err - } - defer resp.Body.Close() - - bodyBytes, err := io.ReadAll(resp.Body) - if err != nil { - return err - } - - if resp.StatusCode != http.StatusOK { - errors := d.FieldError{} - _ = json.Unmarshal(bodyBytes, &errors) - - return fmt.Errorf(errors.Message) - } - - return nil + return helper.DoJsonRequest(input, "DELETE", endpoint) } func getPrefixEndpoint() string { diff --git a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go index bbbc8687..3a190d56 100644 --- a/internal/use-case/simgos-sync-use-case/new/encounter/helper.go +++ b/internal/use-case/simgos-sync-use-case/new/encounter/helper.go @@ -381,9 +381,7 @@ func updatePatientCaraBayar(input etp.TPendaftaran, event *pl.Event, dbx ...*gor if err := tx.Model(&ep.MPasien{}). Where("\"nomr\" = ?", input.Nomr). - Updates(map[string]interface{}{ - "kdcarabayar": input.Kdcarabayar, - }).Error; err != nil { + Update("kdcarabayar", input.Kdcarabayar).Error; err != nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "update-fail", diff --git a/pkg/dualtrx-helper/dualtrx-helper.go b/pkg/dualtrx-helper/dualtrx-helper.go index 2f16203c..144337c5 100644 --- a/pkg/dualtrx-helper/dualtrx-helper.go +++ b/pkg/dualtrx-helper/dualtrx-helper.go @@ -11,9 +11,12 @@ type Dualtx struct { } func NewDualtx() *Dualtx { + simgosTx := dg.IS["simrs"].Begin() + simgosTx.Exec(`SET LOCAL simx.sync_source = 'new'`) + return &Dualtx{ Sync: dg.I.Begin(), - Simgos: dg.IS["simrs"].Begin(), + Simgos: simgosTx, } }