Merge branch 'migration-vanilia' of https://github.com/dikstub-rssa/simrs-be into feat/sync-seeder
# Conflicts: # internal/interface/main-handler/main-handler.go
This commit is contained in:
@@ -27,6 +27,8 @@ go.work.sum
|
||||
# env file
|
||||
.env
|
||||
config.yml
|
||||
Dockerfile-main-api
|
||||
Dockerfile-sync-api
|
||||
**/atlas.hcl
|
||||
!**/atlas.hcl.example
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o ./cmd/main-api/main-api ./cmd/main-api/
|
||||
|
||||
FROM alpine:latest
|
||||
WORKDIR /app
|
||||
COPY --from=builder /src/assets .
|
||||
COPY --from=builder /src/cmd/main-api/main-api .
|
||||
COPY --from=builder /src/cmd/main-api/config.yml .
|
||||
EXPOSE 8000
|
||||
EXPOSE 8010
|
||||
CMD ["./main-api"]
|
||||
@@ -7,7 +7,8 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o ./cmd/simgos-sync-api/simgos-sync-api .
|
||||
|
||||
FROM alpine:latest
|
||||
WORKDIR /app
|
||||
COPY --from=builder /src/assets .
|
||||
COPY --from=builder /src/cmd/simgos-sync-api/simgos-sync-api .
|
||||
COPY --from=builder /src/cmd/simgos-sync-api/config.yml .
|
||||
EXPOSE 8000
|
||||
EXPOSE 8011
|
||||
CMD ["./simgos-sync-api"]
|
||||
@@ -0,0 +1,36 @@
|
||||
-- Modify "Specialist" table
|
||||
ALTER TABLE "public"."Specialist" DROP COLUMN "Unit_Code";
|
||||
-- Rename a column from "SrcUnit_Code" to "Specialist_Code"
|
||||
ALTER TABLE "public"."Chemo" RENAME COLUMN "SrcUnit_Code" TO "Specialist_Code";
|
||||
-- Modify "Chemo" table
|
||||
ALTER TABLE "public"."Chemo" DROP CONSTRAINT "fk_Chemo_SrcUnit", ADD CONSTRAINT "fk_Chemo_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
-- Modify "Doctor" table
|
||||
ALTER TABLE "public"."Doctor" DROP COLUMN "Unit_Code";
|
||||
-- Rename a column from "DstUnit_Code" to "Specialist_Code"
|
||||
ALTER TABLE "public"."Consultation" RENAME COLUMN "DstUnit_Code" TO "Specialist_Code";
|
||||
-- Rename a column from "DstDoctor_Code" to "Doctor_Code"
|
||||
ALTER TABLE "public"."Consultation" RENAME COLUMN "DstDoctor_Code" TO "Doctor_Code";
|
||||
-- Modify "Consultation" table
|
||||
ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_DstDoctor", DROP CONSTRAINT "fk_Consultation_DstUnit", ADD CONSTRAINT "fk_Consultation_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
-- Rename a column from "Unit_Code" to "Specialist_Code"
|
||||
ALTER TABLE "public"."InternalReference" RENAME COLUMN "Unit_Code" TO "Specialist_Code";
|
||||
-- Modify "InternalReference" table
|
||||
ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Unit", ADD CONSTRAINT "fk_InternalReference_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
-- Rename a column from "Unit_Code" to "Specialist_Code"
|
||||
ALTER TABLE "public"."Nurse" RENAME COLUMN "Unit_Code" TO "Specialist_Code";
|
||||
-- Modify "Nurse" table
|
||||
ALTER TABLE "public"."Nurse" DROP CONSTRAINT "fk_Nurse_Unit", ADD CONSTRAINT "fk_Nurse_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
-- Rename a column from "Unit_Code" to "Specialist_Code"
|
||||
ALTER TABLE "public"."PracticeSchedule" RENAME COLUMN "Unit_Code" TO "Specialist_Code";
|
||||
-- Modify "PracticeSchedule" table
|
||||
ALTER TABLE "public"."PracticeSchedule" DROP CONSTRAINT "fk_PracticeSchedule_Unit", ADD CONSTRAINT "fk_PracticeSchedule_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
-- Modify "ControlLetter" table
|
||||
ALTER TABLE "public"."ControlLetter" DROP COLUMN "Unit_Code";
|
||||
-- Modify "Encounter" table
|
||||
ALTER TABLE "public"."Encounter" DROP COLUMN "Unit_Code";
|
||||
-- Modify "ProcedureRoom" table
|
||||
ALTER TABLE "public"."ProcedureRoom" DROP COLUMN "Unit_Code";
|
||||
-- Drop "UnitPosition" table
|
||||
DROP TABLE "public"."UnitPosition";
|
||||
-- Drop "Unit" table
|
||||
DROP TABLE "public"."Unit";
|
||||
@@ -0,0 +1,4 @@
|
||||
-- Modify "Subspecialist" table
|
||||
ALTER TABLE "public"."Subspecialist" ALTER COLUMN "Name" TYPE character varying(100);
|
||||
-- Modify "Specialist" table
|
||||
ALTER TABLE "public"."Specialist" ADD COLUMN "Installation_Code" character varying(20) NULL, ADD CONSTRAINT "fk_Specialist_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
|
||||
@@ -1,4 +1,4 @@
|
||||
h1:nDEuOqs0hKLyxdzKDcaNhEkrmnmbm6o/jgoGigw47bo=
|
||||
h1:IfSOZ5RxGCWboRtqCJrYxCJa1HYSrlROJLXcElq1P3I=
|
||||
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
|
||||
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
|
||||
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
|
||||
@@ -160,4 +160,6 @@ h1:nDEuOqs0hKLyxdzKDcaNhEkrmnmbm6o/jgoGigw47bo=
|
||||
20251209064304.sql h1:Xs73yQbuJvuQ0OnW1FAZpeytmUl/bGTlJFrwGOsTF4w=
|
||||
20251209070128.sql h1:fPGE6xOV6uCiVOqnvwn2L/GsBbgp2wxgmZOhF3bSGGM=
|
||||
20251209084929.sql h1:u4LPMvkGAH4RfGC2IlBTIm7T7paMHoBSvTQ0w5Br7d0=
|
||||
20251210145148.sql h1:EWbK5f1QKyhaVsKZfJFunmQuw22Msl0Ox3KQ/uag2bw=
|
||||
20251210145148.sql h1:rejGrnTpaygxPv06v0vxMytF4rk1OJBXaw3ttSmidgc=
|
||||
20251211101547.sql h1:+jT5yRCEsSRExzoawrqymS/I7lVfwUQQSgSzbxCxgRk=
|
||||
20251211113942.sql h1:F8go8XaJf4GFa4RuoMlo4U/NtbDtbDkVYHZOJz7GYhM=
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
h1:D3uD6s7yxMG7Roi9DCeYuLeRazZmQnd3rHMmUWf6YMM=
|
||||
h1:V6uRNFb6js/aPft2hebJMA8tI0YJc4BuZ7Rlp56FV00=
|
||||
20251113035508.sql h1:rjDlu6yDdy5xv6nrCOr7NialrLSLT23pzduYNq29Hf0=
|
||||
20251114071129.sql h1:Z0GQ5bJo3C+tplaWzxT8n3J9HLkEaVsRVp5nn7bmYow=
|
||||
20251117041601.sql h1:l/RPG5mObqCSBjO4mzG+wTq2ieSycvlfOSz4czpUdWY=
|
||||
@@ -6,4 +6,4 @@ h1:D3uD6s7yxMG7Roi9DCeYuLeRazZmQnd3rHMmUWf6YMM=
|
||||
20251118082915.sql h1:hP6FmUVFuADIN2cDg2Z1l7Wx7PQRb+IYQDvKD7J8VAM=
|
||||
20251126115527.sql h1:Bvg+Y7k+h5s+/UaezUyJb7J7uzEJS7U5Z/RoCixcUtI=
|
||||
20251201093443.sql h1:dyiD1WzU9D6RjGhF0AtGfGLEsG6yocuk3HbcZWt9ZRQ=
|
||||
20251209083238.sql h1:83pG5dPfMh8v0QognjeacK6s3fGxQ0nkijxtKL5y3Dc=
|
||||
20251209083238.sql h1:GmnvITp+vr3sYlWmPxWVxMnjSIRI0QKmv9i202kRgp4=
|
||||
|
||||
@@ -2,7 +2,7 @@ package chemo
|
||||
|
||||
import (
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
// std
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
"time"
|
||||
|
||||
// internal - lib
|
||||
@@ -14,14 +14,13 @@ import (
|
||||
// internal - domain - main-entities
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
eun "simrs-vx/internal/domain/main-entities/unit"
|
||||
eus "simrs-vx/internal/domain/main-entities/user"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Status_Code erc.DataVerifiedCode `json:"status_code"`
|
||||
SrcUnit_Code *string `json:"srcUnit_code"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Status_Code erc.DataVerifiedCode `json:"status_code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -34,7 +33,7 @@ type FilterDto struct {
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Status_Code *erc.DataVerifiedCode `json:"status-code"`
|
||||
VerifiedBy_User_Id *uint `json:"verifiedBy-user-id"`
|
||||
SrcUnit_Code *string `json:"srcUnit-code"`
|
||||
Specialist_Code *string `json:"specialist-code"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
@@ -75,8 +74,8 @@ type ResponseDto struct {
|
||||
VerifiedAt *time.Time `json:"verifiedAt"`
|
||||
VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"`
|
||||
VerifiedBy *eus.User `json:"verifiedBy,omitempty"`
|
||||
SrcUnit_Code *string `json:"srcUnit_code"`
|
||||
SrcUnit *eun.Unit `json:"srcUnit,omitempty"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Doctor *ed.Doctor `json:"doctor,omitempty"`
|
||||
NextChemoDate *time.Time `json:"nextChemoDate"`
|
||||
@@ -90,8 +89,8 @@ func (d Chemo) ToResponse() ResponseDto {
|
||||
VerifiedAt: d.VerifiedAt,
|
||||
VerifiedBy_User_Id: d.VerifiedBy_User_Id,
|
||||
VerifiedBy: d.VerifiedBy,
|
||||
SrcUnit_Code: d.SrcUnit_Code,
|
||||
SrcUnit: d.SrcUnit,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Doctor: d.Doctor,
|
||||
NextChemoDate: d.NextChemoDate,
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
eun "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
eus "simrs-vx/internal/domain/main-entities/user"
|
||||
)
|
||||
|
||||
@@ -21,8 +21,8 @@ type Chemo struct {
|
||||
VerifiedAt *time.Time `json:"verifiedAt"`
|
||||
VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"`
|
||||
VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"`
|
||||
SrcUnit_Code *string `json:"src_unit_code"` // klinik asal
|
||||
SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Code;references:Code"`
|
||||
Specialist_Code *string `json:"specialist_code"` // klinik asal
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Bed *string `json:"bed" gorm:"size:1024"`
|
||||
Needs *string `json:"needs" gorm:"size:2048"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
|
||||
@@ -13,14 +13,14 @@ import (
|
||||
// internal - domain - main-entities
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Date *time.Time `json:"date"`
|
||||
Problem *string `json:"problem" validate:"maxLength=10240"`
|
||||
DstUnit_Code *string `json:"dstUnit_code"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Date *time.Time `json:"date"`
|
||||
Problem *string `json:"problem" validate:"maxLength=10240"`
|
||||
Specialist_Code *string `json:"dstSpecialist_code"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -30,9 +30,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
DstUnit_Code *string `json:"dstUnit-code"`
|
||||
DstDoctor_Code *string `json:"dstDoctor-code"`
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Specialist_Code *string `json:"dstSpecialist-code"`
|
||||
Doctor_Code *string `json:"doctor-code"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
@@ -63,29 +63,29 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Encounter *ee.Encounter `json:"encounter,omitempty"`
|
||||
Date *time.Time `json:"date"`
|
||||
Problem *string `json:"problem"`
|
||||
Solution *string `json:"solution"`
|
||||
DstUnit_Code *string `json:"dstUnit_code"`
|
||||
DstUnit *eu.Unit `json:"dstUnit,omitempty"`
|
||||
DstDoctor_Code *string `json:"dstDoctor_code"`
|
||||
DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"`
|
||||
RepliedAt *time.Time `json:"repliedAt"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Encounter *ee.Encounter `json:"encounter,omitempty"`
|
||||
Date *time.Time `json:"date"`
|
||||
Problem *string `json:"problem"`
|
||||
Solution *string `json:"solution"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Doctor *ed.Doctor `json:"doctor,omitempty"`
|
||||
RepliedAt *time.Time `json:"repliedAt"`
|
||||
}
|
||||
|
||||
func (d Consultation) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Encounter_Id: d.Encounter_Id,
|
||||
Encounter: d.Encounter,
|
||||
Date: d.Date,
|
||||
Problem: d.Problem,
|
||||
Solution: d.Solution,
|
||||
DstUnit_Code: d.DstUnit_Code,
|
||||
DstUnit: d.DstUnit,
|
||||
DstDoctor_Code: d.DstDoctor_Code,
|
||||
DstDoctor: d.DstDoctor,
|
||||
Encounter_Id: d.Encounter_Id,
|
||||
Encounter: d.Encounter,
|
||||
Date: d.Date,
|
||||
Problem: d.Problem,
|
||||
Solution: d.Solution,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Doctor: d.Doctor,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
)
|
||||
|
||||
type Consultation struct {
|
||||
@@ -15,11 +15,11 @@ type Consultation struct {
|
||||
Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"`
|
||||
Date *time.Time `json:"date"`
|
||||
|
||||
Problem *string `json:"case" gorm:"size:10240"`
|
||||
Solution *string `json:"solution" gorm:"size:10240"`
|
||||
DstUnit_Code *string `json:"dstUnit_code"`
|
||||
DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Code;references:Code"`
|
||||
DstDoctor_Code *string `json:"dstDoctor_code"`
|
||||
DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Code;references:Code"`
|
||||
RepliedAt *time.Time `json:"repliedAt"`
|
||||
Problem *string `json:"case" gorm:"size:10240"`
|
||||
Solution *string `json:"solution" gorm:"size:10240"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Code;references:Code"`
|
||||
RepliedAt *time.Time `json:"repliedAt"`
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
@@ -66,8 +65,6 @@ type ResponseDto struct {
|
||||
ecore.Main
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Encounter *ee.Encounter `json:"encounter,omitempty"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
@@ -81,8 +78,6 @@ func (d ControlLetter) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Encounter_Id: d.Encounter_Id,
|
||||
Encounter: d.Encounter,
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Subspecialist_Code: d.Subspecialist_Code,
|
||||
|
||||
@@ -8,15 +8,12 @@ import (
|
||||
ee "simrs-vx/internal/domain/main-entities/encounter"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type ControlLetter struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -69,8 +68,6 @@ type ResponseDto struct {
|
||||
Employee *ee.Employee `json:"employee,omitempty"`
|
||||
IHS_Number *string `json:"ihs_number"`
|
||||
SIP_Number *string `json:"sip_number"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" `
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
@@ -84,8 +81,6 @@ func (d Doctor) ToResponse() ResponseDto {
|
||||
Employee: d.Employee,
|
||||
IHS_Number: d.IHS_Number,
|
||||
SIP_Number: d.SIP_Number,
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Subspecialist_Code: d.Subspecialist_Code,
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -17,8 +16,6 @@ type Doctor struct {
|
||||
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||
SIP_Number *string `json:"sip_number" gorm:"unique;size:20"`
|
||||
SIP_ExpiredDate *time.Time `json:"sip_expiredDate"`
|
||||
Unit_Code *string `json:"unit_code" gorm:"size:10"`
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
Specialist_Code *string `json:"specialist_code" gorm:"size:10"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"`
|
||||
|
||||
@@ -30,7 +30,6 @@ import (
|
||||
er "simrs-vx/internal/domain/main-entities/rehab/base"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
@@ -39,7 +38,6 @@ type CreateDto struct {
|
||||
Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"`
|
||||
SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub
|
||||
Infra_Code *string `json:"infra_code"` // for inpatient
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
VisitDate time.Time `json:"visitDate"`
|
||||
@@ -96,7 +94,7 @@ type ReadListDto struct {
|
||||
EndDate *string `json:"end-date"`
|
||||
PaymentMethod_Code *string `json:"paymentMethod-code"`
|
||||
Status_Code *string `json:"status-code"`
|
||||
Unit_Code *string `json:"unit-code"`
|
||||
Specialist_Code *string `json:"specialist-code"`
|
||||
|
||||
pa.AuthInfo
|
||||
}
|
||||
@@ -170,7 +168,7 @@ type CheckinDto struct {
|
||||
pa.AuthInfo
|
||||
}
|
||||
|
||||
type SwitchUnitDto struct {
|
||||
type SwitchSpecialistDto struct {
|
||||
Id uint `json:"id"`
|
||||
PolySwitchCode *ere.PolySwitchCode `json:"polySwitchCode"`
|
||||
InternalReferences *[]eir.CreateDto `json:"internalReferences" validate:"required"`
|
||||
@@ -180,7 +178,7 @@ type SwitchUnitDto struct {
|
||||
pa.AuthInfo
|
||||
}
|
||||
|
||||
type ApproveCancelUnitDto struct {
|
||||
type ApproveCancelSpecialistDto struct {
|
||||
Id uint `json:"id"`
|
||||
InternalReferences_Id uint `json:"internalReferences_id" validate:"required"`
|
||||
Dst_Doctor_Code *string `json:"dst_doctor_code"`
|
||||
@@ -194,12 +192,10 @@ type ResponseDto struct {
|
||||
Patient *ep.Patient `json:"patient,omitempty"`
|
||||
RegisteredAt *time.Time `json:"registeredAt"`
|
||||
Class_Code ere.EncounterClassCode `json:"class_code"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
VisitDate time.Time `json:"visitDate"`
|
||||
PaymentMethod_Code ere.AllPaymentMethodCode `json:"paymentMethod_code"`
|
||||
InsuranceCompany_Code *string `json:"insuranceCompany_code"`
|
||||
@@ -244,8 +240,6 @@ func (d Encounter) ToResponse() ResponseDto {
|
||||
Patient: d.Patient,
|
||||
RegisteredAt: d.RegisteredAt,
|
||||
Class_Code: d.Class_Code,
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Subspecialist_Code: d.Subspecialist_Code,
|
||||
@@ -297,3 +291,8 @@ func ToResponseList(data []Encounter) []ResponseDto {
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
type CreateWithPatientDto struct {
|
||||
Encounter CreateDto `json:"encounter"`
|
||||
Patient ep.CreateDto `json:"patient"`
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
er "simrs-vx/internal/domain/main-entities/rehab/base"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type Encounter struct {
|
||||
@@ -34,8 +33,6 @@ type Encounter struct {
|
||||
Patient *ep.Patient `json:"patient,omitempty" gorm:"foreignKey:Patient_Id;references:Id"`
|
||||
RegisteredAt *time.Time `json:"registeredAt"`
|
||||
Class_Code ere.EncounterClassCode `json:"class_code" gorm:"not null;size:10"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
|
||||
@@ -5,17 +5,17 @@ import (
|
||||
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Encounter_Id *uint `json:"-"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Nurse_Code *string `json:"nurse_code"`
|
||||
Status_Code erc.DataApprovalCode `json:"status_code"`
|
||||
SrcDoctor_Code *string `json:"srcDoctor_code"`
|
||||
SrcNurse_Code *string `json:"srcNurse_code"`
|
||||
Encounter_Id *uint `json:"-"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Nurse_Code *string `json:"nurse_code"`
|
||||
Status_Code erc.DataApprovalCode `json:"status_code"`
|
||||
SrcDoctor_Code *string `json:"srcDoctor_code"`
|
||||
SrcNurse_Code *string `json:"srcNurse_code"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -25,10 +25,10 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Unit_Code *uint `json:"unit-code"`
|
||||
Doctor_Code *uint `json:"doctor-code"`
|
||||
Status_Code erc.DataApprovalCode `json:"status-code"`
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Specialist_Code *uint `json:"specialist-code"`
|
||||
Doctor_Code *uint `json:"doctor-code"`
|
||||
Status_Code erc.DataApprovalCode `json:"status-code"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
@@ -53,22 +53,22 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
Doctor_Code *string `json:"doctor_id"`
|
||||
Doctor *ed.Doctor `json:"doctor,omitempty"`
|
||||
Status_Code *erc.DataApprovalCode `json:"status_code"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Doctor_Code *string `json:"doctor_id"`
|
||||
Doctor *ed.Doctor `json:"doctor,omitempty"`
|
||||
Status_Code *erc.DataApprovalCode `json:"status_code"`
|
||||
}
|
||||
|
||||
func (d InternalReference) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Encounter_Id: d.Encounter_Id,
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Doctor: d.Doctor,
|
||||
Status_Code: d.Status_Code,
|
||||
Encounter_Id: d.Encounter_Id,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Doctor: d.Doctor,
|
||||
Status_Code: d.Status_Code,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
|
||||
@@ -6,21 +6,21 @@ 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"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
)
|
||||
|
||||
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"`
|
||||
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"`
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_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"`
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
ei "simrs-vx/internal/domain/main-entities/infra"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Code *string `json:"code" validate:"maxLength=20"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
IHS_Number *string `json:"ihs_number" validate:"maxLength=20"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Infra_Code *string `json:"infra_code"`
|
||||
Code *string `json:"code" validate:"maxLength=20"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
IHS_Number *string `json:"ihs_number" validate:"maxLength=20"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Infra_Code *string `json:"infra_code"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -22,11 +22,11 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Code *string `json:"code"`
|
||||
Employee_Id *uint `json:"employee-id"`
|
||||
IHS_Number *string `json:"ihs-number"`
|
||||
Unit_Code *string `json:"unit-code"`
|
||||
Infra_Code *string `json:"infra-code"`
|
||||
Code *string `json:"code"`
|
||||
Employee_Id *uint `json:"employee-id"`
|
||||
IHS_Number *string `json:"ihs-number"`
|
||||
Specialist_Code *string `json:"specialist-code"`
|
||||
Infra_Code *string `json:"infra-code"`
|
||||
}
|
||||
type ReadDetailDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
@@ -53,26 +53,26 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Code *string `json:"code"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
Employee *ee.Employee `json:"employee,omitempty"`
|
||||
IHS_Number *string `json:"ihs_number"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
Infra_Code *string `json:"infra_code"`
|
||||
Infra *ei.Infra `json:"infra,omitempty"`
|
||||
Code *string `json:"code"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
Employee *ee.Employee `json:"employee,omitempty"`
|
||||
IHS_Number *string `json:"ihs_number"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Infra_Code *string `json:"infra_code"`
|
||||
Infra *ei.Infra `json:"infra,omitempty"`
|
||||
}
|
||||
|
||||
func (d Nurse) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Code: d.Code,
|
||||
Employee_Id: d.Employee_Id,
|
||||
Employee: d.Employee,
|
||||
IHS_Number: d.IHS_Number,
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Infra_Code: d.Infra_Code,
|
||||
Infra: d.Infra,
|
||||
Code: d.Code,
|
||||
Employee_Id: d.Employee_Id,
|
||||
Employee: d.Employee,
|
||||
IHS_Number: d.IHS_Number,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Infra_Code: d.Infra_Code,
|
||||
Infra: d.Infra,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
|
||||
@@ -4,17 +4,17 @@ import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
ei "simrs-vx/internal/domain/main-entities/infra"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
)
|
||||
|
||||
type Nurse struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Code *string `json:"code" gorm:"unique;size:20"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||
Unit_Code *string `json:"unit_code" gorm:"size:10"`
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
Infra_Code *string `json:"infra_code" gorm:"size:10"`
|
||||
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"`
|
||||
ecore.Main // adjust this according to the needs
|
||||
Code *string `json:"code" gorm:"unique;size:20"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||
IHS_Number *string `json:"ihs_number" gorm:"unique;size:20"`
|
||||
Specialist_Code *string `json:"specialist_code" gorm:"size:10"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Infra_Code *string `json:"infra_code" gorm:"size:10"`
|
||||
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"`
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime" validate:"maxLength=5"`
|
||||
EndTime *string `json:"endTime" validate:"maxLength=5"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime" validate:"maxLength=5"`
|
||||
EndTime *string `json:"endTime" validate:"maxLength=5"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -20,11 +20,11 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Doctor_Code *string `json:"doctor-code"`
|
||||
Unit_Code *string `json:"unit-code"`
|
||||
Day_Code *erc.DayCode `json:"day-code"`
|
||||
StartTime *string `json:"startTime"`
|
||||
EndTime *string `json:"endTime"`
|
||||
Doctor_Code *string `json:"doctor-code"`
|
||||
Specialist_Code *string `json:"specialist-code"`
|
||||
Day_Code *erc.DayCode `json:"day-code"`
|
||||
StartTime *string `json:"startTime"`
|
||||
EndTime *string `json:"endTime"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
@@ -48,20 +48,20 @@ type MetaDto struct {
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime"`
|
||||
EndTime *string `json:"endTime"`
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime"`
|
||||
EndTime *string `json:"endTime"`
|
||||
}
|
||||
|
||||
func (d PracticeSchedule) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Unit_Code: d.Unit_Code,
|
||||
Day_Code: d.Day_Code,
|
||||
StartTime: d.StartTime,
|
||||
EndTime: d.EndTime,
|
||||
Doctor_Code: d.Doctor_Code,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Day_Code: d.Day_Code,
|
||||
StartTime: d.StartTime,
|
||||
EndTime: d.EndTime,
|
||||
}
|
||||
resp.Main = d.Main
|
||||
return resp
|
||||
|
||||
@@ -3,17 +3,17 @@ package practiceschedule
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ed "simrs-vx/internal/domain/main-entities/doctor"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
)
|
||||
|
||||
type PracticeSchedule struct {
|
||||
ecore.Main // adjust this according to the needs
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime" gorm:"size:5"`
|
||||
EndTime *string `json:"endTime" gorm:"size:5"`
|
||||
ecore.Main // adjust this according to the needs
|
||||
Doctor_Code *string `json:"doctor_code"`
|
||||
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Day_Code *erc.DayCode `json:"day_code"`
|
||||
StartTime *string `json:"startTime" gorm:"size:5"`
|
||||
EndTime *string `json:"endTime" gorm:"size:5"`
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ type ProcedureRoom struct {
|
||||
Code string `json:"code" gorm:"unique;size:20"` // copied from infra code
|
||||
Infra_Code *string `json:"infra_code" gorm:"size:20;unique"`
|
||||
Type_Code *ero.ProdcedureRoomTypeCode `json:"type_code" gorm:"size:10"`
|
||||
Unit_Code *string `json:"unit_code" gorm:"size:20"`
|
||||
Specialist_Code *string `json:"specialist_code" gorm:"size:20"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:20"`
|
||||
}
|
||||
|
||||
@@ -5,14 +5,12 @@ import (
|
||||
ei "simrs-vx/internal/domain/main-entities/infra"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Code *string `json:"code"`
|
||||
Infra_Code *string `json:"infra_code"`
|
||||
Type_Code string `json:"type_code"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
}
|
||||
@@ -26,7 +24,6 @@ type ReadListDto struct {
|
||||
type FilterDto struct {
|
||||
Infra_Code *string `json:"infra-code"`
|
||||
Type_Code string `json:"type-code"`
|
||||
Unit_Code *string `json:"unit-code"`
|
||||
Specialist_Code *string `json:"specialist-code"`
|
||||
Subspecialist_Code *string `json:"subspecialist-code"`
|
||||
}
|
||||
@@ -56,8 +53,6 @@ type ResponseDto struct {
|
||||
Type_Code *string `json:"type_code"`
|
||||
Infra_Code *string `json:"infra_code"`
|
||||
Infra *ei.Infra `json:"infra,omitempty"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
Specialist_Code *string `json:"specialist_code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty"`
|
||||
Subspecialist_Code *string `json:"subspecialist_code"`
|
||||
@@ -70,8 +65,6 @@ func (d ProcedureRoom) ToResponse() ResponseDto {
|
||||
Infra_Code: d.Infra_Code,
|
||||
Infra: d.Infra,
|
||||
Type_Code: (*string)(d.Type_Code),
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Specialist_Code: d.Specialist_Code,
|
||||
Specialist: d.Specialist,
|
||||
Subspecialist_Code: d.Subspecialist_Code,
|
||||
|
||||
@@ -5,13 +5,11 @@ import (
|
||||
ebase "simrs-vx/internal/domain/main-entities/procedure-room/base"
|
||||
es "simrs-vx/internal/domain/main-entities/specialist"
|
||||
ess "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type ProcedureRoom struct {
|
||||
ebase.ProcedureRoom
|
||||
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"`
|
||||
}
|
||||
|
||||
@@ -4,14 +4,13 @@ import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
espb "simrs-vx/internal/domain/main-entities/specialist-position/base"
|
||||
essb "simrs-vx/internal/domain/main-entities/subspecialist/base"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Id *uint `json:"id"`
|
||||
Code string `json:"code" validate:"maxLength=10"`
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Id *uint `json:"id"`
|
||||
Installation_Code string `json:"installation_code"`
|
||||
Code string `json:"code" validate:"maxLength=10"`
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
@@ -22,10 +21,9 @@ type ReadListDto struct {
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Unit_Code *string `json:"unit-code"`
|
||||
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
@@ -58,8 +56,6 @@ type ResponseDto struct {
|
||||
ecore.SmallMain
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
SpecialistPositions []espb.Basic `json:"specialistPositions,omitempty"`
|
||||
Subspecialists []essb.Basic `json:"subspecialists,omitempty"`
|
||||
}
|
||||
@@ -68,8 +64,6 @@ func (d Specialist) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
Unit: d.Unit,
|
||||
Unit_Code: d.Unit_Code,
|
||||
SpecialistPositions: d.SpecialistPositions,
|
||||
Subspecialists: d.Subspecialists,
|
||||
}
|
||||
|
||||
@@ -2,17 +2,17 @@ package specialist
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ei "simrs-vx/internal/domain/main-entities/installation"
|
||||
eub "simrs-vx/internal/domain/main-entities/specialist-position/base"
|
||||
essb "simrs-vx/internal/domain/main-entities/subspecialist/base"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type Specialist struct {
|
||||
ecore.SmallMain // adjust this according to the needs
|
||||
Code string `json:"code" gorm:"unique;size:20"`
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
Unit_Code *string `json:"unit_code" gorm:"size:20"`
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
SpecialistPositions []eub.Basic `json:"specialistPositions,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Subspecialists []essb.Basic `json:"subspecialists,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
ecore.SmallMain // adjust this according to the needs
|
||||
Code string `json:"code" gorm:"unique;size:20"`
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
Installation_Code string `json:"installation_code" gorm:"size:20"`
|
||||
Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Code;references:Code"`
|
||||
SpecialistPositions []eub.Basic `json:"specialistPositions,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
Subspecialists []essb.Basic `json:"subspecialists,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"`
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
type Basic struct {
|
||||
ecore.SmallMain // adjust this according to the needs
|
||||
Code string `json:"code" gorm:"unique;size:20"`
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
Name string `json:"name" gorm:"size:100"`
|
||||
Specialist_Code *string `json:"specialist_code" gorm:"size:20"`
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
)
|
||||
|
||||
type Basic struct {
|
||||
ecore.SmallMain // adjust this according to the needs
|
||||
Unit_Code *string `json:"unit_code" gorm:"size:10"`
|
||||
Code string `json:"code" gorm:"unique;size:10;not null"`
|
||||
Name string `json:"name" gorm:"size:30;not null"`
|
||||
HeadStatus bool `json:"headStatus"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"`
|
||||
}
|
||||
|
||||
func (Basic) TableName() string {
|
||||
return "UnitPosition"
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Unit_Code *string `json:"unit_code" validate:"required"`
|
||||
Code string `json:"code" validate:"maxLength=10;required"`
|
||||
Name string `json:"name" validate:"maxLength=30;required"`
|
||||
HeadStatus bool `json:"headStatus"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
FilterDto
|
||||
Includes string `json:"includes"`
|
||||
Sort string `json:"sort"`
|
||||
Pagination ecore.Pagination
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Unit_Code *string `json:"unit-code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
HeadStatus *bool `json:"head-status"`
|
||||
Employee_Id *uint `json:"employee-id"`
|
||||
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
CreateDto
|
||||
}
|
||||
|
||||
type DeleteDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type MetaDto struct {
|
||||
PageNumber int `json:"page_number"`
|
||||
PageSize int `json:"page_size"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.SmallMain
|
||||
Unit_Code *string `json:"unit_code"`
|
||||
Unit *eu.Unit `json:"unit,omitempty"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
HeadStatus bool `json:"headStatus"`
|
||||
Employee_Id *uint `json:"employee_id"`
|
||||
Employee *ee.Employee `json:"employee,omitempty"`
|
||||
}
|
||||
|
||||
func (d UnitPosition) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Unit_Code: d.Unit_Code,
|
||||
Unit: d.Unit,
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
HeadStatus: d.HeadStatus,
|
||||
Employee_Id: d.Employee_Id,
|
||||
Employee: d.Employee,
|
||||
}
|
||||
resp.SmallMain = d.SmallMain
|
||||
return resp
|
||||
}
|
||||
|
||||
func ToResponseList(data []UnitPosition) []ResponseDto {
|
||||
resp := make([]ResponseDto, len(data))
|
||||
for i, u := range data {
|
||||
resp[i] = u.ToResponse()
|
||||
}
|
||||
return resp
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
eub "simrs-vx/internal/domain/main-entities/unit-position/base"
|
||||
)
|
||||
|
||||
type UnitPosition struct {
|
||||
eub.Basic
|
||||
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ei "simrs-vx/internal/domain/main-entities/installation"
|
||||
eipb "simrs-vx/internal/domain/main-entities/unit-position/base"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
Id *uint `json:"id"`
|
||||
Installation_Code *string `json:"installation_code"`
|
||||
Code string `json:"code" validate:"maxLength=20"`
|
||||
Name string `json:"name" validate:"maxLength=50"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
FilterDto
|
||||
Includes string `json:"includes"`
|
||||
Sort string `json:"sort"`
|
||||
Pagination ecore.Pagination
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
Installation_Code *string `json:"installation-code"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
Installation_Code *string `json:"installation_code"`
|
||||
Code *string `json:"code"`
|
||||
Includes string `json:"includes"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
CreateDto
|
||||
}
|
||||
|
||||
type DeleteDto struct {
|
||||
Id *uint16 `json:"id"`
|
||||
Code *string `json:"code"`
|
||||
}
|
||||
|
||||
type MetaDto struct {
|
||||
PageNumber int `json:"page_number"`
|
||||
PageSize int `json:"page_size"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type ResponseDto struct {
|
||||
ecore.SmallMain
|
||||
Installation_Code *string `json:"installation_code"`
|
||||
Installation *ei.Installation `json:"installation,omitempty"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
UnitPositions []eipb.Basic `json:"unitPositions,omitempty"`
|
||||
}
|
||||
|
||||
func (d Unit) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
Installation_Code: d.Installation_Code,
|
||||
Code: d.Code,
|
||||
Name: d.Name,
|
||||
UnitPositions: d.UnitPositions,
|
||||
}
|
||||
resp.SmallMain = d.SmallMain
|
||||
if d.Installation != nil {
|
||||
resp.Installation = d.Installation
|
||||
}
|
||||
return resp
|
||||
}
|
||||
|
||||
func ToResponseList(data []Unit) []ResponseDto {
|
||||
resp := make([]ResponseDto, len(data))
|
||||
for i, u := range data {
|
||||
resp[i] = u.ToResponse()
|
||||
}
|
||||
return resp
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ei "simrs-vx/internal/domain/main-entities/installation"
|
||||
eub "simrs-vx/internal/domain/main-entities/unit-position/base"
|
||||
ero "simrs-vx/internal/domain/references/organization"
|
||||
)
|
||||
|
||||
type Unit struct {
|
||||
ecore.SmallMain // adjust this according to the needs
|
||||
Installation_Code *string `json:"installation_code" gorm:"size:20"`
|
||||
Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Code;references:Code"`
|
||||
Code string `json:"code" gorm:"unique;size:20"`
|
||||
Name string `json:"name" gorm:"size:50"`
|
||||
Type_Code *ero.UnitTypeCode `json:"type_code"`
|
||||
UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
|
||||
}
|
||||
@@ -240,8 +240,8 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) {
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.SwitchUnitDto{}
|
||||
func (obj myBase) RequestSwitchSpecialist(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.SwitchSpecialistDto{}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
@@ -252,7 +252,7 @@ func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// validate request body
|
||||
if valid := validateRequestSwitchUnit(w, dto); !valid {
|
||||
if valid := validateRequestSwitchSpecialist(w, dto); !valid {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -263,12 +263,12 @@ func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
dto.AuthInfo = *authInfo
|
||||
dto.Id = uint(id)
|
||||
res, err := u.RequestSwitchUnit(dto)
|
||||
res, err := u.RequestSwitchSpecialist(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelUnitDto{}
|
||||
func (obj myBase) ApproveSwitchSpecialist(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelSpecialistDto{}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
@@ -286,12 +286,12 @@ func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto.AuthInfo = *authInfo
|
||||
dto.Id = uint(id)
|
||||
|
||||
res, err := u.ApproveSwitchUnit(dto)
|
||||
res, err := u.ApproveSwitchSpecialist(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelUnitDto{}
|
||||
func (obj myBase) CancelSwitchSpecialist(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelSpecialistDto{}
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
@@ -309,6 +309,32 @@ func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto.AuthInfo = *authInfo
|
||||
dto.Id = uint(id)
|
||||
|
||||
res, err := u.CancelSwitchUnit(dto)
|
||||
res, err := u.CancelSwitchSpecialist(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) CreateWithPatient(w http.ResponseWriter, r *http.Request) {
|
||||
authInfo, err := pa.GetAuthInfo(r)
|
||||
if err != nil {
|
||||
rw.WriteJSON(w, http.StatusUnauthorized, d.IS{"message": err.Error()}, nil)
|
||||
}
|
||||
|
||||
dto := e.CreateWithPatientDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
// validate SubClass
|
||||
if err := verifyClassCode(dto.Encounter); err != nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
dto.Encounter.AuthInfo = *authInfo
|
||||
dto.Patient.AuthInfo = *authInfo
|
||||
res, err := u.CreateWithPatient(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool)
|
||||
return true
|
||||
}
|
||||
|
||||
func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) {
|
||||
func validateRequestSwitchSpecialist(w http.ResponseWriter, i e.SwitchSpecialistDto) (valid bool) {
|
||||
// validate poly-switch-code
|
||||
if i.PolySwitchCode == nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
@@ -84,7 +84,7 @@ func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid
|
||||
}
|
||||
|
||||
for _, v := range *i.InternalReferences {
|
||||
if v.Unit_Code == nil {
|
||||
if v.Specialist_Code == nil {
|
||||
rw.DataResponse(w, nil, d.FieldError{
|
||||
Code: dataValidationFail,
|
||||
Message: "internalReferences.unit_code required",
|
||||
|
||||
@@ -115,8 +115,6 @@ import (
|
||||
subspecialist "simrs-vx/internal/interface/main-handler/subspecialist"
|
||||
subspecialistposition "simrs-vx/internal/interface/main-handler/subspecialist-position"
|
||||
therapyprotocol "simrs-vx/internal/interface/main-handler/therapy-protocol"
|
||||
unit "simrs-vx/internal/interface/main-handler/unit"
|
||||
unitposition "simrs-vx/internal/interface/main-handler/unit-position"
|
||||
uom "simrs-vx/internal/interface/main-handler/uom"
|
||||
vehicle "simrs-vx/internal/interface/main-handler/vehicle"
|
||||
vehiclehist "simrs-vx/internal/interface/main-handler/vehicle-hist"
|
||||
@@ -194,9 +192,10 @@ func SetRoutes() http.Handler {
|
||||
"PATCH /{id}/cancel": encounter.O.Cancel,
|
||||
"PATCH /{id}/reject": encounter.O.Reject,
|
||||
"PATCH /{id}/skip": encounter.O.Skip,
|
||||
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit,
|
||||
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
|
||||
"PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit,
|
||||
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchSpecialist,
|
||||
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchSpecialist,
|
||||
"PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchSpecialist,
|
||||
"POST /create-with-patient": encounter.O.CreateWithPatient,
|
||||
})
|
||||
hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{
|
||||
"GET /": mcuorder.O.GetList,
|
||||
@@ -375,9 +374,7 @@ func SetRoutes() http.Handler {
|
||||
"DELETE /{id}": installation.O.Delete,
|
||||
"POST /bulk": installation.O.CreateBulk,
|
||||
})
|
||||
hc.RegCrudByCode(r, "/v1/unit", unit.O)
|
||||
hc.RegCrudByCode(r, "/v1/installation-position", installationposition.O)
|
||||
hc.RegCrudByCode(r, "/v1/unit-position", unitposition.O)
|
||||
hk.GroupRoutes("/v1/specialist", r, hk.MapHandlerFunc{
|
||||
"GET /": specialist.O.GetList,
|
||||
"GET /{id}": specialist.O.GetDetail,
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
rw "github.com/karincake/risoles"
|
||||
sf "github.com/karincake/semprit"
|
||||
|
||||
// ua "github.com/karincake/tumpeng/auth/svc"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
u "simrs-vx/internal/use-case/main-use-case/unit-position"
|
||||
)
|
||||
|
||||
type myBase struct{}
|
||||
|
||||
var O myBase
|
||||
|
||||
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.CreateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
res, err := u.Create(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ReadListDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
res, err := u.ReadList(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
code := rw.ValidateString(w, "code", r.PathValue("code"))
|
||||
if code == "" {
|
||||
return
|
||||
}
|
||||
dto := e.ReadDetailDto{}
|
||||
dto.Code = &code
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
|
||||
code := rw.ValidateString(w, "code", r.PathValue("code"))
|
||||
if code == "" {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
dto.Code = code
|
||||
res, err := u.Update(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
code := rw.ValidateString(w, "code", r.PathValue("code"))
|
||||
if code == "" {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.DeleteDto{}
|
||||
dto.Code = &code
|
||||
res, err := u.Delete(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
rw "github.com/karincake/risoles"
|
||||
sf "github.com/karincake/semprit"
|
||||
|
||||
// ua "github.com/karincake/tumpeng/auth/svc"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
u "simrs-vx/internal/use-case/main-use-case/unit"
|
||||
)
|
||||
|
||||
type myBase struct{}
|
||||
|
||||
var O myBase
|
||||
|
||||
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.CreateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
res, err := u.Create(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ReadListDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
res, err := u.ReadList(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
code := rw.ValidateString(w, "code", r.PathValue("code"))
|
||||
if code == "" {
|
||||
return
|
||||
}
|
||||
dto := e.ReadDetailDto{}
|
||||
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
dto.Code = &code
|
||||
res, err := u.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
|
||||
code := rw.ValidateString(w, "code", r.PathValue("code"))
|
||||
if code == "" {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
dto.Code = code
|
||||
res, err := u.Update(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
code := rw.ValidateString(w, "code", r.PathValue("code"))
|
||||
if code == "" {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.DeleteDto{}
|
||||
dto.Code = &code
|
||||
res, err := u.Delete(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -109,8 +109,6 @@ import (
|
||||
subspecialist "simrs-vx/internal/domain/main-entities/subspecialist"
|
||||
subspecialistposition "simrs-vx/internal/domain/main-entities/subspecialist-position"
|
||||
therapyprotocol "simrs-vx/internal/domain/main-entities/therapy-protocol"
|
||||
unit "simrs-vx/internal/domain/main-entities/unit"
|
||||
unitposition "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
uom "simrs-vx/internal/domain/main-entities/uom"
|
||||
user "simrs-vx/internal/domain/main-entities/user"
|
||||
userfes "simrs-vx/internal/domain/main-entities/user-fes"
|
||||
@@ -135,7 +133,6 @@ func getMainEntities() []any {
|
||||
&division.Division{},
|
||||
&divisionposition.DivisionPosition{},
|
||||
&installation.Installation{},
|
||||
&unit.Unit{},
|
||||
&village.Village{},
|
||||
&district.District{},
|
||||
®ency.Regency{},
|
||||
@@ -237,7 +234,6 @@ func getMainEntities() []any {
|
||||
&generalconsent.GeneralConsent{},
|
||||
&deathcause.DeathCause{},
|
||||
&installationposition.InstallationPosition{},
|
||||
&unitposition.UnitPosition{},
|
||||
&specialistposition.SpecialistPosition{},
|
||||
&subspecialistposition.SubspecialistPosition{},
|
||||
&responsibledoctorhist.ResponsibleDoctorHist{},
|
||||
|
||||
@@ -87,32 +87,32 @@ func (obj myBase) UpdateStatus(w http.ResponseWriter, r *http.Request) {
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
func (obj myBase) RequestSwitchSpecialist(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.Encounter{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
res, err := u.RequestSwitchUnit(dto)
|
||||
res, err := u.RequestSwitchSpecialist(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelUnitDto{}
|
||||
func (obj myBase) ApproveSwitchSpecialist(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelSpecialistDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
res, err := u.ApproveSwitchUnit(dto)
|
||||
res, err := u.ApproveSwitchSpecialist(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) CancelSwitchUnit(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelUnitDto{}
|
||||
func (obj myBase) CancelSwitchSpecialist(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.ApproveCancelSpecialistDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
res, err := u.CancelSwitchUnit(dto)
|
||||
res, err := u.CancelSwitchSpecialist(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
rw "github.com/karincake/risoles"
|
||||
// ua "github.com/karincake/tumpeng/auth/svc"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
u "simrs-vx/internal/use-case/simgos-sync-use-case/new/unit"
|
||||
)
|
||||
|
||||
type myBase struct{}
|
||||
|
||||
var O myBase
|
||||
|
||||
func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
|
||||
dto := e.CreateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
res, err := u.Create(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) CreateLog(w http.ResponseWriter, r *http.Request) {
|
||||
dto := esync.SimxLogDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
res, err := u.CreateSimxLog(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.UpdateDto{}
|
||||
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
|
||||
return
|
||||
}
|
||||
|
||||
val := uint16(id)
|
||||
dto.Id = &val
|
||||
|
||||
res, err := u.Update(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
|
||||
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
|
||||
id := rw.ValidateInt(w, "id", r.PathValue("id"))
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := e.DeleteDto{}
|
||||
val := uint16(id)
|
||||
dto.Id = &val
|
||||
|
||||
res, err := u.Delete(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
}
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/soapi"
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/specialist"
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/subspecialist"
|
||||
"simrs-vx/internal/interface/simgos-sync-handler/new/unit"
|
||||
|
||||
sd "simrs-vx/internal/interface/simgos-sync-handler/seeder"
|
||||
|
||||
@@ -55,7 +54,6 @@ func SetRoutes() http.Handler {
|
||||
/******************** SvcToOld ******************/
|
||||
prefixnew := "/new-to-old"
|
||||
hc.SyncCrud(r, prefixnew+"/v1/installation", installation.O)
|
||||
hc.SyncCrud(r, prefixnew+"/v1/unit", unit.O)
|
||||
hc.SyncCrud(r, prefixnew+"/v1/division", division.O)
|
||||
hc.SyncCrud(r, prefixnew+"/v1/specialist", specialist.O)
|
||||
hc.SyncCrud(r, prefixnew+"/v1/subspecialist", subspecialist.O)
|
||||
@@ -74,9 +72,9 @@ func SetRoutes() http.Handler {
|
||||
"PATCH /{id}/checkin": encounter.O.Checkin,
|
||||
"PATCH /{id}/checkout": encounter.O.Checkout,
|
||||
"PATCH /{id}/update-status": encounter.O.UpdateStatus,
|
||||
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit,
|
||||
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
|
||||
"PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchUnit,
|
||||
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchSpecialist,
|
||||
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchSpecialist,
|
||||
"PATCH /{id}/cancel-switch-unit": encounter.O.CancelSwitchSpecialist,
|
||||
})
|
||||
hc.SyncCrud(r, prefixnew+"/v1/soapi", soapi.O)
|
||||
|
||||
|
||||
@@ -29,14 +29,12 @@ import (
|
||||
er "simrs-vx/internal/domain/main-entities/registrator"
|
||||
esp "simrs-vx/internal/domain/main-entities/specialist-position"
|
||||
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"
|
||||
|
||||
udp "simrs-vx/internal/use-case/main-use-case/division-position"
|
||||
uip "simrs-vx/internal/use-case/main-use-case/installation-position"
|
||||
usp "simrs-vx/internal/use-case/main-use-case/specialist-position"
|
||||
ussp "simrs-vx/internal/use-case/main-use-case/subspecialist-position"
|
||||
uup "simrs-vx/internal/use-case/main-use-case/unit-position"
|
||||
)
|
||||
|
||||
// just return the error code
|
||||
@@ -85,7 +83,7 @@ func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) {
|
||||
func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
// get data specialist_position based on employee_id
|
||||
data, _, err := uip.ReadListData(eip.ReadListDto{
|
||||
FilterDto: eip.FilterDto{Employee_Id: &employeeId},
|
||||
Includes: "installation"}, event)
|
||||
@@ -102,28 +100,10 @@ func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
data, _, err := uup.ReadListData(eup.ReadListDto{FilterDto: eup.FilterDto{Employee_Id: &employeeId}}, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(data) > 0 {
|
||||
for _, dp := range data {
|
||||
result = append(result, "unit|"+*dp.Unit_Code+"|"+dp.Code)
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
// get data specialist_position based on employee_id
|
||||
data, _, err := usp.ReadListData(esp.ReadListDto{FilterDto: esp.FilterDto{Employee_Id: &employeeId}}, event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -141,7 +121,7 @@ func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) {
|
||||
var result []string
|
||||
|
||||
// get data unit_position based on employee_id
|
||||
// get data specialist_position based on employee_id
|
||||
data, _, err := ussp.ReadListData(essp.ReadListDto{
|
||||
FilterDto: essp.FilterDto{Employee_Id: &employeeId},
|
||||
Includes: "subspecialist"}, event)
|
||||
@@ -230,9 +210,9 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out
|
||||
outputData["doctor_code"] = doctor.Code
|
||||
|
||||
// specialist
|
||||
if doctor.Unit_Code != nil {
|
||||
atClaims["unit_code"] = doctor.Unit_Code
|
||||
outputData["unit_code"] = doctor.Unit_Code
|
||||
if doctor.Specialist_Code != nil {
|
||||
atClaims["specialist_code"] = doctor.Specialist_Code
|
||||
outputData["specialist_code"] = doctor.Specialist_Code
|
||||
}
|
||||
if doctor.Specialist_Code != nil {
|
||||
atClaims["specialist_code"] = doctor.Specialist_Code
|
||||
@@ -292,12 +272,6 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out
|
||||
return errorGetPosition
|
||||
}
|
||||
|
||||
// unit position
|
||||
unitPositions, err := getUnitPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
return errorGetPosition
|
||||
}
|
||||
|
||||
// specialist position
|
||||
specialistPositions, err := getSpecialistPosition(employee.Id, &event)
|
||||
if err != nil {
|
||||
@@ -312,7 +286,7 @@ func populateRoles(user *eu.User, input eu.LoginDto, atClaims jwt.MapClaims, out
|
||||
|
||||
roles = append(roles, divisionPositions...)
|
||||
roles = append(roles, installationPositions...)
|
||||
roles = append(roles, unitPositions...)
|
||||
roles = append(roles, specialistPositions...)
|
||||
roles = append(roles, specialistPositions...)
|
||||
roles = append(roles, subspecialistPositions...)
|
||||
// atClaims["division_positions"] = divsionPositions
|
||||
|
||||
@@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Chemo) {
|
||||
|
||||
data.Encounter_Id = inputSrc.Encounter_Id
|
||||
data.Status_Code = inputSrc.Status_Code
|
||||
data.SrcUnit_Code = inputSrc.SrcUnit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) {
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
if data.DstDoctor_Code != nil && data.DstDoctor_Code != input.AuthInfo.Doctor_Code {
|
||||
if data.Doctor_Code != nil && data.Doctor_Code != input.AuthInfo.Doctor_Code {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-handled-mismatch",
|
||||
@@ -322,7 +322,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) {
|
||||
return pl.SetLogError(&event, input)
|
||||
}
|
||||
|
||||
data.DstDoctor_Code = input.AuthInfo.Doctor_Code
|
||||
data.Doctor_Code = input.AuthInfo.Doctor_Code
|
||||
data.Solution = input.Solution
|
||||
data.RepliedAt = pu.GetTimeNow()
|
||||
err = tx.Save(&data).Error
|
||||
|
||||
@@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Consultation) {
|
||||
data.Encounter_Id = inputSrc.Encounter_Id
|
||||
data.Date = inputSrc.Date
|
||||
data.Problem = inputSrc.Problem
|
||||
data.DstUnit_Code = inputSrc.DstUnit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) {
|
||||
}
|
||||
|
||||
data.Encounter_Id = inputSrc.Encounter_Id
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
data.Subspecialist_Code = inputSrc.Subspecialist_Code
|
||||
data.Doctor_Code = inputSrc.Doctor_Code
|
||||
|
||||
@@ -21,7 +21,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Doctor) {
|
||||
data.Employee_Id = inputSrc.Employee_Id
|
||||
data.IHS_Number = inputSrc.IHS_Number
|
||||
data.SIP_Number = inputSrc.SIP_Number
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
data.Subspecialist_Code = inputSrc.Subspecialist_Code
|
||||
}
|
||||
|
||||
@@ -22,12 +22,14 @@ import (
|
||||
edc "simrs-vx/internal/domain/main-entities/death-cause"
|
||||
e "simrs-vx/internal/domain/main-entities/encounter"
|
||||
eir "simrs-vx/internal/domain/main-entities/internal-reference"
|
||||
ep "simrs-vx/internal/domain/main-entities/patient"
|
||||
es "simrs-vx/internal/domain/main-entities/soapi"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
|
||||
uv "simrs-vx/internal/use-case/bpjs-use-case/vclaim-reference"
|
||||
udc "simrs-vx/internal/use-case/main-use-case/death-cause"
|
||||
uir "simrs-vx/internal/use-case/main-use-case/internal-reference"
|
||||
up "simrs-vx/internal/use-case/main-use-case/patient"
|
||||
us "simrs-vx/internal/use-case/main-use-case/soapi"
|
||||
)
|
||||
|
||||
@@ -702,13 +704,13 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
|
||||
func RequestSwitchSpecialist(input e.SwitchSpecialistDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Responsible_Nurse.Employee.User,Responsible_Doctor.Employee"}
|
||||
var data *e.Encounter
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "RequestSwitchUnit",
|
||||
Feature: "RequestSwitchSpecialist",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
@@ -718,8 +720,8 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
|
||||
unitCodes := make(map[string]struct{})
|
||||
doctorCodes := make(map[string]struct{})
|
||||
for _, ref := range *input.InternalReferences {
|
||||
if ref.Unit_Code != nil {
|
||||
unitCodes[*ref.Unit_Code] = struct{}{}
|
||||
if ref.Specialist_Code != nil {
|
||||
unitCodes[*ref.Specialist_Code] = struct{}{}
|
||||
}
|
||||
if ref.Doctor_Code != nil {
|
||||
doctorCodes[*ref.Doctor_Code] = struct{}{}
|
||||
@@ -727,7 +729,7 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
|
||||
}
|
||||
|
||||
// validate unit
|
||||
if err = validateUnitCodes(unitCodes, &event); err != nil {
|
||||
if err = validateSpecialistCodes(unitCodes, &event); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -794,7 +796,7 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunRequestSwitchUnitMiddleware(requestSwitchEncounter, dataEncounter); err != nil {
|
||||
if err := mwRunner.RunRequestSwitchSpecialistMiddleware(requestSwitchEncounter, dataEncounter); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -810,13 +812,13 @@ func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "requestSwitchUnit",
|
||||
"status": "requestSwitchSpecialist",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
func ApproveSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Id: input.Id, Includes: "Responsible_Doctor.Employee"}
|
||||
var (
|
||||
data *e.Encounter
|
||||
@@ -824,12 +826,12 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
)
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "ApproveSwitchUnit",
|
||||
Feature: "ApproveSwitchSpecialist",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "approveSwitchUnit")
|
||||
pl.SetLogInfo(&event, input, "started", "approveSwitchSpecialist")
|
||||
|
||||
roleAllowed := []string{string(erg.EPCNur)}
|
||||
err = validateAuth(input.AuthInfo, roleAllowed, "request-switch-poly", &event)
|
||||
@@ -902,13 +904,13 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
}
|
||||
|
||||
// update encounter
|
||||
if err = updateEncounterApproveSwitchUnit(input, &event, tx); err != nil {
|
||||
if err = updateEncounterApproveSwitchSpecialist(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunApproveSwitchUnitMiddleware(approveSwitchEncounter, &input); err != nil {
|
||||
if err := mwRunner.RunApproveSwitchSpecialistMiddleware(approveSwitchEncounter, &input); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -931,7 +933,7 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
|
||||
}
|
||||
|
||||
func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
func CancelSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Id: input.Id}
|
||||
var (
|
||||
data *e.Encounter
|
||||
@@ -939,12 +941,12 @@ func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
)
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "CancelSwitchUnit",
|
||||
Feature: "CancelSwitchSpecialist",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "cancelSwitchUnit")
|
||||
pl.SetLogInfo(&event, input, "started", "cancelSwitchSpecialist")
|
||||
|
||||
roleAllowed := []string{string(erg.EPCNur)}
|
||||
err = validateAuth(input.AuthInfo, roleAllowed, "request-switch-poly", &event)
|
||||
@@ -998,7 +1000,7 @@ func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunCancelSwitchUnitMiddleware(cancelSwitchEncounter, &input); err != nil {
|
||||
if err := mwRunner.RunCancelSwitchSpecialistMiddleware(cancelSwitchEncounter, &input); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -1075,3 +1077,144 @@ func validateAuth(a auth.AuthInfo, roleAllowed []string, action string, event *p
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateWithPatient(input e.CreateWithPatientDto) (*d.Data, error) {
|
||||
var (
|
||||
data e.Encounter
|
||||
recentSoapiDataforCopy []es.CreateDto
|
||||
err error
|
||||
)
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Create",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
|
||||
roleAllowed := []string{string(erg.EPCReg)}
|
||||
err = validateAuth(input.Encounter.AuthInfo, roleAllowed, "create-encounter", &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// validate rehab by bpjs
|
||||
if input.Encounter.RefTypeCode == ere.RTCBpjs &&
|
||||
input.Encounter.Class_Code == ere.ECAmbulatory &&
|
||||
ere.AmbulatoryClassCode(*input.Encounter.SubClass_Code) == ere.ACCRehab {
|
||||
// get latest rehab data
|
||||
recentRehabData, err := getLatestRehabData(input.Encounter, &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// If recentRehabData is nil, then visitMode_Code = "adm"
|
||||
if recentRehabData != nil {
|
||||
// If recentRehabData is not nil, determine the visitMode_Code:
|
||||
// If the mode is "series", verify whether the visit count still remains
|
||||
// and whether the series has not expired.
|
||||
// If visitMode is "series", then get encounterAdm
|
||||
input.Encounter.VisitMode_Code, input.Encounter.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input.Encounter, &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
input.Encounter.VisitMode_Code = ere.VMCAdm
|
||||
}
|
||||
|
||||
// When visitMode_Code is "series", load the associated SOAPI record to copy its values.
|
||||
if input.Encounter.VisitMode_Code == ere.VMCSeries {
|
||||
// get data soapi
|
||||
recentSoapiDataforCopy, err = getSoapiEncounterAdm(*input.Encounter.RecentEncounterAdm, &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check if patient is new in the hospital
|
||||
input.Encounter.NewStatus, err = identifyPatientStatus(input.Encounter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
input.Encounter.Adm_Employee_Id = input.Encounter.AuthInfo.Employee_Id
|
||||
|
||||
mwRunner := newMiddlewareRunner(&event, input.Encounter.Sync)
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
// create patient
|
||||
var patientId uint
|
||||
patientData, err := up.Create(input.Patient, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if patientData != nil {
|
||||
patientId = patientData.Data.(ep.ResponseDto).Id
|
||||
}
|
||||
|
||||
// create encounter
|
||||
input.Encounter.Patient_Id = &patientId
|
||||
if resData, err := CreateData(input.Encounter, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
data = *resData
|
||||
input.Encounter.Id = data.Id
|
||||
}
|
||||
|
||||
// insert ambulatory/emergency/inpatient
|
||||
err = insertdataClassCode(input.Encounter, recentSoapiDataforCopy, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// insert vclaimReference
|
||||
if vr := input.Encounter.VclaimReference; vr != nil {
|
||||
t, _ := time.Parse("2006-01-02", vr.TglRujukan)
|
||||
_, err = uv.CreateData(ev.CreateDto{
|
||||
Encounter_Id: &data.Id,
|
||||
Date: &t,
|
||||
SrcCode: input.Encounter.Ref_Number,
|
||||
SrcName: input.Encounter.RefSource_Name,
|
||||
Number: &vr.NoSep}, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
dataEncounter, err := ReadDetailData(e.ReadDetailDto{
|
||||
Id: data.Id,
|
||||
Includes: "Adm_Employee.User,Adm_Employee.Person," +
|
||||
"Patient.Person.Relatives," +
|
||||
"Patient.Person.VclaimMember,VclaimReference," +
|
||||
"Patient.Person.Contacts,Patient.Person.Addresses"},
|
||||
&event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunCreateWithPatientMiddleware(createWithPatientPreMw, dataEncounter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err = runLogMiddleware(err, input, mwRunner); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.II{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "created",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ import (
|
||||
er "simrs-vx/internal/domain/main-entities/rehab"
|
||||
erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist"
|
||||
es "simrs-vx/internal/domain/main-entities/soapi"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
esp "simrs-vx/internal/domain/main-entities/specialist"
|
||||
|
||||
// udo "simrs-vx/internal/use-case/main-use-case/device-order"
|
||||
uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist"
|
||||
@@ -69,7 +69,7 @@ func setDataCreate(input *e.CreateDto, data *e.Encounter) {
|
||||
data.Patient_Id = input.Patient_Id
|
||||
data.RegisteredAt = input.RegisteredAt
|
||||
data.Class_Code = input.Class_Code
|
||||
data.Unit_Code = input.Unit_Code
|
||||
data.Specialist_Code = input.Specialist_Code
|
||||
data.Specialist_Code = input.Specialist_Code
|
||||
data.Subspecialist_Code = input.Subspecialist_Code
|
||||
data.VisitDate = input.VisitDate
|
||||
@@ -88,7 +88,7 @@ func setDataCreate(input *e.CreateDto, data *e.Encounter) {
|
||||
}
|
||||
|
||||
func setDataUpdate(src e.UpdateDto, dst *e.Encounter) {
|
||||
dst.Unit_Code = src.Unit_Code
|
||||
dst.Specialist_Code = src.Specialist_Code
|
||||
dst.Specialist_Code = src.Specialist_Code
|
||||
dst.Subspecialist_Code = src.Subspecialist_Code
|
||||
dst.VisitDate = src.VisitDate
|
||||
@@ -104,7 +104,7 @@ func setDataUpdate(src e.UpdateDto, dst *e.Encounter) {
|
||||
func setDataUpdateFromSource(input *e.UpdateDto, data *e.Encounter) {
|
||||
data.Patient_Id = input.Patient_Id
|
||||
data.RegisteredAt = input.RegisteredAt
|
||||
data.Unit_Code = input.Unit_Code
|
||||
data.Specialist_Code = input.Specialist_Code
|
||||
data.Specialist_Code = input.Specialist_Code
|
||||
data.Subspecialist_Code = input.Subspecialist_Code
|
||||
data.VisitDate = input.VisitDate
|
||||
@@ -853,9 +853,9 @@ func insertDataSubClassAmbulatory(input e.CreateDto, soapiData []es.CreateDto, e
|
||||
switch {
|
||||
case subCode == ere.ACCChemo:
|
||||
chemoCreate := ec.CreateDto{
|
||||
Encounter_Id: &input.Id,
|
||||
Status_Code: erc.DVCNew,
|
||||
SrcUnit_Code: input.Unit_Code,
|
||||
Encounter_Id: &input.Id,
|
||||
Status_Code: erc.DVCNew,
|
||||
Specialist_Code: input.Specialist_Code,
|
||||
}
|
||||
|
||||
// create data chemo
|
||||
@@ -977,9 +977,9 @@ func setDBError(event *pl.Event, err error, ctx any) error {
|
||||
return pl.SetLogError(event, ctx)
|
||||
}
|
||||
|
||||
func getUnits(unitIds []string, event *pl.Event) ([]eu.Unit, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "getUnits")
|
||||
var units []eu.Unit
|
||||
func getSpecialists(unitIds []string, event *pl.Event) ([]esp.Specialist, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "getSpecialists")
|
||||
var units []esp.Specialist
|
||||
err := dg.I.Where("\"Code\" IN ?", unitIds).Find(&units).Error
|
||||
if err != nil {
|
||||
event.Status = "failed"
|
||||
@@ -1009,14 +1009,14 @@ func getDoctors(doctorIds []string, event *pl.Event) ([]ed.Doctor, error) {
|
||||
return doctors, nil
|
||||
}
|
||||
|
||||
func validateUnitCodes(unitCodes map[string]struct{}, event *pl.Event) error {
|
||||
func validateSpecialistCodes(unitCodes map[string]struct{}, event *pl.Event) error {
|
||||
if len(unitCodes) > 0 {
|
||||
var codes []string
|
||||
for code := range unitCodes {
|
||||
codes = append(codes, code)
|
||||
}
|
||||
|
||||
units, err := getUnits(codes, event)
|
||||
units, err := getSpecialists(codes, event)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to fetch units: %w", err)
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.En
|
||||
tx = tx.Where("\"Encounter\".\"Status_Code\" = ?", *input.Status_Code)
|
||||
}
|
||||
|
||||
if input.Unit_Code != nil {
|
||||
tx = tx.Where("\"Encounter\".\"Unit_Code\" = ?", *input.Unit_Code)
|
||||
if input.Specialist_Code != nil {
|
||||
tx = tx.Where("\"Encounter\".\"Specialist_Code\" = ?", *input.Specialist_Code)
|
||||
}
|
||||
|
||||
if input.PaymentMethod_Code != nil {
|
||||
@@ -268,7 +268,7 @@ func UpdateStatusData(input e.UpdateStatusDto, event *pl.Event, dbx ...*gorm.DB)
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateDischargeMethod(input e.SwitchUnitDto, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
func UpdateDischargeMethod(input e.SwitchSpecialistDto, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, input, "started", "DBUpdateDischargeMethod")
|
||||
dischargeCode := setDischargeMethodCode(*input.PolySwitchCode)
|
||||
|
||||
@@ -382,7 +382,7 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo
|
||||
return recentEncounterAdm, valid, nil
|
||||
}
|
||||
|
||||
func updateEncounterApproveSwitchUnit(input e.ApproveCancelUnitDto, event *pl.Event, dbx ...*gorm.DB) (err error) {
|
||||
func updateEncounterApproveSwitchSpecialist(input e.ApproveCancelSpecialistDto, event *pl.Event, dbx ...*gorm.DB) (err error) {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
|
||||
var tx *gorm.DB
|
||||
|
||||
@@ -202,7 +202,7 @@ func (me *middlewareRunner) RunUpdateStatusMiddleware(middlewares []updateStatus
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunRequestSwitchUnitMiddleware(middleware requestSwitchUnitMw, input *e.Encounter) error {
|
||||
func (me *middlewareRunner) RunRequestSwitchSpecialistMiddleware(middleware requestSwitchSpecialistMw, input *e.Encounter) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
@@ -220,7 +220,7 @@ func (me *middlewareRunner) RunRequestSwitchUnitMiddleware(middleware requestSwi
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunApproveSwitchUnitMiddleware(middleware approveSwitchUnitMw, input *e.ApproveCancelUnitDto) error {
|
||||
func (me *middlewareRunner) RunApproveSwitchSpecialistMiddleware(middleware approveSwitchSpecialistMw, input *e.ApproveCancelSpecialistDto) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (me *middlewareRunner) RunApproveSwitchUnitMiddleware(middleware approveSwi
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunCancelSwitchUnitMiddleware(middleware cancelSwitchUnitMw, input *e.ApproveCancelUnitDto) error {
|
||||
func (me *middlewareRunner) RunCancelSwitchSpecialistMiddleware(middleware cancelSwitchSpecialistMw, input *e.ApproveCancelSpecialistDto) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
@@ -259,3 +259,22 @@ func (me *middlewareRunner) RunCancelSwitchUnitMiddleware(middleware cancelSwitc
|
||||
func (me *middlewareRunner) setMwType(mwType pu.MWType) {
|
||||
me.MwType = mwType
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunCreateWithPatientMiddleware(middlewares []createWithPatientMw, input *e.Encounter) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, nil)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func init() {
|
||||
updatestatusEncounter = append(updatestatusEncounter,
|
||||
updateStatusMw{Name: "sync-update-status-encounter", Func: plugin.UpdateStatus})
|
||||
|
||||
requestSwitchEncounter = requestSwitchUnitMw{Name: "sync-request-switch-unit-encounter", Func: plugin.RequestSwitchUnit}
|
||||
approveSwitchEncounter = approveSwitchUnitMw{Name: "sync-approve-switch-unit-encounter", Func: plugin.ApproveSwitchUnit}
|
||||
cancelSwitchEncounter = cancelSwitchUnitMw{Name: "sync-cancel-switch-unit-encounter", Func: plugin.CancelSwitchUnit}
|
||||
requestSwitchEncounter = requestSwitchSpecialistMw{Name: "sync-request-switch-unit-encounter", Func: plugin.RequestSwitchSpecialist}
|
||||
approveSwitchEncounter = approveSwitchSpecialistMw{Name: "sync-approve-switch-unit-encounter", Func: plugin.ApproveSwitchSpecialist}
|
||||
cancelSwitchEncounter = cancelSwitchSpecialistMw{Name: "sync-cancel-switch-unit-encounter", Func: plugin.CancelSwitchSpecialist}
|
||||
}
|
||||
|
||||
@@ -59,19 +59,24 @@ type updateStatusMw struct {
|
||||
Func func(input *e.Encounter) error
|
||||
}
|
||||
|
||||
type requestSwitchUnitMw struct {
|
||||
type requestSwitchSpecialistMw struct {
|
||||
Name string
|
||||
Func func(input *e.Encounter) error
|
||||
}
|
||||
|
||||
type approveSwitchUnitMw struct {
|
||||
type approveSwitchSpecialistMw struct {
|
||||
Name string
|
||||
Func func(input *e.ApproveCancelUnitDto) error
|
||||
Func func(input *e.ApproveCancelSpecialistDto) error
|
||||
}
|
||||
|
||||
type cancelSwitchUnitMw struct {
|
||||
type cancelSwitchSpecialistMw struct {
|
||||
Name string
|
||||
Func func(input *e.ApproveCancelUnitDto) error
|
||||
Func func(input *e.ApproveCancelSpecialistDto) error
|
||||
}
|
||||
|
||||
type createWithPatientMw struct {
|
||||
Name string
|
||||
Func func(input *e.Encounter) error
|
||||
}
|
||||
|
||||
type UpdateMw = updateMw
|
||||
@@ -91,6 +96,8 @@ var deletePostMw []readDetailMw
|
||||
var checkinEncounterMw checkinMw
|
||||
var checkoutEncounter checkoutMw
|
||||
var updatestatusEncounter []updateStatusMw
|
||||
var requestSwitchEncounter requestSwitchUnitMw
|
||||
var approveSwitchEncounter approveSwitchUnitMw
|
||||
var cancelSwitchEncounter cancelSwitchUnitMw
|
||||
var requestSwitchEncounter requestSwitchSpecialistMw
|
||||
var approveSwitchEncounter approveSwitchSpecialistMw
|
||||
var cancelSwitchEncounter cancelSwitchSpecialistMw
|
||||
var createWithPatientPreMw []createWithPatientMw
|
||||
var createWithPatientPostMw []createWithPatientMw
|
||||
|
||||
@@ -57,7 +57,6 @@ func createProcedureRoom(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error
|
||||
roomCreate := er.CreateDto{
|
||||
Code: input.Infra_Code,
|
||||
Infra_Code: input.Infra_Code,
|
||||
Unit_Code: input.Unit_Code,
|
||||
Specialist_Code: input.Specialist_Code,
|
||||
Subspecialist_Code: input.Subspecialist_Code,
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func setDataCreate(input *ir.CreateDto, data *ir.InternalReference) {
|
||||
data.Encounter_Id = input.Encounter_Id
|
||||
data.Unit_Code = input.Unit_Code
|
||||
data.Specialist_Code = input.Specialist_Code
|
||||
|
||||
data.Doctor_Code = input.Doctor_Code
|
||||
data.SrcDoctor_Code = input.SrcDoctor_Code
|
||||
@@ -28,18 +28,18 @@ func setDataUpdate(input *ir.UpdateDto, data *ir.InternalReference) {
|
||||
data.Status_Code = &input.Status_Code
|
||||
}
|
||||
|
||||
func setBulkData(input *e.SwitchUnitDto) []ir.InternalReference {
|
||||
func setBulkData(input *e.SwitchSpecialistDto) []ir.InternalReference {
|
||||
var data []ir.InternalReference
|
||||
|
||||
for _, v := range *input.InternalReferences {
|
||||
statusCode := erc.DACNew
|
||||
data = append(data, ir.InternalReference{
|
||||
Encounter_Id: &input.Id,
|
||||
Unit_Code: v.Unit_Code,
|
||||
Doctor_Code: v.Doctor_Code,
|
||||
Status_Code: &statusCode,
|
||||
SrcDoctor_Code: input.Src_Doctor_Code,
|
||||
SrcNurse_Code: input.Src_Nurse_Code,
|
||||
Encounter_Id: &input.Id,
|
||||
Specialist_Code: v.Specialist_Code,
|
||||
Doctor_Code: v.Doctor_Code,
|
||||
Status_Code: &statusCode,
|
||||
SrcDoctor_Code: input.Src_Doctor_Code,
|
||||
SrcNurse_Code: input.Src_Nurse_Code,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ func DeleteData(data *eir.InternalReference, event *pl.Event, dbx ...*gorm.DB) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateBulkData(input *e.SwitchUnitDto, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
func CreateBulkData(input *e.SwitchSpecialistDto, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
|
||||
data := setBulkData(input)
|
||||
|
||||
@@ -20,6 +20,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Nurse) {
|
||||
data.Code = inputSrc.Code
|
||||
data.Employee_Id = inputSrc.Employee_Id
|
||||
data.IHS_Number = inputSrc.IHS_Number
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
data.Infra_Code = inputSrc.Infra_Code
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
|
||||
const source = "patient"
|
||||
|
||||
func Create(input e.CreateDto) (*d.Data, error) {
|
||||
func Create(input e.CreateDto, dbx ...*gorm.DB) (*d.Data, error) {
|
||||
data := e.Patient{}
|
||||
|
||||
event := pl.Event{
|
||||
@@ -35,6 +35,13 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
Source: source,
|
||||
}
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
mwRunner := newMiddlewareRunner(&event, input.Sync)
|
||||
@@ -51,7 +58,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
|
||||
input.RegisteredBy_User_Name = &input.AuthInfo.User_Name
|
||||
|
||||
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
err := tx.Transaction(func(tx1 *gorm.DB) error {
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunCreateMiddleware(createPreMw, &input, &data); err != nil {
|
||||
@@ -65,14 +72,14 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
}
|
||||
input.Number = nomr
|
||||
|
||||
if person_id, err := upe.CreateOrUpdatePerson(input.Person, &event, tx); err != nil {
|
||||
if person_id, err := upe.CreateOrUpdatePerson(input.Person, &event, tx1); err != nil {
|
||||
return err
|
||||
} else {
|
||||
input.Person_Id = person_id
|
||||
}
|
||||
|
||||
if input.Person.VclaimMember_CardNumber != nil && input.Person.ResidentIdentityNumber != nil {
|
||||
if err := uvm.CreateOrUpdateData(evm.CreateDto{CardNumber: input.Person.VclaimMember_CardNumber, Person_Id: input.Person_Id}, &event, tx); err != nil {
|
||||
if err := uvm.CreateOrUpdateData(evm.CreateDto{CardNumber: input.Person.VclaimMember_CardNumber, Person_Id: input.Person_Id}, &event, tx1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -80,38 +87,38 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
for idx := range input.PersonAddresses {
|
||||
input.PersonAddresses[idx].Person_Id = *input.Person_Id
|
||||
}
|
||||
if err := upa.CreateOrUpdateBatch(input.PersonAddresses, &event, tx); err != nil {
|
||||
if err := upa.CreateOrUpdateBatch(input.PersonAddresses, &event, tx1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for idx := range input.PersonContacts {
|
||||
input.PersonContacts[idx].Person_Id = *input.Person_Id
|
||||
}
|
||||
if err := upc.CreateOrUpdateBatch(input.PersonContacts, &event, tx); err != nil {
|
||||
if err := upc.CreateOrUpdateBatch(input.PersonContacts, &event, tx1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for idx := range input.PersonRelatives {
|
||||
input.PersonRelatives[idx].Person_Id = *input.Person_Id
|
||||
}
|
||||
if err := upr.CreateOrUpdateBatch(input.PersonRelatives, &event, tx); err != nil {
|
||||
if err := upr.CreateOrUpdateBatch(input.PersonRelatives, &event, tx1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for idx := range input.PersonInsurances {
|
||||
input.PersonInsurances[idx].Person_Id = *input.Person_Id
|
||||
}
|
||||
if err := upi.CreateOrUpdateBatch(input.PersonInsurances, &event, tx); err != nil {
|
||||
if err := upi.CreateOrUpdateBatch(input.PersonInsurances, &event, tx1); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
if resData, err := CreateData(input, &event, tx1); err != nil {
|
||||
return err
|
||||
} else {
|
||||
data = *resData
|
||||
}
|
||||
|
||||
dataPatient, err := ReadDetailData(e.ReadDetailDto{Id: uint16(data.Id)}, &event, tx)
|
||||
dataPatient, err := ReadDetailData(e.ReadDetailDto{Id: uint16(data.Id)}, &event, tx1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.PracticeSchedule) {
|
||||
}
|
||||
|
||||
data.Doctor_Code = inputSrc.Doctor_Code
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
data.Day_Code = inputSrc.Day_Code
|
||||
data.StartTime = inputSrc.StartTime
|
||||
data.EndTime = inputSrc.EndTime
|
||||
|
||||
@@ -19,7 +19,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ProcedureRoom) {
|
||||
|
||||
data.Code = *inputSrc.Infra_Code
|
||||
data.Infra_Code = inputSrc.Infra_Code
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Specialist_Code = inputSrc.Specialist_Code
|
||||
data.Subspecialist_Code = inputSrc.Subspecialist_Code
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Specialist) {
|
||||
|
||||
data.Code = inputSrc.Code
|
||||
data.Name = inputSrc.Name
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Installation_Code = inputSrc.Installation_Code
|
||||
}
|
||||
|
||||
func setBulkData(input []e.CreateDto) (data []e.Specialist) {
|
||||
|
||||
@@ -1,302 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
eu "simrs-vx/internal/domain/main-entities/unit"
|
||||
e "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
"strconv"
|
||||
|
||||
ue "simrs-vx/internal/use-case/main-use-case/employee"
|
||||
uu "simrs-vx/internal/use-case/main-use-case/unit"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const source = "unit-position"
|
||||
|
||||
func Create(input e.CreateDto) (*d.Data, error) {
|
||||
data := e.UnitPosition{}
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Create",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
|
||||
err := dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunCreateMiddleware(createPreMw, &input, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateForeignKey(input); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
data = *resData
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPost)
|
||||
// Run post-middleware
|
||||
if err := mwRunner.RunCreateMiddleware(createPostMw, &input, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.II{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "created",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ReadList(input e.ReadListDto) (*d.Data, error) {
|
||||
var data *e.UnitPosition
|
||||
var dataList []e.UnitPosition
|
||||
var metaList *e.MetaDto
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "ReadList",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "readList")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunReadListMiddleware(readListPreMw, &input, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPost)
|
||||
// Run post-middleware
|
||||
if err := mwRunner.RunReadListMiddleware(readListPostMw, &input, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "list-data",
|
||||
"status": "fetched",
|
||||
"page_number": strconv.Itoa(metaList.PageNumber),
|
||||
"page_size": strconv.Itoa(metaList.PageSize),
|
||||
"record_totalCount": strconv.Itoa(metaList.Count),
|
||||
"record_currentCount": strconv.Itoa(len(dataList)),
|
||||
},
|
||||
Data: e.ToResponseList(dataList),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
||||
var data *e.UnitPosition
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "ReadDetail",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "readDetail")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunReadDetailMiddleware(readDetailPreMw, &input, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if data, err = ReadDetailData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPost)
|
||||
// Run post-middleware
|
||||
if err := mwRunner.RunReadDetailMiddleware(readDetailPostMw, &input, 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": "fetched",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Code: &input.Code}
|
||||
var data *e.UnitPosition
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Update",
|
||||
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
|
||||
}
|
||||
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunUpdateMiddleware(readDetailPreMw, &rdDto, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateForeignKey(input.CreateDto); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := UpdateData(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
|
||||
|
||||
}
|
||||
|
||||
func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Code: input.Code}
|
||||
var data *e.UnitPosition
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Delete",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "delete")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
mwRunner := newMiddlewareRunner(&event, tx)
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunDeleteMiddleware(readDetailPreMw, &rdDto, data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := DeleteData(data, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPost)
|
||||
// Run post-middleware
|
||||
if err := mwRunner.RunDeleteMiddleware(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": "deleted",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func validateForeignKey(input e.CreateDto) error {
|
||||
// validate installation_id
|
||||
if _, err := uu.ReadDetail(eu.ReadDetailDto{Code: input.Unit_Code}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// validate employee_Id
|
||||
if _, err := ue.ReadDetail(ee.ReadDetailDto{Id: uint16(*input.Employee_Id)}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Any functions that are used internally by the use-case
|
||||
*/
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
)
|
||||
|
||||
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.UnitPosition) {
|
||||
var inputSrc *e.CreateDto
|
||||
if inputT, ok := any(input).(*e.CreateDto); ok {
|
||||
inputSrc = inputT
|
||||
} else {
|
||||
inputTemp := any(input).(*e.UpdateDto)
|
||||
inputSrc = &inputTemp.CreateDto
|
||||
}
|
||||
|
||||
data.Unit_Code = inputSrc.Unit_Code
|
||||
data.Code = inputSrc.Code
|
||||
data.Name = inputSrc.Name
|
||||
data.HeadStatus = inputSrc.HeadStatus
|
||||
data.Employee_Id = inputSrc.Employee_Id
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
"errors"
|
||||
e "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
|
||||
plh "simrs-vx/pkg/lib-helper"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
gh "github.com/karincake/getuk"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.UnitPosition, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
|
||||
data := e.UnitPosition{}
|
||||
setData(&input, &data)
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Create(&data).Error; err != nil {
|
||||
return nil, plh.HandleCreateError(input, event, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.UnitPosition, *e.MetaDto, error) {
|
||||
pl.SetLogInfo(event, input, "started", "DBReadList")
|
||||
data := []e.UnitPosition{}
|
||||
pagination := gh.Pagination{}
|
||||
count := int64(0)
|
||||
meta := e.MetaDto{}
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
tx = tx.
|
||||
Model(&e.UnitPosition{}).
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
Scopes(gh.Filter(input.FilterDto)).
|
||||
Count(&count).
|
||||
Scopes(gh.Paginate(input, &pagination)).
|
||||
Scopes(gh.Sort(input.Sort))
|
||||
|
||||
if err := tx.Find(&data).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, &meta, nil
|
||||
}
|
||||
return nil, nil, plh.HandleListError(input, event, err)
|
||||
}
|
||||
|
||||
meta.Count = int(count)
|
||||
meta.PageNumber = pagination.PageNumber
|
||||
meta.PageSize = pagination.PageSize
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return data, &meta, nil
|
||||
}
|
||||
|
||||
func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.UnitPosition, error) {
|
||||
pl.SetLogInfo(event, input, "started", "DBReadDetail")
|
||||
data := e.UnitPosition{}
|
||||
|
||||
var tx, getData *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
switch {
|
||||
case input.Id != nil:
|
||||
getData = tx.First(&data, input.Id)
|
||||
case input.Code != nil && *input.Code != "":
|
||||
getData = tx.Where("\"Code\" = ?", *input.Code).First(&data)
|
||||
default:
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-read-detail-fail",
|
||||
Detail: "either Id or Code must be provided",
|
||||
}
|
||||
|
||||
return nil, pl.SetLogError(event, nil)
|
||||
}
|
||||
|
||||
if err := getData.Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func UpdateData(input e.UpdateDto, data *e.UnitPosition, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBUpdate")
|
||||
setData(&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
|
||||
}
|
||||
|
||||
func DeleteData(data *e.UnitPosition, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBDelete")
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Delete(&data).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-delete-fail",
|
||||
Detail: "Database delete failed",
|
||||
Raw: err,
|
||||
}
|
||||
return pl.SetLogError(event, data)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return nil
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type middlewareRunner struct {
|
||||
Event *pl.Event
|
||||
Tx *gorm.DB
|
||||
MwType pu.MWType
|
||||
}
|
||||
|
||||
// NewMiddlewareExecutor creates a new middleware executor
|
||||
func newMiddlewareRunner(event *pl.Event, tx *gorm.DB) *middlewareRunner {
|
||||
return &middlewareRunner{
|
||||
Event: event,
|
||||
Tx: tx,
|
||||
}
|
||||
}
|
||||
|
||||
// ExecuteCreateMiddleware executes create middleware
|
||||
func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.UnitPosition) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.UnitPosition) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.UnitPosition) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.UnitPosition) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.UnitPosition) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) setMwType(mwType pu.MWType) {
|
||||
me.MwType = mwType
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package unit_position
|
||||
|
||||
// example of middleware
|
||||
// func init() {
|
||||
// createPreMw = append(createPreMw,
|
||||
// CreateMw{Name: "modif-input", Func: pm.ModifInput},
|
||||
// CreateMw{Name: "check-data", Func: pm.CheckData},
|
||||
// )
|
||||
// }
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains type, constants, and/or variables.
|
||||
|
||||
In this sample it also provides type and variable regarding the needs of the
|
||||
middleware to separate from main use-case which has the basic CRUD
|
||||
functionality. The purpose of this is to make the code more maintainable.
|
||||
*/
|
||||
package unit_position
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit-position"
|
||||
)
|
||||
|
||||
type createMw struct {
|
||||
Name string
|
||||
Func func(input *e.CreateDto, data *e.UnitPosition, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type readListMw struct {
|
||||
Name string
|
||||
Func func(input *e.ReadListDto, data *e.UnitPosition, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type readDetailMw struct {
|
||||
Name string
|
||||
Func func(input *e.ReadDetailDto, data *e.UnitPosition, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type UpdateMw = readDetailMw
|
||||
type DeleteMw = readDetailMw
|
||||
|
||||
var createPreMw []createMw // preprocess middleware
|
||||
var createPostMw []createMw // postprocess middleware
|
||||
var readListPreMw []readListMw // ..
|
||||
var readListPostMw []readListMw // ..
|
||||
var readDetailPreMw []readDetailMw
|
||||
var readDetailPostMw []readDetailMw
|
||||
var updatePreMw []readDetailMw
|
||||
var updatePostMw []readDetailMw
|
||||
var deletePreMw []readDetailMw
|
||||
var deletePostMw []readDetailMw
|
||||
@@ -1,280 +0,0 @@
|
||||
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"
|
||||
"strconv"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
d "github.com/karincake/dodol"
|
||||
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const source = "unit"
|
||||
|
||||
func Create(input e.CreateDto) (*d.Data, error) {
|
||||
data := e.Unit{}
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Create",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// 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 {
|
||||
if resData, err := CreateData(input, &event, tx); err != nil {
|
||||
return err
|
||||
} else {
|
||||
data = *resData
|
||||
id := uint(data.Id)
|
||||
input.Id = &id
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunCreateMiddleware(createPreMw, &input); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err = runLogMiddleware(err, input, mwRunner); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.II{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "created",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ReadList(input e.ReadListDto) (*d.Data, error) {
|
||||
var dataList []e.Unit
|
||||
var metaList *e.MetaDto
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "ReadList",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "readList")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
if dataList, metaList, err = ReadListData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "list-data",
|
||||
"status": "fetched",
|
||||
"page_number": strconv.Itoa(metaList.PageNumber),
|
||||
"page_size": strconv.Itoa(metaList.PageSize),
|
||||
"record_totalCount": strconv.Itoa(metaList.Count),
|
||||
"record_currentCount": strconv.Itoa(len(dataList)),
|
||||
},
|
||||
Data: e.ToResponseList(dataList),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
|
||||
var data *e.Unit
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "ReadDetail",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "readDetail")
|
||||
|
||||
err = dg.I.Transaction(func(tx *gorm.DB) error {
|
||||
if data, err = ReadDetailData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "fetched",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Code: &input.Code}
|
||||
var data *e.Unit
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Update",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "update")
|
||||
mwRunner := newMiddlewareRunner(&event)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
input.Id = &data.Id
|
||||
if err := UpdateData(input, data, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunUpdateMiddleware(updatePreMw, &input); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err = runLogMiddleware(err, input, mwRunner); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "updated",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
rdDto := e.ReadDetailDto{Code: input.Code}
|
||||
var data *e.Unit
|
||||
var err error
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Delete",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "delete")
|
||||
mwRunner := newMiddlewareRunner(&event)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
input.Id = &data.Id
|
||||
if err := DeleteData(data, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mwRunner.setMwType(pu.MWTPre)
|
||||
// Run pre-middleware
|
||||
if err := mwRunner.RunDeleteMiddleware(deletePreMw, &input); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err = runLogMiddleware(err, input, mwRunner); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "deleted",
|
||||
},
|
||||
Data: data.ToResponse(),
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func runLogMiddleware(err error, input any, mwRunner *middlewareRunner) error {
|
||||
var errMsg string
|
||||
inputLog := esync.SimxLogDto{
|
||||
Payload: input,
|
||||
Method: erc.CCCreate,
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
// Run log-middleware
|
||||
errMsg = err.Error()
|
||||
inputLog.ErrMessage = &errMsg
|
||||
inputLog.IsSuccess = false
|
||||
|
||||
// create log failed
|
||||
if errMiddleware := mwRunner.RunCreateLogMiddleware(createSimxLogMw, &inputLog); errMiddleware != nil {
|
||||
return errMiddleware
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// create log success
|
||||
inputLog.IsSuccess = true
|
||||
if err = mwRunner.RunCreateLogMiddleware(createSimxLogMw, &inputLog); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Any functions that are used internally by the use-case
|
||||
*/
|
||||
package unit
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Unit) {
|
||||
var inputSrc *e.CreateDto
|
||||
if inputT, ok := any(input).(*e.CreateDto); ok {
|
||||
inputSrc = inputT
|
||||
} else {
|
||||
inputTemp := any(input).(*e.UpdateDto)
|
||||
inputSrc = &inputTemp.CreateDto
|
||||
}
|
||||
|
||||
data.Installation_Code = inputSrc.Installation_Code
|
||||
data.Code = inputSrc.Code
|
||||
data.Name = inputSrc.Name
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
|
||||
plh "simrs-vx/pkg/lib-helper"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
gh "github.com/karincake/getuk"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Unit, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
|
||||
data := e.Unit{}
|
||||
setData(&input, &data)
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Create(&data).Error; err != nil {
|
||||
return nil, plh.HandleCreateError(input, event, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Unit, *e.MetaDto, error) {
|
||||
pl.SetLogInfo(event, input, "started", "DBReadList")
|
||||
data := []e.Unit{}
|
||||
pagination := gh.Pagination{}
|
||||
count := int64(0)
|
||||
meta := e.MetaDto{}
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
tx = tx.
|
||||
Model(&e.Unit{}).
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
Scopes(gh.Filter(input.FilterDto)).
|
||||
Count(&count).
|
||||
Scopes(gh.Paginate(input, &pagination)).
|
||||
Scopes(gh.Sort(input.Sort))
|
||||
|
||||
if err := tx.Find(&data).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return nil, &meta, nil
|
||||
}
|
||||
return nil, nil, plh.HandleListError(input, event, err)
|
||||
}
|
||||
|
||||
meta.Count = int(count)
|
||||
meta.PageNumber = pagination.PageNumber
|
||||
meta.PageSize = pagination.PageSize
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return data, &meta, nil
|
||||
}
|
||||
|
||||
func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e.Unit, error) {
|
||||
pl.SetLogInfo(event, input, "started", "DBReadDetail")
|
||||
data := e.Unit{}
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if input.Code != nil {
|
||||
tx = tx.Where("\"Code\" = ?", *input.Code)
|
||||
}
|
||||
if input.Id != nil {
|
||||
tx = tx.Where("\"Id\" = ?", input.Id)
|
||||
}
|
||||
|
||||
if err := tx.
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func UpdateData(input e.UpdateDto, data *e.Unit, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBUpdate")
|
||||
setData(&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
|
||||
}
|
||||
|
||||
func DeleteData(data *e.Unit, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBDelete")
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Delete(&data).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-delete-fail",
|
||||
Detail: "Database delete failed",
|
||||
Raw: err,
|
||||
}
|
||||
return pl.SetLogError(event, data)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return nil
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
sync "simrs-vx/internal/infra/sync-consumer-cfg"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
esync "simrs-vx/internal/domain/sync-entities/log"
|
||||
)
|
||||
|
||||
type middlewareRunner struct {
|
||||
Event *pl.Event
|
||||
Tx *gorm.DB
|
||||
MwType pu.MWType
|
||||
SyncOn bool
|
||||
}
|
||||
|
||||
// NewMiddlewareExecutor creates a new middleware executor
|
||||
func newMiddlewareRunner(event *pl.Event) *middlewareRunner {
|
||||
return &middlewareRunner{
|
||||
Event: event,
|
||||
SyncOn: sync.O.Enable,
|
||||
}
|
||||
}
|
||||
|
||||
// ExecuteCreateMiddleware executes create middleware
|
||||
func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, nil)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExecuteCreateMiddleware executes create middleware
|
||||
func (me *middlewareRunner) RunCreateLogMiddleware(middlewares []createLogMw, input *esync.SimxLogDto) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, nil)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.Unit) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Unit) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunUpdateMiddleware(middlewares []updateMw, input *e.UpdateDto) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, nil)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunDeleteMiddleware(middlewares []deleteMw, input *e.DeleteDto) error {
|
||||
if !me.SyncOn {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, nil)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) setMwType(mwType pu.MWType) {
|
||||
me.MwType = mwType
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
plugin "simrs-vx/internal/use-case/simgos-sync-plugin/new/unit"
|
||||
)
|
||||
|
||||
// example of middleware
|
||||
func init() {
|
||||
createPreMw = append(createPreMw,
|
||||
createMw{Name: "sync-create-unit", Func: plugin.Create})
|
||||
|
||||
createSimxLogMw = append(createSimxLogMw,
|
||||
createLogMw{Name: "create-sync-log", Func: plugin.CreateLog})
|
||||
|
||||
updatePreMw = append(updatePreMw,
|
||||
updateMw{Name: "sync-update-unit", Func: plugin.Update})
|
||||
|
||||
deletePreMw = append(deletePreMw,
|
||||
deleteMw{Name: "sync-delete-unit", Func: plugin.Delete})
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains type, constants, and/or variables.
|
||||
|
||||
In this sample it also provides type and variable regarding the needs of the
|
||||
middleware to separate from main use-case which has the basic CRUD
|
||||
functionality. The purpose of this is to make the code more maintainable.
|
||||
*/
|
||||
package unit
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
)
|
||||
|
||||
type createMw struct {
|
||||
Name string
|
||||
Func func(input *e.CreateDto) error
|
||||
}
|
||||
|
||||
type createLogMw struct {
|
||||
Name string
|
||||
Func func(input *elog.SimxLogDto) error
|
||||
}
|
||||
|
||||
type updateMw struct {
|
||||
Name string
|
||||
Func func(input *e.UpdateDto) error
|
||||
}
|
||||
|
||||
type deleteMw struct {
|
||||
Name string
|
||||
Func func(input *e.DeleteDto) error
|
||||
}
|
||||
|
||||
type readListMw struct {
|
||||
Name string
|
||||
Func func(input *e.ReadListDto, data *e.Unit, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type readDetailMw struct {
|
||||
Name string
|
||||
Func func(input *e.ReadDetailDto, data *e.Unit, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type UpdateMw = updateMw
|
||||
type DeleteMw = deleteMw
|
||||
|
||||
var createPreMw []createMw // preprocess middleware
|
||||
var createPostMw []createMw // postprocess middleware
|
||||
var createSimxLogMw []createLogMw
|
||||
var readListPreMw []readListMw // ..
|
||||
var readListPostMw []readListMw // ..
|
||||
var readDetailPreMw []readDetailMw
|
||||
var readDetailPostMw []readDetailMw
|
||||
var updatePreMw []updateMw
|
||||
var updatePostMw []readDetailMw
|
||||
var deletePreMw []deleteMw
|
||||
var deletePostMw []readDetailMw
|
||||
@@ -114,7 +114,6 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
SIP_Number: input.SIP_Number,
|
||||
Unit_Code: input.Unit_Code,
|
||||
Specialist_Code: input.Specialist_Code,
|
||||
Subspecialist_Code: input.Subspecialist_Code,
|
||||
}
|
||||
@@ -123,11 +122,11 @@ func Create(input e.CreateDto) (*d.Data, error) {
|
||||
}
|
||||
case ero.EPCNur:
|
||||
createNurse := en.CreateDto{
|
||||
Code: input.Code,
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
Unit_Code: input.Unit_Code,
|
||||
Infra_Code: input.Infra_Code,
|
||||
Code: input.Code,
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
Specialist_Code: input.Specialist_Code,
|
||||
Infra_Code: input.Infra_Code,
|
||||
}
|
||||
if _, err := un.CreateData(createNurse, &event, tx); err != nil {
|
||||
return err
|
||||
@@ -436,11 +435,11 @@ func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
createNur := en.CreateDto{
|
||||
Code: input.Code,
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
Unit_Code: input.Unit_Code,
|
||||
Infra_Code: input.Infra_Code,
|
||||
Code: input.Code,
|
||||
Employee_Id: &employeeData.Id,
|
||||
IHS_Number: input.IHS_Number,
|
||||
Specialist_Code: input.Specialist_Code,
|
||||
Infra_Code: input.Infra_Code,
|
||||
}
|
||||
if readNurData != nil {
|
||||
if err := un.UpdateData(en.UpdateDto{CreateDto: createNur}, readNurData, &event, tx); err != nil {
|
||||
|
||||
@@ -49,19 +49,19 @@ func UpdateStatus(input *e.Encounter) error {
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func RequestSwitchUnit(input *e.Encounter) error {
|
||||
func RequestSwitchSpecialist(input *e.Encounter) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v/req-switch-unit", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func ApproveSwitchUnit(input *e.ApproveCancelUnitDto) error {
|
||||
func ApproveSwitchSpecialist(input *e.ApproveCancelSpecialistDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v/approve-switch-unit", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func CancelSwitchUnit(input *e.ApproveCancelUnitDto) error {
|
||||
func CancelSwitchSpecialist(input *e.ApproveCancelSpecialistDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v/cancel-switch-unit", prefixEndpoint, input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
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"
|
||||
)
|
||||
|
||||
func Create(input *e.CreateDto) error {
|
||||
return helper.DoJsonRequest(input, "POST", getPrefixEndpoint())
|
||||
}
|
||||
|
||||
func CreateLog(input *elog.SimxLogDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := prefixEndpoint + "/log"
|
||||
return helper.DoJsonRequest(input, "POST", endpoint)
|
||||
}
|
||||
|
||||
func Update(input *e.UpdateDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
return helper.DoJsonRequest(input, "PATCH", endpoint)
|
||||
}
|
||||
|
||||
func Delete(input *e.DeleteDto) error {
|
||||
prefixEndpoint := getPrefixEndpoint()
|
||||
endpoint := fmt.Sprintf("%s/%v", prefixEndpoint, *input.Id)
|
||||
return helper.DoJsonRequest(input, "DELETE", endpoint)
|
||||
}
|
||||
|
||||
func getPrefixEndpoint() string {
|
||||
return fmt.Sprintf("%s%s/v1/unit", sync.O.TargetHost, sync.O.Prefix)
|
||||
}
|
||||
@@ -368,18 +368,18 @@ func UpdateStatus(input e.Encounter) (*d.Data, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func RequestSwitchUnit(input e.Encounter) (*d.Data, error) {
|
||||
func RequestSwitchSpecialist(input e.Encounter) (*d.Data, error) {
|
||||
var (
|
||||
syncLinkInternal *[]syncir.InternalReferenceLink
|
||||
)
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "RequestSwitchUnit",
|
||||
Feature: "RequestSwitchSpecialist",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "request-switch-unit")
|
||||
pl.SetLogInfo(&event, input, "started", "request-switch-specialist")
|
||||
|
||||
// STEP 1: Get Link
|
||||
syncLink, err := ReadDetailLinkData(input.Id, &event)
|
||||
@@ -431,14 +431,14 @@ func RequestSwitchUnit(input e.Encounter) (*d.Data, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
func ApproveSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) {
|
||||
event := pl.Event{
|
||||
Feature: "ApproveSwitchUnit",
|
||||
Feature: "ApproveSwitchSpecialist",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "approve-switch-unit")
|
||||
pl.SetLogInfo(&event, input, "started", "approve-switch-specialist")
|
||||
|
||||
// STEP 1: Get InternalReference Link
|
||||
syncLink, err := utph.ReadDetailLinkData(input.InternalReferences_Id, &event)
|
||||
@@ -478,14 +478,14 @@ func ApproveSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func CancelSwitchUnit(input e.ApproveCancelUnitDto) (*d.Data, error) {
|
||||
func CancelSwitchSpecialist(input e.ApproveCancelSpecialistDto) (*d.Data, error) {
|
||||
event := pl.Event{
|
||||
Feature: "CancelSwitchUnit",
|
||||
Feature: "CancelSwitchSpecialist",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "cancel-switch-unit")
|
||||
pl.SetLogInfo(&event, input, "started", "cancel-switch-specialist")
|
||||
|
||||
// STEP 1: Get InternalReference Link
|
||||
syncLink, err := utph.ReadDetailLinkData(input.InternalReferences_Id, &event)
|
||||
|
||||
@@ -77,8 +77,8 @@ func setDataTPendaftaran(input *e.Encounter, data *etp.TPendaftaran) {
|
||||
data.Tglreg = input.RegisteredAt
|
||||
|
||||
// set kdpoly
|
||||
if p := input.Unit_Code; p != nil {
|
||||
kdpoly, _ := strconv.Atoi(*input.Unit_Code)
|
||||
if p := input.Specialist_Code; p != nil {
|
||||
kdpoly, _ := strconv.Atoi(*input.Specialist_Code)
|
||||
data.Kdpoly = uint(kdpoly)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ func setCreateDataSimgos(input e.Encounter, data *etp.TPendaftaran) (hist []etph
|
||||
for i, ref := range *enc {
|
||||
hist = append(hist, etph.TPemeriksaanHist{
|
||||
Idxdaftar: &data.Idxdaftar,
|
||||
Kdpoly: stringtouint(*ref.Unit_Code),
|
||||
Kdpoly: stringtouint(*ref.Specialist_Code),
|
||||
DokterPengonsul: stringtouint(*ref.SrcDoctor_Code),
|
||||
DokterPenerima: stringtouint(*ref.Doctor_Code),
|
||||
})
|
||||
@@ -46,7 +46,7 @@ func setCreateDataSimgos(input e.Encounter, data *etp.TPendaftaran) (hist []etph
|
||||
return
|
||||
}
|
||||
|
||||
func setUpdateApproveDataSimgos(input e.ApproveCancelUnitDto, data *etph.TPemeriksaanHist) {
|
||||
func setUpdateApproveDataSimgos(input e.ApproveCancelSpecialistDto, data *etph.TPemeriksaanHist) {
|
||||
data.DokterPenerima = stringtouint(*input.Dst_Doctor_Code)
|
||||
data.StartKonsul = &now
|
||||
data.UserPenerima = &input.User_Name
|
||||
@@ -54,7 +54,7 @@ func setUpdateApproveDataSimgos(input e.ApproveCancelUnitDto, data *etph.TPemeri
|
||||
return
|
||||
}
|
||||
|
||||
func setUpdateCancelDataSimgos(input e.ApproveCancelUnitDto, data *etph.TPemeriksaanHist) {
|
||||
func setUpdateCancelDataSimgos(input e.ApproveCancelSpecialistDto, data *etph.TPemeriksaanHist) {
|
||||
data.UserBatal = &input.User_Name
|
||||
data.TglBatal = &now
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ func ReadDetailSimgosData(simgosId uint, event *pl.Event) (*etph.TPemeriksaanHis
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func UpdateSimgosData(input e.ApproveCancelUnitDto, data *etph.TPemeriksaanHist, method string, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
func UpdateSimgosData(input e.ApproveCancelSpecialistDto, data *etph.TPemeriksaanHist, method string, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, input, "started", "DBUpdate")
|
||||
|
||||
switch method {
|
||||
|
||||
@@ -1,198 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
pl "simrs-vx/pkg/logger"
|
||||
|
||||
d "github.com/karincake/dodol"
|
||||
"gorm.io/gorm"
|
||||
|
||||
db "simrs-vx/pkg/dualtrx-helper"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
esimgos "simrs-vx/internal/domain/simgos-entities/m-poly"
|
||||
elog "simrs-vx/internal/domain/sync-entities/log"
|
||||
esync "simrs-vx/internal/domain/sync-entities/unit"
|
||||
)
|
||||
|
||||
const source = "unit"
|
||||
|
||||
func Create(input e.CreateDto) (*d.Data, error) {
|
||||
var (
|
||||
sgData *esimgos.MPoly
|
||||
syncLink *esync.UnitLink
|
||||
err error
|
||||
)
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Create",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
|
||||
err = db.WithDualTx(func(tx *db.Dualtx) error {
|
||||
// STEP 1: Insert to simgos
|
||||
sgData, err = CreateSimgosData(input, &event, tx.Simgos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// STEP 2: Insert to Link
|
||||
syncLink, err = CreateLinkData(*input.Id, sgData.Kode, &event, tx.Sync)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if syncLink != nil {
|
||||
go func() { _ = DeleteLinkData(syncLink, &event) }()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.II{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "created",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func CreateSimxLog(input elog.SimxLogDto) (*d.Data, error) {
|
||||
event := pl.Event{
|
||||
Feature: "Create",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "create")
|
||||
|
||||
tx := db.NewTx()
|
||||
err := tx.Sync.Transaction(func(tx *gorm.DB) error {
|
||||
// Insert to Log
|
||||
if err := CreateLogData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.II{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "created",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Update(input e.UpdateDto) (*d.Data, error) {
|
||||
event := pl.Event{
|
||||
Feature: "Update",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "update")
|
||||
|
||||
// STEP 1: Get Installation Link
|
||||
syncLink, err := ReadDetailLinkData(*input.Id, &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tx := db.NewTx()
|
||||
err = tx.Simgos.Transaction(func(tx *gorm.DB) error {
|
||||
// Step 2: Update Simgos
|
||||
err = UpdateSimgosData(input, syncLink, &event, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "updated",
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func Delete(input e.DeleteDto) (*d.Data, error) {
|
||||
var isLinkDeleted bool
|
||||
|
||||
event := pl.Event{
|
||||
Feature: "Delete",
|
||||
Source: source,
|
||||
}
|
||||
|
||||
// Start log
|
||||
pl.SetLogInfo(&event, input, "started", "delete")
|
||||
|
||||
// STEP 1: Get Installation Link
|
||||
syncLink, err := ReadDetailLinkData(*input.Id, &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// STEP 2: Get Simgos
|
||||
sgData, err := ReadDetailSimgosData(uint16(syncLink.Simgos_Id), &event)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = db.WithDualTx(func(tx *db.Dualtx) error {
|
||||
// STEP 3: Delete M_Poly Simgos
|
||||
err = HardDeleteSimgosData(sgData, &event, tx.Simgos)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// STEP 4: Delete Installation Link
|
||||
err = DeleteLinkData(syncLink, &event, tx.Sync)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
isLinkDeleted = true
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
if isLinkDeleted {
|
||||
go func() {
|
||||
_, _ = CreateLinkData(uint(*input.Id), sgData.Kode, &event)
|
||||
}()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pl.SetLogInfo(&event, nil, "complete")
|
||||
|
||||
return &d.Data{
|
||||
Meta: d.IS{
|
||||
"source": source,
|
||||
"structure": "single-data",
|
||||
"status": "deleted",
|
||||
},
|
||||
}, nil
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
Any functions that are used internally by the use-case
|
||||
*/
|
||||
package unit
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
"strconv"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
|
||||
esimgos "simrs-vx/internal/domain/simgos-entities/m-poly"
|
||||
esyncLog "simrs-vx/internal/domain/sync-entities/log"
|
||||
esync "simrs-vx/internal/domain/sync-entities/unit"
|
||||
)
|
||||
|
||||
func setDataSimgos[T *e.CreateDto | *e.UpdateDto](input T) (data esimgos.MPoly) {
|
||||
var inputSrc *e.CreateDto
|
||||
if inputT, ok := any(input).(*e.CreateDto); ok {
|
||||
inputSrc = inputT
|
||||
} else {
|
||||
inputTemp := any(input).(*e.UpdateDto)
|
||||
inputSrc = &inputTemp.CreateDto
|
||||
}
|
||||
|
||||
data.Nama = inputSrc.Name
|
||||
data.Jenispoly = 0
|
||||
|
||||
kodePoly, _ := strconv.Atoi(inputSrc.Code)
|
||||
data.Kode = uint(kodePoly)
|
||||
return
|
||||
}
|
||||
|
||||
func setDataSimxLog(input *esyncLog.SimxLogDto) (data esync.UnitSimxLog) {
|
||||
// encode to JSON
|
||||
jsonData, _ := json.MarshalIndent(input.Payload, "", " ")
|
||||
jsonString := string(jsonData)
|
||||
|
||||
var status erc.ProcessStatusCode
|
||||
if input.IsSuccess {
|
||||
status = erc.PSCSuccess
|
||||
} else {
|
||||
status = erc.PSCFailed
|
||||
if input.ErrMessage != nil {
|
||||
data.ErrMessage = input.ErrMessage
|
||||
}
|
||||
}
|
||||
|
||||
data.Value = &jsonString
|
||||
data.Date = &now
|
||||
data.Status = status
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func setDataSimxLink(simxId, simgosId uint) (data esync.UnitLink) {
|
||||
data.Simx_Id = simxId
|
||||
data.Simgos_Id = simgosId
|
||||
return
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
plh "simrs-vx/pkg/lib-helper"
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
"time"
|
||||
|
||||
dg "github.com/karincake/apem/db-gorm-pg"
|
||||
"gorm.io/gorm"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
esimgos "simrs-vx/internal/domain/simgos-entities/m-poly"
|
||||
esynclog "simrs-vx/internal/domain/sync-entities/log"
|
||||
esync "simrs-vx/internal/domain/sync-entities/unit"
|
||||
)
|
||||
|
||||
var now = time.Now()
|
||||
|
||||
func CreateSimgosData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*esimgos.MPoly, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
|
||||
data := setDataSimgos(&input)
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.IS["simrs"]
|
||||
}
|
||||
|
||||
if err := tx.Create(&data).Error; err != nil {
|
||||
return nil, plh.HandleCreateError(input, event, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func ReadDetailSimgosData(simgosId uint16, event *pl.Event) (*esimgos.MPoly, error) {
|
||||
pl.SetLogInfo(event, simgosId, "started", "DBReadDetail")
|
||||
data := esimgos.MPoly{}
|
||||
|
||||
var tx = dg.IS["simrs"]
|
||||
|
||||
if err := tx.
|
||||
Where("\"kode\" = ?", simgosId).
|
||||
First(&data).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, simgosId, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func UpdateSimgosData(input e.UpdateDto, dataSimgos *esync.UnitLink, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, input, "started", "DBUpdate")
|
||||
|
||||
data := setDataSimgos(&input)
|
||||
data.Kode = dataSimgos.Simgos_Id
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.IS["simrs"]
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func HardDeleteSimgosData(data *esimgos.MPoly, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBDelete")
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.IS["simrs"]
|
||||
}
|
||||
|
||||
if err := tx.
|
||||
Delete(&data).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-delete-fail",
|
||||
Detail: "Database delete failed",
|
||||
Raw: err,
|
||||
}
|
||||
return pl.SetLogError(event, data)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLinkData(simxId, simgosId uint, event *pl.Event, dbx ...*gorm.DB) (*esync.UnitLink, error) {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
data := setDataSimxLink(simxId, simgosId)
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Create(&data).Error; err != nil {
|
||||
return nil, plh.HandleCreateError(data, event, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func ReadDetailLinkData(simxId uint16, event *pl.Event) (*esync.UnitLink, error) {
|
||||
pl.SetLogInfo(event, simxId, "started", "DBReadDetail")
|
||||
data := esync.UnitLink{}
|
||||
|
||||
var tx = dg.I
|
||||
|
||||
if err := tx.
|
||||
Where("\"Simx_Id\" = ?", simxId).
|
||||
First(&data).Error; err != nil {
|
||||
if processedErr := pu.HandleReadError(err, event, source, simxId, data); processedErr != nil {
|
||||
return nil, processedErr
|
||||
}
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return &data, nil
|
||||
}
|
||||
|
||||
func DeleteLinkData(data *esync.UnitLink, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBDelete")
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Delete(&data).Error; err != nil {
|
||||
event.Status = "failed"
|
||||
event.ErrInfo = pl.ErrorInfo{
|
||||
Code: "data-delete-fail",
|
||||
Detail: "Database delete failed",
|
||||
Raw: err,
|
||||
}
|
||||
return pl.SetLogError(event, data)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateLogData(input esynclog.SimxLogDto, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, nil, "started", "DBCreate")
|
||||
data := setDataSimxLog(&input)
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
tx = dbx[0]
|
||||
} else {
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
if err := tx.Create(&data).Error; err != nil {
|
||||
return plh.HandleCreateError(input, event, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(event, nil, "complete")
|
||||
return nil
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
package unit
|
||||
|
||||
import (
|
||||
pl "simrs-vx/pkg/logger"
|
||||
pu "simrs-vx/pkg/use-case-helper"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type middlewareRunner struct {
|
||||
Event *pl.Event
|
||||
Tx *gorm.DB
|
||||
MwType pu.MWType
|
||||
}
|
||||
|
||||
// NewMiddlewareExecutor creates a new middleware executor
|
||||
func newMiddlewareRunner(event *pl.Event, tx *gorm.DB) *middlewareRunner {
|
||||
return &middlewareRunner{
|
||||
Event: event,
|
||||
Tx: tx,
|
||||
}
|
||||
}
|
||||
|
||||
// ExecuteCreateMiddleware executes create middleware
|
||||
func (me *middlewareRunner) RunCreateMiddleware(middlewares []createMw, input *e.CreateDto, data *e.Unit) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunReadListMiddleware(middlewares []readListMw, input *e.ReadListDto, data *e.Unit) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunReadDetailMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Unit) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunUpdateMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Unit) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) RunDeleteMiddleware(middlewares []readDetailMw, input *e.ReadDetailDto, data *e.Unit) error {
|
||||
for _, middleware := range middlewares {
|
||||
logData := pu.GetLogData(input, data)
|
||||
|
||||
pl.SetLogInfo(me.Event, logData, "started", middleware.Name)
|
||||
|
||||
if err := middleware.Func(input, data, me.Tx); err != nil {
|
||||
return pu.HandleMiddlewareError(me.Event, string(me.MwType), middleware.Name, logData, err)
|
||||
}
|
||||
|
||||
pl.SetLogInfo(me.Event, nil, "complete")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (me *middlewareRunner) setMwType(mwType pu.MWType) {
|
||||
me.MwType = mwType
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package unit
|
||||
|
||||
// example of middleware
|
||||
// func init() {
|
||||
// createPreMw = append(createPreMw,
|
||||
// CreateMw{Name: "modif-input", Func: pm.ModifInput},
|
||||
// CreateMw{Name: "check-data", Func: pm.CheckData},
|
||||
// )
|
||||
// }
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
DESCRIPTION:
|
||||
A sample, part of the package that contains type, constants, and/or variables.
|
||||
|
||||
In this sample it also provides type and variable regarding the needs of the
|
||||
middleware to separate from main use-case which has the basic CRUD
|
||||
functionality. The purpose of this is to make the code more maintainable.
|
||||
*/
|
||||
package unit
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
e "simrs-vx/internal/domain/main-entities/unit"
|
||||
)
|
||||
|
||||
type createMw struct {
|
||||
Name string
|
||||
Func func(input *e.CreateDto, data *e.Unit, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type readListMw struct {
|
||||
Name string
|
||||
Func func(input *e.ReadListDto, data *e.Unit, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type readDetailMw struct {
|
||||
Name string
|
||||
Func func(input *e.ReadDetailDto, data *e.Unit, tx *gorm.DB) error
|
||||
}
|
||||
|
||||
type UpdateMw = readDetailMw
|
||||
type DeleteMw = readDetailMw
|
||||
|
||||
var createPreMw []createMw // preprocess middleware
|
||||
var createPostMw []createMw // postprocess middleware
|
||||
var readListPreMw []readListMw // ..
|
||||
var readListPostMw []readListMw // ..
|
||||
var readDetailPreMw []readDetailMw
|
||||
var readDetailPostMw []readDetailMw
|
||||
var updatePreMw []readDetailMw
|
||||
var updatePostMw []readDetailMw
|
||||
var deletePreMw []readDetailMw
|
||||
var deletePostMw []readDetailMw
|
||||
Reference in New Issue
Block a user