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

This commit is contained in:
vanilia
2025-11-06 14:36:49 +07:00
11 changed files with 97 additions and 73 deletions

No files matched your search

@@ -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;
@@ -0,0 +1,2 @@
-- Modify "Rehab" table
ALTER TABLE "public"."Rehab" DROP COLUMN "Doctor_Id";
+4 -2
View File
@@ -1,4 +1,4 @@
h1:drtrRtMhlNYK0c9wV3CUkJvXwWgrD8xGPPJy9wlcvNA= h1:KxMvALnpFUI2RXpBZgkJ312FeLtrm9L0o+CqgJbm40U=
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
@@ -68,4 +68,6 @@ h1:drtrRtMhlNYK0c9wV3CUkJvXwWgrD8xGPPJy9wlcvNA=
20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk= 20251104042334.sql h1:7PDMWOhmJywolAPKFZ14XaDBeMvcxShaXFN2IemNtzk=
20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU= 20251104043530.sql h1:qvYVp3ysPf27f1BcoRNCFGovxuVE12lg9d6Xzda6zWU=
20251104080952.sql h1:avghpv1n3yaCDR/TA0X+hgxDGoLBQGu/GJUwj4VT/Ic= 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=
@@ -9,5 +9,4 @@ type Ambulatory struct {
ecore.Main // adjust this according to the needs ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"` Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.AmbulatoryClassCode `json:"class_code" gorm:"size:10"` Class_Code ere.AmbulatoryClassCode `json:"class_code" gorm:"size:10"`
VisitMode_Code ere.VisitModeCode `json:"visitMode_code"`
} }
@@ -68,7 +68,8 @@ type Encounter struct {
Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Emergency *eem.Emergency `json:"emergency,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"` 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 { func (d Encounter) IsDone() bool {
@@ -1,6 +1,8 @@
package internal_reference package internal_reference
import ( import (
erc "simrs-vx/internal/domain/references/common"
ecore "simrs-vx/internal/domain/base-entities/core" ecore "simrs-vx/internal/domain/base-entities/core"
ed "simrs-vx/internal/domain/main-entities/doctor" ed "simrs-vx/internal/domain/main-entities/doctor"
eu "simrs-vx/internal/domain/main-entities/unit" eu "simrs-vx/internal/domain/main-entities/unit"
@@ -13,4 +15,5 @@ type InternalReference struct {
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"` Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"` Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Status_Code *erc.DataApprovalCode `json:"status_code"`
} }
@@ -1,16 +1,21 @@
package base package base
import ( import (
erc "simrs-vx/internal/domain/references/common"
ere "simrs-vx/internal/domain/references/encounter"
"time"
ecore "simrs-vx/internal/domain/base-entities/core" ecore "simrs-vx/internal/domain/base-entities/core"
ed "simrs-vx/internal/domain/main-entities/doctor"
) )
type Basic struct { type Basic struct {
ecore.Main // adjust this according to the needs ecore.Main // adjust this according to the needs
Parent_Encounter_Id *uint `json:"parent_encounter_id"`
Encounter_Id *uint `json:"encounter_id"` 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"` 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 { func (Basic) TableName() string {
@@ -15,6 +15,7 @@ type (
DataAvailabilityCode string DataAvailabilityCode string
DataVerifiedCode string DataVerifiedCode string
CrudCode string CrudCode string
DataApprovalCode string
) )
const ( const (
@@ -96,6 +97,10 @@ const (
CCRead CrudCode = "r" // Read CCRead CrudCode = "r" // Read
CCUpdate CrudCode = "u" // Update CCUpdate CrudCode = "u" // Update
CCDelete CrudCode = "d" // Delete CCDelete CrudCode = "d" // Delete
DACNew DataApprovalCode = "new"
DACApproved DataApprovalCode = "approved"
DACRejected DataApprovalCode = "rejected"
) )
func GetDayCodes() map[DayCode]string { func GetDayCodes() map[DayCode]string {
@@ -19,6 +19,7 @@ type (
AllPaymentMethodCode string AllPaymentMethodCode string
SEPRefTypeCode string SEPRefTypeCode string
VisitModeCode string VisitModeCode string
PolySwitchCode string
) )
const ( const (
@@ -35,8 +36,8 @@ const (
DMCHome DischargeMethodCode = "home" // Pulang DMCHome DischargeMethodCode = "home" // Pulang
DMCHomeReq DischargeMethodCode = "home-request" // Pulang Atas Permintaan Sendiri DMCHomeReq DischargeMethodCode = "home-request" // Pulang Atas Permintaan Sendiri
DMCConsulBack DischargeMethodCode = "consul-back" // Konsultasi Balik / Lanjutan DMCConsulBack DischargeMethodCode = "consul-back" // Konsultasi Balik / Lanjutan
DMCConsulPoly DischargeMethodCode = "consul-poly" // Konsultasi Poliklinik Lain //DMCConsulPoly DischargeMethodCode = "consul-poly" // Konsultasi Poliklinik Lain
DMCConsulExecutive DischargeMethodCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif //DMCConsulExecutive DischargeMethodCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif
DMCConsulChDay DischargeMethodCode = "consul-ch-day" // Konsultasi Hari Lain DMCConsulChDay DischargeMethodCode = "consul-ch-day" // Konsultasi Hari Lain
DMCEmergency DischargeMethodCode = "emergency" // Rujuk IGD DMCEmergency DischargeMethodCode = "emergency" // Rujuk IGD
DMCEmergencyCovid DischargeMethodCode = "emergency-covid" // Rujuk IGD Covid DMCEmergencyCovid DischargeMethodCode = "emergency-covid" // Rujuk IGD Covid
@@ -112,6 +113,9 @@ const (
VMCAdm VisitModeCode = "adm" VMCAdm VisitModeCode = "adm"
VMCSeries VisitModeCode = "series" VMCSeries VisitModeCode = "series"
PSCConsulPoly PolySwitchCode = "consul-poly" // Konsultasi Poliklinik Lain
PSCConsulExecutive PolySwitchCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif
) )
func (ec EncounterClassCode) Code() string { func (ec EncounterClassCode) Code() string {
@@ -1,7 +1,6 @@
package encounter package encounter
import ( import (
"fmt"
"net/http" "net/http"
e "simrs-vx/internal/domain/main-entities/encounter" e "simrs-vx/internal/domain/main-entities/encounter"
ere "simrs-vx/internal/domain/references/encounter" ere "simrs-vx/internal/domain/references/encounter"
@@ -13,42 +12,41 @@ import (
const dataValidationFail = "data-validation-fail" const dataValidationFail = "data-validation-fail"
func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) { func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) {
switch *i.Discharge_Method_Code { if *i.Discharge_Method_Code == ere.DMCDeath && i.DeathCause == nil {
case ere.DMCDeath:
if i.DeathCause == nil {
rw.DataResponse(w, nil, d.FieldError{ rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail, Code: dataValidationFail,
Message: "deathCause required if discharge_method_code is death", Message: "deathCause required if discharge_method_code is death",
}) })
return 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 { //case ere.DMCConsulPoly, ere.DMCConsulExecutive:
if v.Unit_Id == nil { // if i.InternalReferences == nil {
rw.DataResponse(w, nil, d.FieldError{ // rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail, // Code: dataValidationFail,
Message: "internalReferences.unit_id required", // Message: fmt.Sprintf("internalReferences required if discharge_method_code is %s", *i.Discharge_Method_Code),
}) // })
return // 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 v.Doctor_Id == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "internalReferences.doctor_id required",
})
return
}
}
}
return true return true
} }
@@ -506,19 +506,18 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) {
return err return err
} }
switch *input.Discharge_Method_Code { if *input.Discharge_Method_Code == ere.DMCDeath {
case ere.DMCDeath:
// insert data death-cause // insert data death-cause
if _, err = udc.CreateData(edc.CreateDto{Encounter_Id: &input.Id, Value: input.DeathCause}, &event, tx); err != nil { if _, err = udc.CreateData(edc.CreateDto{Encounter_Id: &input.Id, Value: input.DeathCause}, &event, tx); err != nil {
return err 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") pl.SetLogInfo(&event, nil, "complete")
return nil return nil