diff --git a/cmd/bpjs-api/config.yml-example b/cmd/bpjs-api/config.yml-example new file mode 100644 index 00000000..f131a725 --- /dev/null +++ b/cmd/bpjs-api/config.yml-example @@ -0,0 +1,66 @@ +appCfg: + fullName: BPJS Bridge + codeName: simrs-vx + version: 0.1.0 + env: development + lang: en + +httpCfg: + host: + port: + +dbCfg: + dsn: + maxOpenConns: 5 + maxIdleConns: 5 + maxIdleTime: 100 + +multiDbCfg: + - dbs : + name: + dsn: + maxOpenConns: + maxIdleConns: + maxIdleTime: + - bpjs + name: bpjs + dsn: + maxOpenConns: + maxIdleConns: + maxIdleTime: + +loggerCfg: + hideTime: + hideLevel: + +msCfg: + dsn: + +langCfg: + active: + path: + fileName: + +minioCfg: + endpoint: + region: + accessKey: + secretKey: + useSsl: + bucketName: + - patient + +corsCfg: + allowedOrigin: + allowedMethod: + +satuSehatCfg: + host: localhost:8200 + +bpjsCfg: + host: localhost:8200 + +corsCfg: + allowedOrigins: + - http://example.com + allowedMethod: \ No newline at end of file diff --git a/cmd/bpjs-api/main.go b/cmd/bpjs-api/main.go new file mode 100644 index 00000000..74be3afd --- /dev/null +++ b/cmd/bpjs-api/main.go @@ -0,0 +1,14 @@ +package main + +import ( + a "github.com/karincake/apem" + d "github.com/karincake/apem/db-gorm-pg" + l "github.com/karincake/apem/logger-zerolog" + m "github.com/karincake/apem/ms-redis" + + h "simrs-vx/internal/interface/main-handler" +) + +func main() { + a.Run(h.SetRoutes(), &l.O, &m.O, &d.O) +} diff --git a/cmd/main-migration/migrations/20251013081808.sql b/cmd/main-migration/migrations/20251013081808.sql new file mode 100644 index 00000000..03bf02ce --- /dev/null +++ b/cmd/main-migration/migrations/20251013081808.sql @@ -0,0 +1,16 @@ +-- Create "InternalReference" table +CREATE TABLE "public"."InternalReference" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Unit_Id" integer NULL, + "Doctor_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_InternalReference_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_InternalReference_Encounter" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_InternalReference_Unit" FOREIGN KEY ("Unit_Id") REFERENCES "public"."Unit" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "CheckoutPolies" table +DROP TABLE "public"."CheckoutPolies"; diff --git a/cmd/main-migration/migrations/20251014060047.sql b/cmd/main-migration/migrations/20251014060047.sql new file mode 100644 index 00000000..1d13853a --- /dev/null +++ b/cmd/main-migration/migrations/20251014060047.sql @@ -0,0 +1,36 @@ +-- Create "VClaimSepHist" table +CREATE TABLE "public"."VClaimSepHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "RequestPayload" text NULL, + "ResponseBody" text NULL, + "Message" text NULL, + PRIMARY KEY ("Id") +); +-- Modify "Encounter" table +ALTER TABLE "public"."Encounter" ADD COLUMN "PaymentMethod_Code" character varying(10) NULL, ADD COLUMN "InsuranceCompany_Id" bigint NULL, ADD COLUMN "Member_Number" character varying(20) NULL, ADD COLUMN "Ref_Number" character varying(20) NULL, ADD COLUMN "Trx_Number" character varying(20) NULL, ADD COLUMN "Adm_Employee_Id" bigint NULL, ADD CONSTRAINT "uni_Encounter_Member_Number" UNIQUE ("Member_Number"), ADD CONSTRAINT "uni_Encounter_Ref_Number" UNIQUE ("Ref_Number"), ADD CONSTRAINT "uni_Encounter_Trx_Number" UNIQUE ("Trx_Number"), ADD CONSTRAINT "fk_Encounter_Adm_Employee" FOREIGN KEY ("Adm_Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Id") REFERENCES "public"."InsuranceCompany" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Create "VClaimSep" table +CREATE TABLE "public"."VClaimSep" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Number" character varying(19) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_VClaimSep_Number" UNIQUE ("Number"), + CONSTRAINT "fk_Encounter_VclaimSep" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Create "VClaimSepPrint" table +CREATE TABLE "public"."VClaimSepPrint" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "VclaimSep_Number" character varying(19) NULL, + "Counter" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_VClaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VClaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251014063537.sql b/cmd/main-migration/migrations/20251014063537.sql new file mode 100644 index 00000000..7b77b3d9 --- /dev/null +++ b/cmd/main-migration/migrations/20251014063537.sql @@ -0,0 +1,16 @@ +-- Create "VclaimSep" table +CREATE TABLE "public"."VclaimSep" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Encounter_Id" bigint NULL, + "Number" character varying(19) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_VclaimSep_Number" UNIQUE ("Number"), + CONSTRAINT "fk_Encounter_VclaimSep" FOREIGN KEY ("Encounter_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Modify "VClaimSepPrint" table +ALTER TABLE "public"."VClaimSepPrint" DROP CONSTRAINT "fk_VClaimSepPrint_VclaimSep", ADD CONSTRAINT "fk_VClaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VclaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Drop "VClaimSep" table +DROP TABLE "public"."VClaimSep"; diff --git a/cmd/main-migration/migrations/20251014063720.sql b/cmd/main-migration/migrations/20251014063720.sql new file mode 100644 index 00000000..0763c12b --- /dev/null +++ b/cmd/main-migration/migrations/20251014063720.sql @@ -0,0 +1,26 @@ +-- Create "VclaimSepHist" table +CREATE TABLE "public"."VclaimSepHist" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "RequestPayload" text NULL, + "ResponseBody" text NULL, + "Message" text NULL, + PRIMARY KEY ("Id") +); +-- Create "VclaimSepPrint" table +CREATE TABLE "public"."VclaimSepPrint" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "VclaimSep_Number" character varying(19) NULL, + "Counter" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_VclaimSepPrint_VclaimSep" FOREIGN KEY ("VclaimSep_Number") REFERENCES "public"."VclaimSep" ("Number") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "VClaimSepHist" table +DROP TABLE "public"."VClaimSepHist"; +-- Drop "VClaimSepPrint" table +DROP TABLE "public"."VClaimSepPrint"; diff --git a/cmd/main-migration/migrations/20251015045455.sql b/cmd/main-migration/migrations/20251015045455.sql new file mode 100644 index 00000000..f2b6be7a --- /dev/null +++ b/cmd/main-migration/migrations/20251015045455.sql @@ -0,0 +1,2 @@ +-- Modify "Chemo" table +ALTER TABLE "public"."Chemo" ADD COLUMN "ClassCode" text NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index d8f19f7d..e3172704 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:0s0nd0srbuZbIdiQHvRt1PALWD+XDaCk7Qg/iAk4wY0= +h1:Y15nC3Bp3DWNym7hAvXkF9zFwkHh8nQDpxcNrxQgYhE= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -38,4 +38,9 @@ h1:0s0nd0srbuZbIdiQHvRt1PALWD+XDaCk7Qg/iAk4wY0= 20251010070721.sql h1:5NQUk/yOV6sABLCB7swx++YIOyJe6MnU+yt1nRzde5w= 20251010072711.sql h1:ZJNqR2piyu8xJhBvVABSlnGEoKSKae3wuEs+wshPe4k= 20251013044536.sql h1:0Xjw8fNILiT8nnfrJDZgQnPf3dntmIoilbapnih8AE4= -20251013051438.sql h1:aREcqpdUTiA2T9/f1HOtfa4BUiPRa50RATZ4ETu1syk= +20251013051438.sql h1:lfSuw5mgJnePBJamvhZ81osFIouXeiIEiSZ/evdwo48= +20251013081808.sql h1:ijgjNX08G6GBjA/ks8EKtb7P7Y7Cg7zbhqEOruGnv6M= +20251014060047.sql h1:0jqj49WTtneEIMQDBoo4c095ZGi8sCrA8NnHBrPU6D8= +20251014063537.sql h1:VZLXol0PTsTW21Epg6vBPsztWkDtcxup9F/z88EGgIg= +20251014063720.sql h1:2HVUyCV0ud3BJJDH2GEKZN/+IWLFPCsN1KqhP6csO14= +20251015045455.sql h1:v120CzYYiFWmW81VmKWsjmjRiBIv5aFnPZXwQaQxqes= diff --git a/internal/domain/bpjs-entities/vclaim-sep-hist/dto.go b/internal/domain/bpjs-entities/vclaim-sep-hist/dto.go new file mode 100644 index 00000000..778154cb --- /dev/null +++ b/internal/domain/bpjs-entities/vclaim-sep-hist/dto.go @@ -0,0 +1 @@ +package vclaimsephist diff --git a/internal/domain/bpjs-entities/vclaim-sep-hist/entitiy.go b/internal/domain/bpjs-entities/vclaim-sep-hist/entitiy.go new file mode 100644 index 00000000..46880159 --- /dev/null +++ b/internal/domain/bpjs-entities/vclaim-sep-hist/entitiy.go @@ -0,0 +1,12 @@ +package vclaimsephist + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type VclaimSepHist struct { + ecore.Main + RequestPayload *string `json:"requestPayload"` + ResponseBody *string `json:"responseBody"` + Message *string `json:"message"` +} diff --git a/internal/domain/bpjs-entities/vclaim-sep-print/dto.go b/internal/domain/bpjs-entities/vclaim-sep-print/dto.go new file mode 100644 index 00000000..b975dd96 --- /dev/null +++ b/internal/domain/bpjs-entities/vclaim-sep-print/dto.go @@ -0,0 +1 @@ +package vclaimsepprint diff --git a/internal/domain/bpjs-entities/vclaim-sep-print/entity.go b/internal/domain/bpjs-entities/vclaim-sep-print/entity.go new file mode 100644 index 00000000..1bd5e9fc --- /dev/null +++ b/internal/domain/bpjs-entities/vclaim-sep-print/entity.go @@ -0,0 +1,13 @@ +package vclaimsepprint + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + evs "simrs-vx/internal/domain/bpjs-entities/vclaim-sep" +) + +type VclaimSepPrint struct { + ecore.Main + VclaimSep_Number *string `json:"vclaimSep_number"` + VclaimSep *evs.VclaimSep `json:"vclaimSep,omitempty" gorm:"foreignKey:VclaimSep_Number;references:Number"` + Counter *uint `json:"counter"` +} diff --git a/internal/domain/bpjs-entities/vclaim-sep/dto.go b/internal/domain/bpjs-entities/vclaim-sep/dto.go new file mode 100644 index 00000000..ce4c6f55 --- /dev/null +++ b/internal/domain/bpjs-entities/vclaim-sep/dto.go @@ -0,0 +1 @@ +package vclaimsep diff --git a/internal/domain/bpjs-entities/vclaim-sep/entitiy.go b/internal/domain/bpjs-entities/vclaim-sep/entitiy.go new file mode 100644 index 00000000..e23106d8 --- /dev/null +++ b/internal/domain/bpjs-entities/vclaim-sep/entitiy.go @@ -0,0 +1,11 @@ +package vclaimsep + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type VclaimSep struct { + ecore.Main + Encounter_Id *uint `json:"encounter_id"` + Number *string `json:"number" gorm:"unique;size:19"` +} diff --git a/internal/domain/main-entities/chemo/entity.go b/internal/domain/main-entities/chemo/entity.go index f80d5bc1..4052ea72 100644 --- a/internal/domain/main-entities/chemo/entity.go +++ b/internal/domain/main-entities/chemo/entity.go @@ -9,6 +9,7 @@ import ( eus "simrs-vx/internal/domain/main-entities/user" erc "simrs-vx/internal/domain/references/common" + ere "simrs-vx/internal/domain/references/encounter" ) type Chemo struct { @@ -19,6 +20,7 @@ type Chemo struct { VerifiedAt *time.Time `json:"verifiedAt"` VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"` VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"` - SrcUnit_Id *uint `json:"srcUnit_id"` - SrcUnit *eun.Unit `json:"srcUnit,omitempty" gorm:"foreignKey:SrcUnit_Id;references:Id"` + SrcUnit_Id *uint `json:"src_unit_id"` + SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Id;references:Id"` + Class_Code ere.ChemoClassCode `json:"class_code"` } diff --git a/internal/domain/main-entities/encounter/dto.go b/internal/domain/main-entities/encounter/dto.go index 608d26dd..bd630857 100644 --- a/internal/domain/main-entities/encounter/dto.go +++ b/internal/domain/main-entities/encounter/dto.go @@ -66,6 +66,11 @@ type UpdateDto struct { CreateDto } +type UpdateStatusDto struct { + Id uint16 `json:"id"` + StatusCode erc.DataStatusCode `json:"status_code"` +} + type DeleteDto struct { Id uint16 `json:"id"` } diff --git a/internal/domain/main-entities/encounter/entity.go b/internal/domain/main-entities/encounter/entity.go index 87833b37..c9f81712 100644 --- a/internal/domain/main-entities/encounter/entity.go +++ b/internal/domain/main-entities/encounter/entity.go @@ -2,12 +2,16 @@ package encounter import ( ecore "simrs-vx/internal/domain/base-entities/core" + evs "simrs-vx/internal/domain/bpjs-entities/vclaim-sep" ea "simrs-vx/internal/domain/main-entities/appointment" ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/employee" + ei "simrs-vx/internal/domain/main-entities/insurance-company" ep "simrs-vx/internal/domain/main-entities/patient" es "simrs-vx/internal/domain/main-entities/specialist" ess "simrs-vx/internal/domain/main-entities/subspecialist" eu "simrs-vx/internal/domain/main-entities/unit" + erc "simrs-vx/internal/domain/references/common" ere "simrs-vx/internal/domain/references/encounter" "time" @@ -26,8 +30,16 @@ type Encounter struct { Subspecialist_Id *uint16 `json:"subspecialist_id"` Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"` VisitDate time.Time `json:"visitDate"` + PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"` + InsuranceCompany_Id *uint `json:"insuranceCompany_id"` + Member_Number *string `json:"memberNumber" gorm:"unique;size:20"` + Ref_Number *string `json:"refNumber" gorm:"unique;size:20"` + Trx_Number *string `json:"trxNumber" gorm:"unique;size:20"` + InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"` Appointment_Doctor_Id *uint `json:"appointment_doctor_id"` Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Id;references:Id"` + Adm_Employee_Id *uint `json:"admEmployee_id"` + Adm_Employee *ee.Employee `json:"admEmployee,omitempty" gorm:"foreignKey:Adm_Employee_Id;references:Id"` Responsible_Doctor_Id *uint `json:"responsible_doctor_id"` Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Id;references:Id"` DischargeMethod_Code *ere.DischargeMethodCode `json:"dischargeMethod_code" gorm:"size:16"` @@ -39,6 +51,7 @@ type Encounter struct { AdmDischargeEducation *string `json:"admDischargeEducation"` DischargeReason *string `json:"dischargeReason"` Status_Code erc.DataStatusCode `json:"status_code" gorm:"size:10"` + VclaimSep *evs.VclaimSep `json:"vclaimSep,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` } func (d Encounter) IsDone() bool { diff --git a/internal/domain/references/encounter/encounter.go b/internal/domain/references/encounter/encounter.go index 7e6bcf8c..93c49a33 100644 --- a/internal/domain/references/encounter/encounter.go +++ b/internal/domain/references/encounter/encounter.go @@ -12,6 +12,7 @@ type ( AmbulatoryClassCode string InpatientClassCode string UploadCode string + ChemoClassCode string ) const ( @@ -78,6 +79,9 @@ const ( UCPP UploadCode = "person-passport" // Person Passport UCPFC UploadCode = "person-family-card" // Person Family Card UCMIR UploadCode = "mcu-item-result" // Mcu Item Result + + CCCAdm ChemoClassCode = "adm" // Administrasi + CCCAct ChemoClassCode = "act" // Tindakan ) func (ec EncounterClassCode) Code() string { diff --git a/internal/interface/bpjs-handler/bpjs-handler.go b/internal/interface/bpjs-handler/bpjs-handler.go new file mode 100644 index 00000000..a3d86116 --- /dev/null +++ b/internal/interface/bpjs-handler/bpjs-handler.go @@ -0,0 +1,52 @@ +package bpjshandler + +import ( + "net/http" + + /******************** main / transaction ********************/ + + /******************** actor ********************/ + + /******************** external ********************/ + a "github.com/karincake/apem" + + /******************** infra ********************/ + gs "simrs-vx/internal/infra/gorm-setting" + minio "simrs-vx/internal/infra/minio" + ssdb "simrs-vx/internal/infra/ss-db" + + /******************** pkg ********************/ + cmw "simrs-vx/pkg/cors-manager-mw" + lh "simrs-vx/pkg/lang-helper" + handlerlogger "simrs-vx/pkg/middleware/handler-logger" + mh "simrs-vx/pkg/minio-helper" + zlc "simrs-vx/pkg/zerolog-ctx" + + /******************** sources ********************/ + ///// Internal + validation "simrs-vx/internal/interface/main-handler/helper/validation" + "simrs-vx/internal/interface/main-handler/home" +) + +// One place route to relatively easier to manage, ESPECIALLY in tracking +func SetRoutes() http.Handler { + ///// + a.RegisterExtCall(gs.Adjust) + a.RegisterExtCall(zlc.Adjust) + a.RegisterExtCall(ssdb.SetInstance) + a.RegisterExtCall(lh.Populate) + a.RegisterExtCall(minio.Connect) + a.RegisterExtCall(mh.I.SetClient) + a.RegisterExtCall(validation.RegisterValidation) + + r := http.NewServeMux() + + /******************** Main ********************/ + r.HandleFunc("/", home.Home) + + /******************** actor ********************/ + + /******************** sources ********************/ + + return cmw.SetCors(handlerlogger.SetLog(r)) +} diff --git a/internal/interface/main-handler/encounter/handler.go b/internal/interface/main-handler/encounter/handler.go index 7484b302..3c0d2da4 100644 --- a/internal/interface/main-handler/encounter/handler.go +++ b/internal/interface/main-handler/encounter/handler.go @@ -10,6 +10,8 @@ import ( e "simrs-vx/internal/domain/main-entities/encounter" u "simrs-vx/internal/use-case/main-use-case/encounter" + + erc "simrs-vx/internal/domain/references/common" ) type myBase struct{} @@ -83,3 +85,63 @@ func (obj myBase) CheckOut(w http.ResponseWriter, r *http.Request) { res, err := u.CheckOut(dto) rw.DataResponse(w, res, err) } + +func (obj myBase) Process(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateStatusDto{ + Id: uint16(id), + StatusCode: erc.DSCProcess, + } + + res, err := u.UpdateStatusCode(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Cancel(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateStatusDto{ + Id: uint16(id), + StatusCode: erc.DSCCancel, + } + + res, err := u.UpdateStatusCode(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Reject(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateStatusDto{ + Id: uint16(id), + StatusCode: erc.DSCRejected, + } + + res, err := u.UpdateStatusCode(dto) + rw.DataResponse(w, res, err) +} + +func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) { + id := rw.ValidateInt(w, "id", r.PathValue("id")) + if id <= 0 { + return + } + + dto := e.UpdateStatusDto{ + Id: uint16(id), + StatusCode: erc.DSCSkipped, + } + + res, err := u.UpdateStatusCode(dto) + rw.DataResponse(w, res, err) +} diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 63448f21..3b31e2e5 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -168,6 +168,10 @@ func SetRoutes() http.Handler { "PATCH /{id}": encounter.O.Update, "DELETE /{id}": encounter.O.Delete, "PATCH /{id}/checkout": encounter.O.CheckOut, + "PATCH /{id}/proccess": encounter.O.Process, + "PATCH /{id}/cancel": encounter.O.Cancel, + "PATCH /{id}/reject": encounter.O.Reject, + "PATCH /{id}/skip": encounter.O.Skip, }) hk.GroupRoutes("/v1/medication", r, auth.GuardMW, hk.MapHandlerFunc{ "GET /": medication.O.GetList, diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 41bb18db..034495c3 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -75,6 +75,11 @@ import ( uom "simrs-vx/internal/domain/main-entities/uom" user "simrs-vx/internal/domain/main-entities/user" village "simrs-vx/internal/domain/main-entities/village" + + ///BPJS + vclaimsep "simrs-vx/internal/domain/bpjs-entities/vclaim-sep" + vclaimsephist "simrs-vx/internal/domain/bpjs-entities/vclaim-sep-hist" + vclaimsepprint "simrs-vx/internal/domain/bpjs-entities/vclaim-sep-print" ) func getMainEntities() []any { @@ -123,6 +128,7 @@ func getMainEntities() []any { &personrelative.PersonRelative{}, &patient.Patient{}, &appointment.Appointment{}, + &vclaimsep.VclaimSep{}, &encounter.Encounter{}, &laborant.Laborant{}, &specialist.Specialist{}, @@ -153,5 +159,7 @@ func getMainEntities() []any { &midwife.Midwife{}, &postalregion.PostalRegion{}, &internalreference.InternalReference{}, + &vclaimsephist.VclaimSepHist{}, + &vclaimsepprint.VclaimSepPrint{}, } } diff --git a/internal/use-case/main-use-case/encounter/case.go b/internal/use-case/main-use-case/encounter/case.go index 7d209041..453ea6cb 100644 --- a/internal/use-case/main-use-case/encounter/case.go +++ b/internal/use-case/main-use-case/encounter/case.go @@ -421,3 +421,69 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) { Data: data.ToResponse(), }, nil } + +func UpdateStatusCode(input e.UpdateStatusDto) (*d.Data, error) { + rdDto := e.ReadDetailDto{Id: input.Id} + var data *e.Encounter + var err error + + event := pl.Event{ + Feature: "Update Status Code", + Source: source, + } + + // Start log + pl.SetLogInfo(&event, input, "started", "update") + + err = dg.I.Transaction(func(tx *gorm.DB) error { + pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail") + if data, err = ReadDetailData(rdDto, &event, tx); err != nil { + return err + } + + if data.IsDone() { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-state-mismatch", + Detail: "encounter is done", + Raw: errors.New("encounter is done"), + } + return pl.SetLogError(&event, input) + } + + mwRunner := newMiddlewareRunner(&event, tx) + mwRunner.setMwType(pu.MWTPre) + // Run pre-middleware + if err := mwRunner.RunUpdateMiddleware(readDetailPreMw, &rdDto, data); err != nil { + return err + } + + if err := UpdateStatusData(input, data, &event, tx); err != nil { + return err + } + + pl.SetLogInfo(&event, nil, "complete") + + mwRunner.setMwType(pu.MWTPost) + // Run post-middleware + if err := mwRunner.RunUpdateMiddleware(readDetailPostMw, &rdDto, data); err != nil { + return err + } + + return nil + }) + + if err != nil { + return nil, err + } + + return &d.Data{ + Meta: d.IS{ + "source": source, + "structure": "single-data", + "status": "updated", + }, + Data: data.ToResponse(), + }, nil + +} diff --git a/internal/use-case/main-use-case/encounter/helper.go b/internal/use-case/main-use-case/encounter/helper.go index 8d9ea44d..448f7be7 100644 --- a/internal/use-case/main-use-case/encounter/helper.go +++ b/internal/use-case/main-use-case/encounter/helper.go @@ -59,7 +59,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) { data.Responsible_Doctor_Id = inputSrc.Responsible_Doctor_Id data.RefSource_Name = inputSrc.RefSource_Name data.Appointment_Id = inputSrc.Appointment_Id - data.Status_Code = erc.DSCNew + data.Status_Code = erc.DSCProcess } func setDataUpdate(src e.UpdateDto, dst *e.Encounter) { @@ -308,3 +308,7 @@ func getMcuOrders(encounter_id uint, event *pl.Event, tx *gorm.DB) error { return nil } + +func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) { + dst.Status_Code = src.StatusCode +} diff --git a/internal/use-case/main-use-case/encounter/lib.go b/internal/use-case/main-use-case/encounter/lib.go index e1bcc630..2f4d69fa 100644 --- a/internal/use-case/main-use-case/encounter/lib.go +++ b/internal/use-case/main-use-case/encounter/lib.go @@ -187,3 +187,28 @@ func IsDone(encounter_id uint, event *pl.Event, dbx ...*gorm.DB) bool { pl.SetLogInfo(event, nil, "complete") return data.IsDone() } + +func UpdateStatusData(input e.UpdateStatusDto, data *e.Encounter, event *pl.Event, dbx ...*gorm.DB) error { + pl.SetLogInfo(event, data, "started", "DBUpdate") + setDataUpdateStatus(input, data) + + var tx *gorm.DB + if len(dbx) > 0 { + tx = dbx[0] + } else { + tx = dg.I + } + + if err := tx.Save(&data).Error; err != nil { + event.Status = "failed" + event.ErrInfo = pl.ErrorInfo{ + Code: "data-update-fail", + Detail: "Database update failed", + Raw: err, + } + return pl.SetLogError(event, input) + } + + pl.SetLogInfo(event, nil, "complete") + return nil +}