add entity fileattchemnt and update contslist

This commit is contained in:
vanilia
2025-11-11 11:04:56 +07:00
106 changed files with 1532 additions and 940 deletions
+9 -9
View File
@@ -1,9 +1,9 @@
package main
import (
m "simrs-vx/internal/interface/migration"
)
func main() {
m.Migrate(m.Main)
}
package main
import (
m "simrs-vx/internal/interface/migration"
)
func main() {
m.Migrate(m.Main)
}
@@ -0,0 +1,14 @@
-- Modify "Consultation" table
ALTER TABLE "public"."Consultation" ADD COLUMN "DstUnit_Code" text NULL, ADD COLUMN "DstDoctor_Code" text NULL;
-- Modify "ControlLetter" table
ALTER TABLE "public"."ControlLetter" ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "Specialist_Code" text NULL, ADD COLUMN "Subspecialist_Code" text NULL, ADD COLUMN "Doctor_Code" text NULL;
-- Modify "Encounter" table
ALTER TABLE "public"."Encounter" ADD COLUMN "Specialist_Code" text NULL, ADD COLUMN "Subspecialist_Code" text NULL, ADD COLUMN "Appointment_Doctor_Code" text NULL, ADD COLUMN "Responsible_Doctor_Code" text NULL;
-- Modify "InternalReference" table
ALTER TABLE "public"."InternalReference" ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "Doctor_Code" text NULL;
-- Modify "PracticeSchedule" table
ALTER TABLE "public"."PracticeSchedule" ADD COLUMN "Doctor_Code" text NULL;
-- Modify "ResponsibleDoctorHist" table
ALTER TABLE "public"."ResponsibleDoctorHist" ADD COLUMN "Doctor_Code" text NULL;
-- Modify "TherapyProtocol" table
ALTER TABLE "public"."TherapyProtocol" ADD COLUMN "Doctor_Code" text NULL;
@@ -0,0 +1,14 @@
-- Modify "Consultation" table
ALTER TABLE "public"."Consultation" DROP CONSTRAINT "fk_Consultation_DstDoctor", DROP CONSTRAINT "fk_Consultation_DstUnit", DROP COLUMN "DstUnit_Id", DROP COLUMN "DstDoctor_Id", ALTER COLUMN "DstUnit_Code" TYPE character varying(10), ALTER COLUMN "DstDoctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_Consultation_DstDoctor" FOREIGN KEY ("DstDoctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Consultation_DstUnit" FOREIGN KEY ("DstUnit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "ControlLetter" table
ALTER TABLE "public"."ControlLetter" DROP CONSTRAINT "fk_ControlLetter_Doctor", DROP CONSTRAINT "fk_ControlLetter_Specialist", DROP CONSTRAINT "fk_ControlLetter_Subspecialist", DROP CONSTRAINT "fk_ControlLetter_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", DROP COLUMN "Doctor_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "Specialist_Code" TYPE character varying(10), ALTER COLUMN "Subspecialist_Code" TYPE character varying(10), ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_ControlLetter_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_ControlLetter_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "Encounter" table
ALTER TABLE "public"."Encounter" DROP CONSTRAINT "fk_Encounter_Appointment_Doctor", DROP CONSTRAINT "fk_Encounter_Responsible_Doctor", DROP CONSTRAINT "fk_Encounter_Specialist", DROP CONSTRAINT "fk_Encounter_Subspecialist", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", DROP COLUMN "Responsible_Doctor_Id", DROP COLUMN "Appointment_Doctor_Id", ALTER COLUMN "Specialist_Code" TYPE character varying(10), ALTER COLUMN "Subspecialist_Code" TYPE character varying(10), ALTER COLUMN "Appointment_Doctor_Code" TYPE character varying(20), ALTER COLUMN "Responsible_Doctor_Code" TYPE character varying(20), ADD COLUMN "Unit_Code" text NULL, ADD COLUMN "InsuranceCompany_Code" text NULL, ADD CONSTRAINT "fk_Encounter_Appointment_Doctor" FOREIGN KEY ("Appointment_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Responsible_Doctor" FOREIGN KEY ("Responsible_Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "InternalReference" table
ALTER TABLE "public"."InternalReference" DROP CONSTRAINT "fk_InternalReference_Doctor", DROP CONSTRAINT "fk_InternalReference_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "Doctor_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_InternalReference_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_InternalReference_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "PracticeSchedule" table
ALTER TABLE "public"."PracticeSchedule" DROP CONSTRAINT "fk_PracticeSchedule_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_PracticeSchedule_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "ResponsibleDoctorHist" table
ALTER TABLE "public"."ResponsibleDoctorHist" DROP CONSTRAINT "fk_ResponsibleDoctorHist_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_ResponsibleDoctorHist_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "TherapyProtocol" table
ALTER TABLE "public"."TherapyProtocol" DROP CONSTRAINT "fk_TherapyProtocol_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_TherapyProtocol_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,4 @@
-- Modify "Chemo" table
ALTER TABLE "public"."Chemo" ADD COLUMN "SrcUnit_Code" text NULL;
-- Modify "Encounter" table
ALTER TABLE "public"."Encounter" DROP CONSTRAINT "fk_Encounter_InsuranceCompany", DROP CONSTRAINT "fk_Encounter_Unit", DROP COLUMN "Unit_Id", DROP COLUMN "InsuranceCompany_Id", ALTER COLUMN "Unit_Code" TYPE character varying(10), ALTER COLUMN "InsuranceCompany_Code" TYPE character varying(20), ADD CONSTRAINT "fk_Encounter_InsuranceCompany" FOREIGN KEY ("InsuranceCompany_Code") REFERENCES "public"."InsuranceCompany" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Encounter_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,2 @@
-- Modify "Chemo" table
ALTER TABLE "public"."Chemo" DROP CONSTRAINT "fk_Chemo_SrcUnit", DROP COLUMN "SrcUnit_Id", ALTER COLUMN "SrcUnit_Code" TYPE character varying(10), ADD CONSTRAINT "fk_Chemo_SrcUnit" FOREIGN KEY ("SrcUnit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,8 @@
-- Modify "DeviceOrder" table
ALTER TABLE "public"."DeviceOrder" ADD COLUMN "Doctor_Code" text NULL;
-- Modify "Inpatient" table
ALTER TABLE "public"."Inpatient" ADD COLUMN "Infra_Code" character varying(10) NULL;
-- Modify "MaterialOrder" table
ALTER TABLE "public"."MaterialOrder" ADD COLUMN "Doctor_Code" text NULL;
-- Modify "McuOrder" table
ALTER TABLE "public"."McuOrder" ADD COLUMN "Doctor_Code" text NULL;
@@ -0,0 +1,8 @@
-- Modify "DeviceOrder" table
ALTER TABLE "public"."DeviceOrder" DROP CONSTRAINT "fk_DeviceOrder_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_DeviceOrder_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "Inpatient" table
ALTER TABLE "public"."Inpatient" DROP CONSTRAINT "fk_Inpatient_Infra", DROP COLUMN "Infra_Id", ADD CONSTRAINT "fk_Inpatient_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "MaterialOrder" table
ALTER TABLE "public"."MaterialOrder" DROP CONSTRAINT "fk_MaterialOrder_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_MaterialOrder_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "McuOrder" table
ALTER TABLE "public"."McuOrder" DROP CONSTRAINT "fk_McuOrder_Doctor", DROP COLUMN "Doctor_Id", ALTER COLUMN "Doctor_Code" TYPE character varying(20), ADD CONSTRAINT "fk_McuOrder_Doctor" FOREIGN KEY ("Doctor_Code") REFERENCES "public"."Doctor" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,4 @@
-- Modify "DeviceOrderItem" table
ALTER TABLE "public"."DeviceOrderItem" ADD COLUMN "Device_Code" text NULL;
-- Modify "MaterialOrderItem" table
ALTER TABLE "public"."MaterialOrderItem" ADD COLUMN "Material_Code" text NULL;
@@ -0,0 +1,4 @@
-- Modify "DeviceOrderItem" table
ALTER TABLE "public"."DeviceOrderItem" DROP CONSTRAINT "fk_DeviceOrderItem_Device", DROP COLUMN "Device_Id", ALTER COLUMN "Device_Code" TYPE character varying(10), ADD CONSTRAINT "fk_DeviceOrderItem_Device" FOREIGN KEY ("Device_Code") REFERENCES "public"."Device" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "MaterialOrderItem" table
ALTER TABLE "public"."MaterialOrderItem" DROP CONSTRAINT "fk_MaterialOrderItem_Material", DROP COLUMN "Material_Id", ALTER COLUMN "Material_Code" TYPE character varying(10), ADD CONSTRAINT "fk_MaterialOrderItem_Material" FOREIGN KEY ("Material_Code") REFERENCES "public"."Material" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,8 @@
-- Modify "McuSrc" table
ALTER TABLE "public"."McuSrc" ALTER COLUMN "Code" SET NOT NULL, ADD COLUMN "Item_Code" text NULL;
-- Modify "McuSubSrc" table
ALTER TABLE "public"."McuSubSrc" ADD COLUMN "McuSrc_Code" text NULL;
-- Modify "MedicalActionSrc" table
ALTER TABLE "public"."MedicalActionSrc" ADD COLUMN "Item_Code" text NULL;
-- Modify "MedicalActionSrcItem" table
ALTER TABLE "public"."MedicalActionSrcItem" ADD COLUMN "MedicalActionSrc_Code" text NULL, ADD COLUMN "ProcedureSrc_Code" text NULL, ADD COLUMN "Item_Code" text NULL;
@@ -0,0 +1,8 @@
-- Modify "McuSrc" table
ALTER TABLE "public"."McuSrc" DROP CONSTRAINT "fk_McuSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_McuSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "McuSubSrc" table
ALTER TABLE "public"."McuSubSrc" DROP CONSTRAINT "fk_McuSubSrc_McuSrc", DROP COLUMN "McuSrc_Id", ALTER COLUMN "McuSrc_Code" TYPE character varying(20), ADD COLUMN "Item_Code" text NULL, ADD CONSTRAINT "fk_McuSubSrc_McuSrc" FOREIGN KEY ("McuSrc_Code") REFERENCES "public"."McuSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "MedicalActionSrc" table
ALTER TABLE "public"."MedicalActionSrc" DROP CONSTRAINT "fk_MedicalActionSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_MedicalActionSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
-- Modify "MedicalActionSrcItem" table
ALTER TABLE "public"."MedicalActionSrcItem" DROP CONSTRAINT "fk_MedicalActionSrcItem_Item", DROP CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc", DROP CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc", DROP COLUMN "MedicalActionSrc_Id", DROP COLUMN "ProcedureSrc_Id", DROP COLUMN "Item_Id", ALTER COLUMN "MedicalActionSrc_Code" TYPE character varying(20), ALTER COLUMN "ProcedureSrc_Code" TYPE character varying(10), ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_MedicalActionSrcItem_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc" FOREIGN KEY ("MedicalActionSrc_Code") REFERENCES "public"."MedicalActionSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc" FOREIGN KEY ("ProcedureSrc_Code") REFERENCES "public"."ProcedureSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,2 @@
-- Modify "McuSubSrc" table
ALTER TABLE "public"."McuSubSrc" DROP CONSTRAINT "fk_McuSubSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_McuSubSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION;
@@ -0,0 +1,17 @@
-- Create "FileAttachment" table
CREATE TABLE "public"."FileAttachment" (
"Id" bigserial NOT NULL,
"CreatedAt" timestamptz NULL,
"UpdatedAt" timestamptz NULL,
"DeletedAt" timestamptz NULL,
"EntityType_Code" text NULL,
"Ref_Id" bigint NULL,
"Type_Code" text NULL,
"Name" text NULL,
"FilePath" text NULL,
"FileName" text NULL,
"Upload_Employee_Id" bigint NULL,
PRIMARY KEY ("Id"),
CONSTRAINT "fk_Encounter_FileAttachments" FOREIGN KEY ("Ref_Id") REFERENCES "public"."Encounter" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT "fk_FileAttachment_Upload_Employee" FOREIGN KEY ("Upload_Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION
);
+13 -1
View File
@@ -1,4 +1,4 @@
h1:nxld1x0gKb2nqU+0YPNq5FaAhodpZwnaSuBWyZrPO+0=
h1:l9TShSJKxWO7Ag2+PYB7DcVDd3pz/M2Sm0hpZYpUNBA=
20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k=
20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0=
20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI=
@@ -97,3 +97,15 @@ h1:nxld1x0gKb2nqU+0YPNq5FaAhodpZwnaSuBWyZrPO+0=
20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68=
20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w=
20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g=
20251110052049.sql h1:232T2x8xTczJl9nk4jxJpZXhoOGYthhxjJ7nK8Jd8vg=
20251110062042.sql h1:WnfVUXrzYoj8qdkkjO9/JQQ8agGd4GfSHQdMjo7LDAg=
20251110063202.sql h1:hSzGfwVMWa6q3vwIQZUkxKgBNCzHjB+6GKy54zfV+oQ=
20251110063633.sql h1:/VpofIAqNS1CnazEnpW/+evbzn9Kew3xDW48r57M+Xg=
20251110085551.sql h1:bFZwSmfvVbTUr/enWB82WqjG88gpqcZ6s45btUvO0uo=
20251110091516.sql h1:KkJMwPQuaZQhiqnKrNQrgP12gw9rV8T3P2o3mtGTcvY=
20251110091948.sql h1:I4odAYrJdvNf1jPw6ppDC0XdI7v6vKBACg/ABwUgA7I=
20251110092729.sql h1:l1out8soEmVP6dNjaIOtGYo6QDcoJZRI8X1sjZ5ZGmo=
20251110093522.sql h1:nsz8jCxGjEdr/bz9g+4ozfZzIP803xONjVmucad1GMc=
20251110100258.sql h1:IBqt1VZj5WjQ+l9aAFGHOCCBtzb03KlLLihFLut7itg=
20251110100545.sql h1:6/LV7751iyKxE2xI6vO1zly+aHUwxXD/IBwLcVpKxqM=
20251111040358.sql h1:dbHqvkf0FWQVGpmTQAY0bdx6v2cXAxrPSH5byP0r/eU=
@@ -6,9 +6,8 @@ import (
)
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"`
VisitMode_Code ere.VisitModeCode `json:"visitMode_code"`
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.AmbulatoryClassCode `json:"class_code" validate:"maxLength=10"`
}
type ReadListDto struct {
+4 -4
View File
@@ -20,7 +20,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataVerifiedCode `json:"status_code"`
SrcUnit_Id *uint `json:"srcUnit_id"`
SrcUnit_Code *string `json:"srcUnit_code"`
}
type ReadListDto struct {
@@ -33,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_Id *uint `json:"srcUnit-id"`
SrcUnit_Code *string `json:"srcUnit-code"`
}
type ReadDetailDto struct {
@@ -72,7 +72,7 @@ type ResponseDto struct {
VerifiedAt *time.Time `json:"verifiedAt"`
VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"`
VerifiedBy *eus.User `json:"verifiedBy,omitempty"`
SrcUnit_Id *uint `json:"srcUnit_id"`
SrcUnit_Code *string `json:"srcUnit_code"`
SrcUnit *eun.Unit `json:"srcUnit,omitempty"`
}
@@ -84,7 +84,7 @@ func (d Chemo) ToResponse() ResponseDto {
VerifiedAt: d.VerifiedAt,
VerifiedBy_User_Id: d.VerifiedBy_User_Id,
VerifiedBy: d.VerifiedBy,
SrcUnit_Id: d.SrcUnit_Id,
SrcUnit_Code: d.SrcUnit_Code,
SrcUnit: d.SrcUnit,
}
resp.Main = d.Main
@@ -19,8 +19,8 @@ type Chemo struct {
VerifiedAt *time.Time `json:"verifiedAt"`
VerifiedBy_User_Id *uint `json:"verifiedBy_user_id"`
VerifiedBy *eus.User `json:"verifiedBy,omitempty" gorm:"foreignKey:VerifiedBy_User_Id;references:Id"`
SrcUnit_Id *uint `json:"src_unit_id"`
SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Id;references:Id"`
SrcUnit_Code *string `json:"src_unit_code"`
SrcUnit *eun.Unit `json:"src_unit,omitempty" gorm:"foreignKey:SrcUnit_Code;references:Code"`
Bed *string `json:"bed" gorm:"size:1024"`
Needs *string `json:"needs" gorm:"size:2048"`
}
@@ -20,7 +20,7 @@ type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Date *time.Time `json:"date"`
Problem *string `json:"problem" validate:"maxLength=10240"`
DstUnit_Id *uint `json:"dstUnit_id"`
DstUnit_Code *string `json:"dstUnit_code"`
}
type ReadListDto struct {
@@ -30,9 +30,9 @@ type ReadListDto struct {
}
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
DstUnit_Id *uint `json:"dstUnit-id"`
DstDoctor_Id *uint `json:"dstDoctor-id"`
Encounter_Id *uint `json:"encounter-id"`
DstUnit_Code *string `json:"dstUnit-code"`
DstDoctor_Code *string `json:"dstDoctor-code"`
}
type ReadDetailDto struct {
@@ -63,29 +63,29 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Date *time.Time `json:"date"`
Problem *string `json:"problem"`
Solution *string `json:"solution"`
DstUnit_Id *uint `json:"dstUnit_id"`
DstUnit *eu.Unit `json:"dstUnit,omitempty"`
DstDoctor_Id *uint `json:"dstDoctor_id"`
DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"`
RepliedAt *time.Time `json:"repliedAt"`
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Date *time.Time `json:"date"`
Problem *string `json:"problem"`
Solution *string `json:"solution"`
DstUnit_Code *string `json:"dstUnit_code"`
DstUnit *eu.Unit `json:"dstUnit,omitempty"`
DstDoctor_Code *string `json:"dstDoctor_code"`
DstDoctor *ed.Doctor `json:"dstDoctor,omitempty"`
RepliedAt *time.Time `json:"repliedAt"`
}
func (d Consultation) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Date: d.Date,
Problem: d.Problem,
Solution: d.Solution,
DstUnit_Id: d.DstUnit_Id,
DstUnit: d.DstUnit,
DstDoctor_Id: d.DstDoctor_Id,
DstDoctor: d.DstDoctor,
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Date: d.Date,
Problem: d.Problem,
Solution: d.Solution,
DstUnit_Code: d.DstUnit_Code,
DstUnit: d.DstUnit,
DstDoctor_Code: d.DstDoctor_Code,
DstDoctor: d.DstDoctor,
}
resp.Main = d.Main
return resp
@@ -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_Id *uint `json:"dstUnit_id"`
DstUnit *eu.Unit `json:"dstUnit" gorm:"foreignKey:DstUnit_Id;references:Id"`
DstDoctor_Id *uint `json:"dstDoctor_id"`
DstDoctor *ed.Doctor `json:"dstDoctor" gorm:"foreignKey:DstDoctor_Id;references:Id"`
RepliedAt *time.Time `json:"repliedAt"`
Problem *string `json:"case" gorm:"size:10240"`
Solution *string `json:"solution" gorm:"size:10240"`
DstUnit_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"`
}
@@ -5,7 +5,6 @@ import (
"time"
// internal - lib
pa "simrs-vx/internal/lib/auth"
// internal - domain - base-entities
ecore "simrs-vx/internal/domain/base-entities/core"
@@ -20,12 +19,12 @@ import (
)
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Unit_Id *uint `json:"unit_id"`
Specialist_Id *uint `json:"specialist_id"`
Subspecialist_Id *uint `json:"subspecialist_id"`
Doctor_Id *uint `json:"doctor_id"`
Date *time.Time `json:"date"`
Encounter_Id *uint `json:"encounter_id"`
Unit_Code *string `json:"unit_code"`
Specialist_Code *string `json:"specialist_code"`
Subspecialist_Code *string `json:"subspecialist_code"`
Doctor_Code *string `json:"doctor_code"`
Date *time.Time `json:"date"`
}
type ReadListDto struct {
@@ -35,12 +34,12 @@ type ReadListDto struct {
}
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Unit_Id *uint `json:"unit-id"`
Specialist_Id *uint `json:"specialist-id"`
Subspecialist_Id *uint `json:"subspecialist-id"`
Doctor_Id *uint `json:"doctor-id"`
Date *time.Time `json:"date"`
Encounter_Id *uint `json:"encounter-id"`
Unit_Code *string `json:"unit-code"`
Specialist_Code *string `json:"specialist-code"`
Subspecialist_Code *string `json:"subspecialist-code"`
Doctor_Code *string `json:"doctor-code"`
Date *time.Time `json:"date"`
}
type ReadDetailDto struct {
@@ -57,13 +56,6 @@ type DeleteDto struct {
Id uint `json:"id"`
}
type ReplyDto struct {
Id uint `json:"id"`
Solution *string `json:"solution"`
pa.AuthInfo
}
type MetaDto struct {
PageNumber int `json:"page_number"`
PageSize int `json:"page_size"`
@@ -72,32 +64,32 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Unit_Id *uint `json:"unit_id"`
Unit *eu.Unit `json:"unit,omitempty"`
Specialist_Id *uint `json:"specialist_id"`
Specialist *es.Specialist `json:"specialist,omitempty"`
Subspecialist_Id *uint `json:"subspecialist_id"`
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Date *time.Time `json:"date"`
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Unit_Code *string `json:"unit_code"`
Unit *eu.Unit `json:"unit,omitempty"`
Specialist_Code *string `json:"specialist_code"`
Specialist *es.Specialist `json:"specialist,omitempty"`
Subspecialist_Code *string `json:"subspecialist_code"`
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Date *time.Time `json:"date"`
}
func (d ControlLetter) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Unit_Id: d.Unit_Id,
Unit: d.Unit,
Specialist_Id: d.Specialist_Id,
Specialist: d.Specialist,
Subspecialist_Id: d.Subspecialist_Id,
Subspecialist: d.Subspecialist,
Doctor_Id: d.Doctor_Id,
Doctor: d.Doctor,
Date: d.Date,
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Unit_Code: d.Unit_Code,
Unit: d.Unit,
Specialist_Code: d.Specialist_Code,
Specialist: d.Specialist,
Subspecialist_Code: d.Subspecialist_Code,
Subspecialist: d.Subspecialist,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Date: d.Date,
}
resp.Main = d.Main
return resp
@@ -12,16 +12,16 @@ import (
)
type ControlLetter struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"`
Unit_Id *uint `json:"unit_id"`
Unit *eu.Unit `json:"unit" gorm:"foreignKey:Unit_Id;references:Id"`
Specialist_Id *uint `json:"specialist_id"`
Specialist *es.Specialist `json:"specialist" gorm:"foreignKey:Specialist_Id;references:Id"`
Subspecialist_Id *uint `json:"subspecialist_id"`
Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Id;references:Id"`
Date *time.Time `json:"date"`
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter" gorm:"foreignKey:Encounter_Id;references:Id"`
Unit_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"`
Subspecialist *ess.Subspecialist `json:"subspecialist" gorm:"foreignKey:Subspecialist_Code;references:Code"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor" gorm:"foreignKey:Doctor_Code;references:Code"`
Date *time.Time `json:"date"`
}
@@ -7,9 +7,9 @@ import (
)
type CreateDto struct {
DeviceOrder_Id *uint `json:"deviceOrder_id"`
Device_Id *uint `json:"device_id"`
Count uint8 `json:"count"`
DeviceOrder_Id *uint `json:"deviceOrder_id"`
Device_Code *string `json:"device_code"`
Count uint8 `json:"count"`
}
type ReadListDto struct {
@@ -19,9 +19,9 @@ type ReadListDto struct {
}
type FilterDto struct {
DeviceOrder_Id *uint `json:"deviceOrder-id"`
Device_Id *uint `json:"device-id"`
Count uint8 `json:"count"`
DeviceOrder_Id *uint `json:"deviceOrder-id"`
Device_Code *string `json:"device-code"`
Count uint8 `json:"count"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
@@ -46,7 +46,7 @@ type ResponseDto struct {
ecore.Main
DeviceOrder_Id *uint `json:"deviceOrder_id"`
DeviceOrder *edo.DeviceOrder `json:"deviceOrder,omitempty"`
Device_Id *uint `json:"device_id"`
Device_Code *string `json:"device_code"`
Device *ed.Device `json:"device,omitempty"`
Count uint8 `json:"count"`
}
@@ -55,7 +55,7 @@ func (d DeviceOrderItem) ToResponse() ResponseDto {
resp := ResponseDto{
DeviceOrder_Id: d.DeviceOrder_Id,
DeviceOrder: d.DeviceOrder,
Device_Id: d.Device_Id,
Device_Code: d.Device_Code,
Device: d.Device,
Count: d.Count,
}
@@ -10,7 +10,7 @@ type DeviceOrderItem struct {
ecore.Main // adjust this according to the needs
DeviceOrder_Id *uint `json:"deviceOrder_id"`
DeviceOrder *edo.DeviceOrder `json:"deviceOrder,omitempty" gorm:"foreignKey:DeviceOrder_Id;references:Id"`
Device_Id *uint `json:"device_id"`
Device *ed.Device `json:"device,omitempty" gorm:"foreignKey:Device_Id;references:Id"`
Device_Code *string `json:"device_code"`
Device *ed.Device `json:"device,omitempty" gorm:"foreignKey:Device_Code;references:Code"`
Count uint8 `json:"count"`
}
@@ -18,7 +18,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataStatusCode `json:"status_code"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
pa.AuthInfo
}
@@ -32,7 +32,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Status_Code erc.DataStatusCode `json:"status-code"`
Doctor_Id *uint `json:"doctor-id"`
Doctor_Code *string `json:"doctor-code"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
@@ -57,7 +57,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -66,7 +66,7 @@ func (d DeviceOrder) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Status_Code: d.Status_Code,
}
@@ -12,8 +12,8 @@ type DeviceOrder struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -21,6 +21,6 @@ func (d DeviceOrder) IsCompleted() bool {
return d.Status_Code == erc.DSCDone
}
func (d DeviceOrder) IsSameDoctor(doctor_id *uint) bool {
return d.Doctor_Id == doctor_id
func (d DeviceOrder) IsSameDoctor(doctor_code *string) bool {
return d.Doctor_Code == doctor_code
}
+4 -3
View File
@@ -38,7 +38,7 @@ type FilterDto struct {
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
Employee_Id *uint `json:"employee_id"`
IHS_Number *string `json:"ihs_number"`
@@ -46,12 +46,13 @@ type ReadDetailDto struct {
}
type UpdateDto struct {
Id uint `json:"id"`
Id *uint `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint `json:"id"`
Id uint `json:"id"`
Code *string `json:"code"`
}
type MetaDto struct {
@@ -1,17 +0,0 @@
package encounter_document
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ee "simrs-vx/internal/domain/main-entities/employee"
)
type EncounterDocument struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Name string `json:"name"`
DocumentType string `json:"documentType"`
FilePath *string `json:"filePath"`
FileName *string `json:"fileName"`
Upload_Employee_Id *string `json:"upload_employee_id"`
Upload_Employee *ee.Employee `json:"upload_employee,omitempty" gorm:"foreignKey:Upload_Employee_Id;references:Id"`
}
+86 -47
View File
@@ -1,6 +1,13 @@
package encounter
import (
eam "simrs-vx/internal/domain/main-entities/ambulatory"
edc "simrs-vx/internal/domain/main-entities/death-cause"
eem "simrs-vx/internal/domain/main-entities/emergency"
eip "simrs-vx/internal/domain/main-entities/inpatient"
eir "simrs-vx/internal/domain/main-entities/internal-reference"
er "simrs-vx/internal/domain/main-entities/rehab/base"
// std
"time"
@@ -19,7 +26,6 @@ import (
ea "simrs-vx/internal/domain/main-entities/appointment"
ed "simrs-vx/internal/domain/main-entities/doctor"
ee "simrs-vx/internal/domain/main-entities/employee"
eir "simrs-vx/internal/domain/main-entities/internal-reference"
ep "simrs-vx/internal/domain/main-entities/patient"
es "simrs-vx/internal/domain/main-entities/specialist"
ess "simrs-vx/internal/domain/main-entities/subspecialist"
@@ -27,29 +33,31 @@ import (
)
type CreateDto struct {
Patient_Id *uint `json:"patient_id"`
RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"`
SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub
Infra_Id *uint16 `json:"infra_id"` // for inpatient
Unit_Id *uint `json:"unit_id"`
Specialist_Id *uint16 `json:"specialist_id"`
Subspecialist_Id *uint16 `json:"subspecialist_id"`
VisitDate time.Time `json:"visitDate"`
PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"`
InsuranceCompany_Id *uint `json:"insuranceCompany_id"`
Member_Number *string `json:"member_number" validate:"maxLength=20"`
Ref_Number *string `json:"ref_number" validate:"maxLength=20"`
Trx_Number *string `json:"trx_number" validate:"maxLength=20"`
Appointment_Doctor_Id *uint `json:"appointment_doctor_id"`
Adm_Employee_Id *uint `json:"-"`
Responsible_Doctor_Id *uint `json:"responsible_doctor_id"`
RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"`
Appointment_Id *uint `json:"appointment_id"`
RefTypeCode ere.RefTypeCode `json:"refTypeCode"`
NewStatus bool `json:"newStatus"`
VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"` // if subClass_Code is rehab
AllocatedVisitCount *int `json:"allocatedVisitCount"` // if subClass_Code is rehab and VisitMode_Code is "adm"
Patient_Id *uint `json:"patient_id"`
RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class_code" validate:"maxLength=10"`
SubClass_Code *string `json:"subClass_code" validate:"maxLength=10"` // for sub
Infra_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"`
PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"`
InsuranceCompany_Code *string `json:"insuranceCompany_code"`
Member_Number *string `json:"member_number" validate:"maxLength=20"`
Ref_Number *string `json:"ref_number" validate:"maxLength=20"`
Trx_Number *string `json:"trx_number" validate:"maxLength=20"`
Appointment_Doctor_Code *string `json:"appointment_doctor_code"`
Adm_Employee_Id *uint `json:"-"`
Responsible_Doctor_Code *string `json:"responsible_doctor_code"`
RefSource_Name *string `json:"refSource_name" validate:"maxLength=100"`
Appointment_Id *uint `json:"appointment_id"`
RefTypeCode ere.RefTypeCode `json:"refTypeCode"`
NewStatus bool `json:"newStatus"`
Id uint `json:"-"`
RecentEncounterAdm *Encounter `json:"-"` // if subClass_Code is rehab
VisitMode_Code ere.VisitModeCode `json:"-"` // if subClass_Code is rehab
pa.AuthInfo
}
@@ -67,12 +75,12 @@ type FilterDto struct {
Patient *ep.Patient `json:"patient,omitempty"`
RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class-code" validate:"maxLength=10"`
Unit_Id *uint `json:"unit-id"`
Specialist_Id *uint16 `json:"specialist-id"`
Subspecialist_Id *uint16 `json:"subspecialist-id"`
Unit_Code *string `json:"unit-code"`
Specialist_Code *string `json:"specialist-code"`
Subspecialist_Code *string `json:"subspecialist-code"`
VisitDate time.Time `json:"visitDate"`
Appoinment_Doctor_Id *uint `json:"appointment-doctor-id"`
Responsible_Doctor_Id *uint `json:"responsible-doctor-id"`
Appoinment_Doctor_Code *string `json:"appointment-doctor-code"`
Responsible_Doctor_Code *string `json:"responsible-doctor-code"`
DischargeMethod_Code ere.DischargeMethodCode `json:"dischargeMethod-code" validate:"maxLength=10"`
RefSource_Name *string `json:"refSource-name" validate:"maxLength=100"`
Appointment_Id *uint `json:"appointment-id"`
@@ -114,15 +122,25 @@ type DischargeDto struct {
AdmDischargeEducation *string `json:"admDischargeEducation"`
DischargeReason *string `json:"dischargeReason"`
DeathCause *string `json:"deathCause"`
InternalReferences *[]eir.CreateDto `json:"internalReferences,omitempty"`
}
type CheckinDto struct {
Id uint `json:"id"`
Responsible_Doctor_Id *uint `json:"responsible_doctor_id"`
Adm_Employee_Id *uint `json:"adm_employee_id"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
Id uint `json:"id"`
Responsible_Doctor_Code *string `json:"responsible_doctor_code"`
Adm_Employee_Id *uint `json:"adm_employee_id"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
}
type SwitchUnitDto struct {
Id uint `json:"id"`
PolySwitchCode *ere.PolySwitchCode `json:"polySwitchCode"`
InternalReferences *[]eir.CreateDto `json:"internalReferences" validate:"required"`
}
type ApproveUnitDto struct {
Id uint `json:"id"`
InternalReferences_Id uint16 `json:"internalReferences_id" validate:"required"`
}
type ResponseDto struct {
@@ -131,21 +149,21 @@ type ResponseDto struct {
Patient *ep.Patient `json:"patient,omitempty"`
RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class_code"`
Unit_Id *uint `json:"unit_id"`
Specialist_Id *uint16 `json:"specialist_id"`
Unit_Code *string `json:"unit_code"`
Specialist_Code *string `json:"specialist_code"`
Specialist *es.Specialist `json:"specialist,omitempty"`
Subspecialist_Id *uint16 `json:"subspecialist_id"`
Subspecialist_Code *string `json:"subspecialist_code"`
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"`
Unit *eu.Unit `json:"unit,omitempty"`
VisitDate time.Time `json:"visitDate"`
PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code"`
InsuranceCompany_Id *uint `json:"insuranceCompany_id"`
InsuranceCompany_Code *string `json:"insuranceCompany_code"`
Member_Number *string `json:"member_number"`
Ref_Number *string `json:"ref_number"`
Trx_Number *string `json:"trx_number"`
Appointment_Doctor_Id *uint `json:"appointment_doctor_id"`
Appointment_Doctor_Code *string `json:"appointment_doctor_code"`
Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty"`
Responsible_Doctor_Id *uint `json:"responsible_doctor_id"`
Responsible_Doctor_Code *string `json:"responsible_doctor_code"`
Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty"`
Adm_Employee_Id *uint `json:"adm_employee_id"`
Adm_Employee *ee.Employee `json:"adm_employee,omitempty"`
@@ -159,6 +177,17 @@ type ResponseDto struct {
DischargeReason *string `json:"dischargeReason"`
Status_Code erc.DataStatusCode `json:"status_code"`
VclaimSep *evs.VclaimSep `json:"vclaimSep,omitempty"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
Discharge_Date *time.Time `json:"discharge_date"`
InternalReferences *[]eir.InternalReference `json:"internalReferences,omitempty"`
DeathCause *edc.DeathCause `json:"deathCause,omitempty"`
NewStatus bool `json:"newStatus"`
Ambulatory *eam.Ambulatory `json:"ambulatory,omitempty"`
Emergency *eem.Emergency `json:"emergency,omitempty"`
Inpatient *eip.Inpatient `json:"inpatient,omitempty"`
Rehab *er.Basic `json:"rehab,omitempty"`
RehabChildren *[]er.Basic `json:"rehabChildren,omitempty"`
}
func (d Encounter) ToResponse() ResponseDto {
@@ -167,23 +196,23 @@ func (d Encounter) ToResponse() ResponseDto {
Patient: d.Patient,
RegisteredAt: d.RegisteredAt,
Class_Code: d.Class_Code,
Unit_Id: d.Unit_Id,
Unit_Code: d.Unit_Code,
Unit: d.Unit,
Specialist_Id: d.Specialist_Id,
Specialist_Code: d.Specialist_Code,
Specialist: d.Specialist,
Subspecialist_Id: d.Subspecialist_Id,
Subspecialist_Code: d.Subspecialist_Code,
Subspecialist: d.Subspecialist,
VisitDate: d.VisitDate,
PaymentMethod_Code: d.PaymentMethod_Code,
InsuranceCompany_Id: d.InsuranceCompany_Id,
InsuranceCompany_Code: d.InsuranceCompany_Code,
Member_Number: d.Member_Number,
Ref_Number: d.Ref_Number,
Trx_Number: d.Trx_Number,
Appointment_Doctor_Id: d.Appointment_Doctor_Id,
Appointment_Doctor_Code: d.Appointment_Doctor_Code,
Appointment_Doctor: d.Appointment_Doctor,
Adm_Employee_Id: d.Adm_Employee_Id,
Adm_Employee: d.Adm_Employee,
Responsible_Doctor_Id: d.Responsible_Doctor_Id,
Responsible_Doctor_Code: d.Responsible_Doctor_Code,
Responsible_Doctor: d.Responsible_Doctor,
Discharge_Method_Code: d.Discharge_Method_Code,
RefSource_Name: d.RefSource_Name,
@@ -195,6 +224,16 @@ func (d Encounter) ToResponse() ResponseDto {
DischargeReason: d.DischargeReason,
Status_Code: d.Status_Code,
VclaimSep: d.VclaimSep,
StartedAt: d.StartedAt,
FinishedAt: d.FinishedAt,
Discharge_Date: d.Discharge_Date,
InternalReferences: d.InternalReferences,
DeathCause: d.DeathCause,
NewStatus: d.NewStatus,
Emergency: d.Emergency,
Inpatient: d.Inpatient,
Rehab: d.Rehab,
RehabChildren: d.RehabChildren,
}
resp.Main = d.Main
return resp
@@ -9,7 +9,7 @@ import (
ed "simrs-vx/internal/domain/main-entities/doctor"
eem "simrs-vx/internal/domain/main-entities/emergency"
ee "simrs-vx/internal/domain/main-entities/employee"
eed "simrs-vx/internal/domain/main-entities/encounter-document"
efa "simrs-vx/internal/domain/main-entities/file-attachment"
eip "simrs-vx/internal/domain/main-entities/inpatient"
ei "simrs-vx/internal/domain/main-entities/insurance-company"
eir "simrs-vx/internal/domain/main-entities/internal-reference"
@@ -30,28 +30,28 @@ type Encounter struct {
Patient *ep.Patient `json:"patient,omitempty" gorm:"foreignKey:Patient_Id;references:Id"`
RegisteredAt *time.Time `json:"registeredAt"`
Class_Code ere.EncounterClassCode `json:"class_code" gorm:"not null;size:10"`
Unit_Id *uint `json:"unit_id"`
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
Specialist_Id *uint16 `json:"specialist_id"`
Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id;references:Id"`
Subspecialist_Id *uint16 `json:"subspecialist_id"`
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id;references:Id"`
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"`
Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"`
VisitDate time.Time `json:"visitDate"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
PaymentMethod_Code erc.PaymentMethodCode `json:"paymentMethod_code" gorm:"size:10"`
InsuranceCompany_Id *uint `json:"insuranceCompany_id"`
InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Id;references:Id"`
InsuranceCompany_Code *string `json:"insuranceCompany_code"`
InsuranceCompany *ei.InsuranceCompany `json:"insuranceCompany,omitempty" gorm:"foreignKey:InsuranceCompany_Code;references:Code"`
Member_Number *string `json:"memberNumber" gorm:"unique;size:20"`
RefType_Code *ere.RefTypeCode `json:"refType_code"`
Ref_Number *string `json:"refNumber" gorm:"unique;size:20"`
Trx_Number *string `json:"trxNumber" gorm:"unique;size:20"`
Appointment_Doctor_Id *uint `json:"appointment_doctor_id"`
Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Id;references:Id"`
Appointment_Doctor_Code *string `json:"appointment_doctor_code"`
Appointment_Doctor *ed.Doctor `json:"appointment_doctor,omitempty" gorm:"foreignKey:Appointment_Doctor_Code;references:Code"`
Adm_Employee_Id *uint `json:"adm_employee_id"`
Adm_Employee *ee.Employee `json:"adm_employee,omitempty" gorm:"foreignKey:Adm_Employee_Id;references:Id"`
Responsible_Doctor_Id *uint `json:"responsible_doctor_id"`
Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Id;references:Id"`
Responsible_Doctor_Code *string `json:"responsible_doctor_code"`
Responsible_Doctor *ed.Doctor `json:"responsible_doctor,omitempty" gorm:"foreignKey:Responsible_Doctor_Code;references:Code"`
Discharge_Method_Code *ere.DischargeMethodCode `json:"discharge_method_code" gorm:"size:16"`
RefSource_Name *string `json:"refSource_name" gorm:"size:100"`
Appointment_Id *uint `json:"appointment_id"`
@@ -71,7 +71,7 @@ type Encounter struct {
Inpatient *eip.Inpatient `json:"inpatient,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Rehab *er.Basic `json:"rehab,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
RehabChildren *[]er.Basic `json:"rehabChildren,omitempty" gorm:"foreignKey:Parent_Encounter_Id;references:Id"`
EncounterDocument *[]eed.EncounterDocument `json:"encounterDocument,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
FileAttachments *[]efa.FileAttachment `json:"fileAttachments,omitempty" gorm:"foreignKey:Ref_Id;references:Id"`
}
func (d Encounter) IsDone() bool {
@@ -0,0 +1,19 @@
package file_attachment
import (
ecore "simrs-vx/internal/domain/base-entities/core"
ee "simrs-vx/internal/domain/main-entities/employee"
eru "simrs-vx/internal/domain/references/upload"
)
type FileAttachment struct {
ecore.Main
EntityType_Code eru.EntityTypeCode `json:"entityType_code"`
Ref_Id *uint `json:"ref_id"`
Type_Code eru.UploadCode `json:"type_code"`
Name string `json:"name"`
FilePath *string `json:"filePath"`
FileName *string `json:"fileName"`
Upload_Employee_Id *string `json:"upload_employee_id"`
Upload_Employee *ee.Employee `json:"upload_employee,omitempty" gorm:"foreignKey:Upload_Employee_Id;references:Id"`
}
@@ -10,7 +10,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.InpatientClassCode `json:"class_code" validate:"maxLength=10"`
Infra_Id *uint16 `json:"infra_id"`
Infra_Code *string `json:"infra_code"`
}
type ReadListDto struct {
@@ -22,7 +22,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Class_Code ere.InpatientClassCode `json:"class-code"`
Infra_Id *uint16 `json:"infra-id"`
Infra_Code *string `json:"infra-code"`
}
type ReadDetailDto struct {
@@ -48,7 +48,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.InpatientClassCode `json:"class_code"`
Infra_Id *uint16 `json:"infra_id"`
Infra_Code *string `json:"infra_code"`
Infra *ei.Infra `json:"infra,omitempty"`
}
@@ -56,7 +56,7 @@ func (d Inpatient) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Class_Code: d.Class_Code,
Infra_Id: d.Infra_Id,
Infra_Code: d.Infra_Code,
Infra: d.Infra,
}
resp.Main = d.Main
@@ -10,6 +10,6 @@ type Inpatient struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Class_Code ere.InpatientClassCode `json:"class_code" gorm:"size:10"`
Infra_Id *uint16 `json:"infra_id"`
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"`
Infra_Code *string `json:"infra_code" gorm:"size:10"`
Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"`
}
@@ -1,15 +1,18 @@
package internal_reference
import (
erc "simrs-vx/internal/domain/references/common"
ecore "simrs-vx/internal/domain/base-entities/core"
ed "simrs-vx/internal/domain/main-entities/doctor"
eu "simrs-vx/internal/domain/main-entities/unit"
)
type CreateDto struct {
Encounter_Id *uint `json:"-"`
Unit_Id *uint16 `json:"unit_id"`
Doctor_Id *uint `json:"doctor_Id"`
Encounter_Id *uint `json:"-"`
Unit_Code *string `json:"unit_code"`
Doctor_Code *string `json:"doctor_code"`
Status_Code erc.DataApprovalCode `json:"status_code"`
}
type ReadListDto struct {
@@ -19,9 +22,10 @@ type ReadListDto struct {
}
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Unit_Id *uint `json:"unit-id"`
Doctor_Id *uint `json:"doctor-id"`
Encounter_Id *uint `json:"encounter-id"`
Unit_Code *uint `json:"unit-code"`
Doctor_Code *uint `json:"doctor-code"`
Status_Code erc.DataApprovalCode `json:"status-code"`
}
type ReadDetailDto struct {
@@ -46,20 +50,22 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Unit_Id *uint16 `json:"unit_id"`
Unit *eu.Unit `json:"unit,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Encounter_Id *uint `json:"encounter_id"`
Unit_Code *string `json:"unit_id"`
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"`
}
func (d InternalReference) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Unit_Id: d.Unit_Id,
Unit_Code: d.Unit_Code,
Unit: d.Unit,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Status_Code: d.Status_Code,
}
resp.Main = d.Main
return resp
@@ -11,9 +11,9 @@ import (
type InternalReference struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Unit_Id *uint16 `json:"unit_id"`
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
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"`
}
@@ -8,7 +8,7 @@ import (
type CreateDto struct {
MaterialOrder_Id *uint `json:"materialOrder_id"`
Material_Id *uint `json:"material_id"`
Material_Code *string `json:"material_code"`
Count *uint16 `json:"count"`
}
@@ -20,7 +20,7 @@ type ReadListDto struct {
type FilterDto struct {
MaterialOrder_Id *uint `json:"materialOrder-id"`
Material_Id *uint `json:"material-id"`
Material_Code *string `json:"material-code"`
Count *uint16 `json:"count"`
}
type ReadDetailDto struct {
@@ -46,7 +46,7 @@ type ResponseDto struct {
ecore.Main
MaterialOrder_Id *uint `json:"materialOrder_id"`
MaterialOrder *emo.MaterialOrder `json:"materialOrder,omitempty"`
Material_Id *uint `json:"material_id"`
Material_Code *string `json:"material_code"`
Material *em.Material `json:"material,omitempty"`
Count *uint16 `json:"count"`
}
@@ -55,7 +55,7 @@ func (d MaterialOrderItem) ToResponse() ResponseDto {
resp := ResponseDto{
MaterialOrder_Id: d.MaterialOrder_Id,
MaterialOrder: d.MaterialOrder,
Material_Id: d.Material_Id,
Material_Code: d.Material_Code,
Material: d.Material,
Count: d.Count,
}
@@ -10,7 +10,7 @@ type MaterialOrderItem struct {
ecore.Main // adjust this according to the needs
MaterialOrder_Id *uint `json:"materialOrder_id"`
MaterialOrder *emo.MaterialOrder `json:"materialOrder,omitempty" gorm:"foreignKey:MaterialOrder_Id;references:Id"`
Material_Id *uint `json:"material_id"`
Material *em.Material `json:"material,omitempty" gorm:"foreignKey:Material_Id;references:Id"`
Material_Code *string `json:"material_code"`
Material *em.Material `json:"material,omitempty" gorm:"foreignKey:Material_Code;references:Code"`
Count *uint16 `json:"count"`
}
@@ -18,7 +18,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataStatusCode `json:"status_code"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
pa.AuthInfo
}
@@ -56,7 +56,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -65,7 +65,7 @@ func (d MaterialOrder) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Status_Code: d.Status_Code,
}
@@ -12,8 +12,8 @@ type MaterialOrder struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
@@ -21,6 +21,6 @@ func (d MaterialOrder) IsCompleted() bool {
return d.Status_Code == erc.DSCDone
}
func (d MaterialOrder) IsSameDoctor(doctor_id *uint) bool {
return d.Doctor_Id == doctor_id
func (d MaterialOrder) IsSameDoctor(doctor_code *string) bool {
return d.Doctor_Code == doctor_code
}
@@ -22,7 +22,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
Number uint8 `json:"number"`
@@ -42,7 +42,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Status_Code erc.DataStatusCode `json:"status-code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor-id"`
Doctor_Code *string `json:"doctor-code"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
Number uint8 `json:"number"`
@@ -79,7 +79,7 @@ type ResponseDto struct {
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
@@ -93,7 +93,7 @@ func (d McuOrder) ToResponse() ResponseDto {
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Status_Code: d.Status_Code,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
SpecimenPickTime: d.SpecimenPickTime,
ExaminationDate: d.ExaminationDate,
@@ -15,8 +15,8 @@ type McuOrder struct {
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Status_Code erc.DataStatusCode `json:"status_code" gorm:"not null;size:10"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
SpecimenPickTime *time.Time `json:"specimenPickTime"`
ExaminationDate *time.Time `json:"examinationDate"`
Number uint8 `json:"number"`
@@ -29,6 +29,6 @@ func (d McuOrder) IsCompleted() bool {
return d.Status_Code == erc.DSCDone
}
func (d McuOrder) IsSameDoctor(doctor_id *uint) bool {
return d.Doctor_Id == doctor_id
func (d McuOrder) IsSameDoctor(doctor_code *string) bool {
return d.Doctor_Code == doctor_code
}
+8 -7
View File
@@ -6,10 +6,10 @@ import (
)
type CreateDto struct {
Code string `json:"code" validate:"maxLength=20"`
Code *string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
McuSrcCategory_Code *string `json:"mcuSrcCategory_code" validate:"maxLength=20"`
Item_Id *uint `json:"item_id"`
Item_Code *string `json:"item_code"`
}
type ReadListDto struct {
@@ -27,17 +27,18 @@ type FilterDto struct {
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
}
type UpdateDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
}
type MetaDto struct {
@@ -51,7 +52,7 @@ type ResponseDto struct {
Code string `json:"code"`
Name string `json:"name"`
McuSrcCategory_Code *string `json:"mcuSrcCategory_code"`
Item_Id *uint `json:"item_id"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty"`
}
@@ -60,7 +61,7 @@ func (d McuSrc) ToResponse() ResponseDto {
Code: d.Code,
Name: d.Name,
McuSrcCategory_Code: d.McuSrcCategory_Code,
Item_Id: d.Item_Id,
Item_Code: d.Item_Code,
Item: d.Item,
}
resp.Main = d.Main
@@ -8,10 +8,10 @@ import (
type McuSrc struct {
ecore.Main // adjust this according to the needs
Code string `json:"code" gorm:"unique;size:20"`
Code string `json:"code" gorm:"unique;size:20;not null"`
Name string `json:"name" gorm:"size:50"`
McuSrcCategory_Code *string `json:"mcuSrcCategory_code" gorm:"size:20"`
McuSrcCategory *emsc.McuSrcCategory `json:"mcuSrcCategory,omitempty" gorm:"foreignKey:McuSrcCategory_Code;references:Code"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"`
}
@@ -7,10 +7,10 @@ import (
)
type CreateDto struct {
Code string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
McuSrc_Id *uint `json:"mcuSrc_id"`
Item_Id *uint `json:"item_id"`
Code *string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
McuSrc_Code *string `json:"mcuSrc_code"`
Item_Code *string `json:"item_code"`
}
type ReadListDto struct {
@@ -21,24 +21,25 @@ type ReadListDto struct {
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
Code *string `json:"code"`
Name *string `json:"name"`
CheckupCategory_Code *string `json:"checkupCategory-code"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
}
type UpdateDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
}
type MetaDto struct {
@@ -49,22 +50,22 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Code string `json:"code"`
Name string `json:"name"`
McuSrc_Id *uint `json:"mcuSrc_id"`
McuSrc *ems.McuSrc `json:"mcuSrc,omitempty"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty"`
Code string `json:"code"`
Name string `json:"name"`
McuSrc_Code *string `json:"mcuSrc_code"`
McuSrc *ems.McuSrc `json:"mcuSrc,omitempty"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty"`
}
func (d McuSubSrc) ToResponse() ResponseDto {
resp := ResponseDto{
Code: d.Code,
Name: d.Name,
McuSrc_Id: d.McuSrc_Id,
McuSrc: d.McuSrc,
Item_Id: d.Item_Id,
Item: d.Item,
Code: d.Code,
Name: d.Name,
McuSrc_Code: d.McuSrc_Code,
McuSrc: d.McuSrc,
Item_Code: d.Item_Code,
Item: d.Item,
}
resp.Main = d.Main
return resp
@@ -7,11 +7,11 @@ import (
)
type McuSubSrc struct {
ecore.Main // adjust this according to the needs
Code string `json:"code" gorm:"unique;size:20"`
Name string `json:"name" gorm:"size:50"`
McuSrc_Id *uint `json:"mcuSrc_id"`
McuSrc *ems.McuSrc `json:"mcuSrc,omitempty" gorm:"foreignKey:McuSrc_Id;references:Id"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
ecore.Main // adjust this according to the needs
Code string `json:"code" gorm:"unique;size:20"`
Name string `json:"name" gorm:"size:50"`
McuSrc_Code *string `json:"mcuSrc_code"`
McuSrc *ems.McuSrc `json:"mcuSrc,omitempty" gorm:"foreignKey:McuSrc_Code;references:Code"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"`
}
@@ -8,9 +8,9 @@ import (
)
type CreateDto struct {
MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"`
ProcedureSrc_Id *uint `json:"procedureSrc_id"`
Item_Id *uint `json:"item_id"`
MedicalActionSrc_Code *string `json:"medicalActionSrc_code"`
ProcedureSrc_Code *string `json:"procedureSrc_code"`
Item_Code *string `json:"item_code"`
}
type ReadListDto struct {
@@ -20,9 +20,9 @@ type ReadListDto struct {
}
type FilterDto struct {
MedicalActionSrc_Id *uint `json:"medicalActionSrc-id"`
ProcedureSrc_Id *uint `json:"procedureSrc-id"`
Item_Id *uint `json:"item-id"`
MedicalActionSrc_Code *string `json:"medicalActionSrc-code"`
ProcedureSrc_Code *string `json:"procedureSrc-code"`
Item_Code *string `json:"item-code"`
}
type ReadDetailDto struct {
@@ -46,22 +46,22 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"`
MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty"`
ProcedureSrc_Id *uint `json:"procedureSrc_id"`
ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty"`
MedicalActionSrc_Code *string `json:"medicalActionSrc_code"`
MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty"`
ProcedureSrc_Code *string `json:"procedureSrc_code"`
ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty"`
}
func (d MedicalActionSrcItem) ToResponse() ResponseDto {
resp := ResponseDto{
MedicalActionSrc_Id: d.MedicalActionSrc_Id,
MedicalActionSrc: d.MedicalActionSrc,
ProcedureSrc_Id: d.ProcedureSrc_Id,
ProcedureSrc: d.ProcedureSrc,
Item_Id: d.Item_Id,
Item: d.Item,
MedicalActionSrc_Code: d.MedicalActionSrc_Code,
MedicalActionSrc: d.MedicalActionSrc,
ProcedureSrc_Code: d.ProcedureSrc_Code,
ProcedureSrc: d.ProcedureSrc,
Item_Code: d.Item_Code,
Item: d.Item,
}
resp.Main = d.Main
return resp
@@ -8,11 +8,11 @@ import (
)
type MedicalActionSrcItem struct {
ecore.Main // adjust this according to the needs
MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"`
MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty" gorm:"foreignKey:MedicalActionSrc_Id;references:Id"`
ProcedureSrc_Id *uint `json:"procedureSrc_id"`
ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty" gorm:"foreignKey:ProcedureSrc_Id;references:Id"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
ecore.Main // adjust this according to the needs
MedicalActionSrc_Code *string `json:"medicalActionSrc_code"`
MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty" gorm:"foreignKey:MedicalActionSrc_Code;references:Code"`
ProcedureSrc_Code *string `json:"procedureSrc_code"`
ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty" gorm:"foreignKey:ProcedureSrc_Code;references:Code"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"`
}
@@ -6,10 +6,10 @@ import (
)
type CreateDto struct {
Code string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
Type_Code string `json:"type_code" validate:"maxLength=20"`
Item_Id *uint `json:"item_id"`
Code *string `json:"code" validate:"maxLength=20"`
Name string `json:"name" validate:"maxLength=50"`
Type_Code string `json:"type_code" validate:"maxLength=20"`
Item_Code *string `json:"item_code"`
}
type ReadListDto struct {
@@ -20,25 +20,26 @@ type ReadListDto struct {
}
type FilterDto struct {
Code string `json:"code"`
Name string `json:"name"`
Type_Code string `json:"type_code"`
Item_Id *uint `json:"item-id"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
Code *string `json:"code"`
Name string `json:"name"`
Type_Code string `json:"type_code"`
Item_Code *string `json:"item-code"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Code string `json:"code"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
}
type UpdateDto struct {
Id uint `json:"id"`
Id *uint `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint `json:"id"`
Id *uint `json:"id"`
Code *string `json:"code"`
}
type MetaDto struct {
@@ -52,7 +53,7 @@ type ResponseDto struct {
Code string `json:"code"`
Name string `json:"name"`
Type_Code string `json:"type_code"`
Item_Id *uint `json:"item_id"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty"`
}
@@ -61,7 +62,7 @@ func (d MedicalActionSrc) ToResponse() ResponseDto {
Code: d.Code,
Name: d.Name,
Type_Code: d.Type_Code,
Item_Id: d.Item_Id,
Item_Code: d.Item_Code,
Item: d.Item,
}
resp.Main = d.Main
@@ -10,6 +10,6 @@ type MedicalActionSrc struct {
Code string `json:"code" gorm:"unique;size:20"`
Name string `json:"name" gorm:"size:50"`
Type_Code string `json:"type_code" gorm:"size:20"`
Item_Id *uint `json:"item_id"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"`
Item_Code *string `json:"item_code"`
Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"`
}
+4 -3
View File
@@ -29,19 +29,20 @@ type FilterDto struct {
Infra_Code *string `json:"infra-code"`
}
type ReadDetailDto struct {
Id uint16 `json:"id"`
Id *uint16 `json:"id"`
Code *string `json:"code"`
Employee_Id *uint `json:"employee_id"`
IHS_Number *string `json:"ihs_number"`
}
type UpdateDto struct {
Id uint `json:"id"`
Id *uint `json:"id"`
CreateDto
}
type DeleteDto struct {
Id uint `json:"id"`
Id *uint `json:"id"`
Code *string `json:"code"`
}
type MetaDto struct {
+2 -2
View File
@@ -12,7 +12,7 @@ import (
epr "simrs-vx/internal/domain/main-entities/person-relative"
erc "simrs-vx/internal/domain/references/common"
ere "simrs-vx/internal/domain/references/encounter"
eru "simrs-vx/internal/domain/references/upload"
pa "simrs-vx/internal/lib/auth"
)
@@ -68,7 +68,7 @@ type SearchDto struct {
type UploadDto struct {
Id uint `json:"-"`
Code ere.UploadCode `json:"-"`
Code eru.UploadCode `json:"-"`
File multipart.File `json:"-"`
FileHeader *multipart.FileHeader `json:"-"`
Filename string `json:"-"`
@@ -6,11 +6,11 @@ import (
)
type CreateDto struct {
Doctor_Id *uint `json:"doctor_id"`
Unit_Code *string `json:"unit_code"`
Day_Code *erc.DayCode `json:"day_code"`
StartTime *string `json:"startTime" validate:"maxLength=5"`
EndTime *string `json:"endTime" validate:"maxLength=5"`
Doctor_Code *string `json:"doctor_code"`
Unit_Code *string `json:"unit_code"`
Day_Code *erc.DayCode `json:"day_code"`
StartTime *string `json:"startTime" validate:"maxLength=5"`
EndTime *string `json:"endTime" validate:"maxLength=5"`
}
type ReadListDto struct {
@@ -20,11 +20,11 @@ type ReadListDto struct {
}
type FilterDto struct {
Doctor_Id *uint `json:"doctor-id"`
Unit_Code *string `json:"unit-code"`
Day_Code *erc.DayCode `json:"day-code"`
StartTime *string `json:"startTime"`
EndTime *string `json:"endTime"`
Doctor_Code *string `json:"doctor-code"`
Unit_Code *string `json:"unit-code"`
Day_Code *erc.DayCode `json:"day-code"`
StartTime *string `json:"startTime"`
EndTime *string `json:"endTime"`
}
type ReadDetailDto struct {
@@ -48,20 +48,20 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Doctor_Id *uint `json:"doctor_id"`
Unit_Code *string `json:"unit_code"`
Day_Code *erc.DayCode `json:"day_code"`
StartTime *string `json:"startTime"`
EndTime *string `json:"endTime"`
Doctor_Code *string `json:"doctor_code"`
Unit_Code *string `json:"unit_code"`
Day_Code *erc.DayCode `json:"day_code"`
StartTime *string `json:"startTime"`
EndTime *string `json:"endTime"`
}
func (d PracticeSchedule) ToResponse() ResponseDto {
resp := ResponseDto{
Doctor_Id: d.Doctor_Id,
Unit_Code: d.Unit_Code,
Day_Code: d.Day_Code,
StartTime: d.StartTime,
EndTime: d.EndTime,
Doctor_Code: d.Doctor_Code,
Unit_Code: d.Unit_Code,
Day_Code: d.Day_Code,
StartTime: d.StartTime,
EndTime: d.EndTime,
}
resp.Main = d.Main
return resp
@@ -8,12 +8,12 @@ import (
)
type PracticeSchedule struct {
ecore.Main // adjust this according to the needs
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Unit_Code *string `json:"unit_code"`
Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
Day_Code *erc.DayCode `json:"day_code"`
StartTime *string `json:"startTime" gorm:"size:5"`
EndTime *string `json:"endTime" gorm:"size:5"`
ecore.Main // adjust this according to the needs
Doctor_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"`
}
+23 -10
View File
@@ -1,14 +1,20 @@
package rehab
import (
erc "simrs-vx/internal/domain/references/common"
ere "simrs-vx/internal/domain/references/encounter"
ecore "simrs-vx/internal/domain/base-entities/core"
ed "simrs-vx/internal/domain/main-entities/doctor"
"time"
)
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Doctor_Id *uint `json:"doctor_id"`
AllocatedVisitCount *int `json:"allocatedVisitCount"`
Encounter_Id *uint `json:"encounter_id"`
Parent_Encounter_Id *uint `json:"parent_encounter_id"`
AllocatedVisitCount *int `json:"allocatedVisitCount"`
ExpiredAt *time.Time `json:"expiredAt"`
VisitMode_Code ere.VisitModeCode `json:"visitMode_code"`
Status_Code erc.DataStatusCode `json:"status_code"`
}
type ReadListDto struct {
@@ -18,8 +24,9 @@ type ReadListDto struct {
}
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Doctor_Id *uint `json:"doctor-id"`
Encounter_Id *uint `json:"encounter-id"`
Parent_Encounter_Id *uint `json:"parent-encounter-id"`
VisitMode_Code ere.VisitModeCode `json:"visitMode-code"`
}
type ReadDetailDto struct {
@@ -44,16 +51,22 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
AllocatedVisitCount *int `json:"allocatedVisitCount"`
Encounter_Id *uint `json:"encounter_id"`
Parent_Encounter_Id *uint `json:"parent_encounter_id"`
AllocatedVisitCount *int `json:"allocatedVisitCount"`
ExpiredAt *time.Time `json:"expiredAt"`
VisitMode_Code *ere.VisitModeCode `json:"visitMode_code"`
Status_Code *erc.DataStatusCode `json:"status_code"`
}
func (d Rehab) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Parent_Encounter_Id: d.Parent_Encounter_Id,
AllocatedVisitCount: d.AllocatedVisitCount,
ExpiredAt: d.ExpiredAt,
VisitMode_Code: d.VisitMode_Code,
Status_Code: d.Status_Code,
}
resp.Main = d.Main
return resp
@@ -8,7 +8,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
}
@@ -22,7 +22,7 @@ type ReadListDto struct {
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Doctor_Id *uint `json:"doctor-id"`
Doctor_Code *string `json:"doctor-code"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
}
@@ -50,7 +50,7 @@ type MetaDto struct {
type ResponseDto struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
@@ -59,7 +59,7 @@ type ResponseDto struct {
func (d ResponsibleDoctorHist) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
StartedAt: d.StartedAt,
FinishedAt: d.FinishedAt,
@@ -9,8 +9,8 @@ import (
type ResponsibleDoctorHist struct {
ecore.Main // adjust this according to the needs
Encounter_Id *uint `json:"encounter_id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
StartedAt *time.Time `json:"startedAt"`
FinishedAt *time.Time `json:"finishedAt"`
}
@@ -9,7 +9,7 @@ import (
type CreateDto struct {
Encounter_Id *uint `json:"encounter_id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Anamnesis *string `json:"anamnesis" validate:"maxLength=2048"`
MedicalDiagnoses *string `json:"medicalDiagnoses"`
FunctionDiagnoses *string `json:"functionDiagnoses"`
@@ -31,8 +31,8 @@ type ReadListDto struct {
}
type FilterDto struct {
Encounter_Id *uint `json:"encounter-id"`
Doctor_Id *uint `json:"doctor-id"`
Encounter_Id *uint `json:"encounter-id"`
Doctor_Code *string `json:"doctor-code"`
}
type ReadDetailDto struct {
@@ -59,7 +59,7 @@ type ResponseDto struct {
ecore.Main
Encounter_Id *uint `json:"encounter_id"`
Encounter *ee.Encounter `json:"encounter,omitempty"`
Doctor_Id *uint `json:"doctor_id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty"`
Anamnesis *string `json:"anamnesis"`
MedicalDiagnoses *string `json:"medicalDiagnoses"`
@@ -79,7 +79,7 @@ func (d TherapyProtocol) ToResponse() ResponseDto {
resp := ResponseDto{
Encounter_Id: d.Encounter_Id,
Encounter: d.Encounter,
Doctor_Id: d.Doctor_Id,
Doctor_Code: d.Doctor_Code,
Doctor: d.Doctor,
Anamnesis: d.Anamnesis,
MedicalDiagnoses: d.MedicalDiagnoses,
@@ -13,8 +13,8 @@ type TherapyProtocol struct {
Encounter_Id *uint `json:"encounter_id" gorm:"not null"`
Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
Doctor_Id *uint `json:"doctor_id"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Id;references:Id"`
Doctor_Code *string `json:"doctor_code"`
Doctor *ed.Doctor `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
Anamnesis *string `json:"anamnesis" gorm:"size:2048"`
MedicalDiagnoses *string `json:"medicalDiagnoses"`
@@ -9,7 +9,7 @@ type (
InstructionCode string
HeadToToeCode string
McuUrgencyLevelCode string
McuScopeCode string
McuScopeCode string
SoapiTypeCode string
MedicalActionTypeCode string
VehicleTypeCode string
@@ -10,7 +10,6 @@ type (
OutpatientClassCode string
AmbulatoryClassCode string
InpatientClassCode string
UploadCode string
ChemoClassCode string
AmbulanceFacilityCode string
AmbulanceNeedsCode string
@@ -78,12 +77,6 @@ const (
ICCHCU InpatientClassCode = "hcu" // HCU
ICCVK InpatientClassCode = "vk" // Verlos kamer
UCPRN UploadCode = "person-resident-number" // Person Resident Number
UCPDL UploadCode = "person-driver-license" // Person Driver License
UCPP UploadCode = "person-passport" // Person Passport
UCPFC UploadCode = "person-family-card" // Person Family Card
UCMIR UploadCode = "mcu-item-result" // Mcu Item Result
CCCAdm ChemoClassCode = "adm" // Administrasi
CCCAct ChemoClassCode = "act" // Tindakan
@@ -125,12 +118,3 @@ func (ec EncounterClassCode) Code() string {
return "UNKNOWN"
}
}
func IsValidUploadCode(code UploadCode) bool {
switch UploadCode(code) {
case UCPRN, UCPDL, UCPP, UCPFC, UCMIR:
return true
default:
return false
}
}
@@ -0,0 +1,37 @@
package upload
type (
UploadCode string
EntityTypeCode string
)
const (
UCPRN UploadCode = "person-resident-number" // Person Resident Number
UCPDL UploadCode = "person-driver-license" // Person Driver License
UCPP UploadCode = "person-passport" // Person Passport
UCPFC UploadCode = "person-family-card" // Person Family Card
UCMIR UploadCode = "mcu-item-result" // Mcu Item Result
UCSEP UploadCode = "vclaim-sep" // SEP
UCSIPP UploadCode = "vclaim-sipp" // SIPP
ETCPerson EntityTypeCode = "person"
ETCEncounter EntityTypeCode = "encounter"
)
var validUploadCodesByEntity = map[EntityTypeCode][]UploadCode{
ETCPerson: {
UCPRN, UCPDL, UCPP, UCPFC, UCMIR,
},
ETCEncounter: {
UCSEP, UCSIPP,
},
}
func IsValidUploadCode(entity EntityTypeCode, code UploadCode) bool {
for _, c := range validUploadCodesByEntity[entity] {
if c == code {
return true
}
}
return false
}
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "code", r.PathValue("code"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "code", r.PathValue("code"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
dto.Code = &code
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "code", r.PathValue("code"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.DeleteDto{}
dto.Id = uint(id)
dto.Code = &code
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -3,18 +3,17 @@ package encounter
import (
"net/http"
pa "simrs-vx/internal/lib/auth"
d "github.com/karincake/dodol"
rw "github.com/karincake/risoles"
sf "github.com/karincake/semprit"
// ua "github.com/karincake/tumpeng/auth/svc"
erc "simrs-vx/internal/domain/references/common"
e "simrs-vx/internal/domain/main-entities/encounter"
u "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
pa "simrs-vx/internal/lib/auth"
d "github.com/karincake/dodol"
)
type myBase struct{}
@@ -31,7 +30,13 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
if valid := validateRequestCreate(w, dto); !valid {
// validate SubClass
if err := verifyClassCode(dto); err != nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: err.Error(),
})
return
}
@@ -192,3 +197,40 @@ func (obj myBase) Skip(w http.ResponseWriter, r *http.Request) {
res, err := u.UpdateStatusCode(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) RequestSwitchUnit(w http.ResponseWriter, r *http.Request) {
dto := e.SwitchUnitDto{}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
// validate request body
if valid := validateRequestSwitchUnit(w, dto); !valid {
return
}
dto.Id = uint(id)
res, err := u.RequestSwitchUnit(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) ApproveSwitchUnit(w http.ResponseWriter, r *http.Request) {
dto := e.ApproveUnitDto{}
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
return
}
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
res, err := u.ApproveSwitchUnit(dto)
rw.DataResponse(w, res, err)
}
@@ -1,9 +1,14 @@
package encounter
import (
"errors"
"fmt"
"net/http"
e "simrs-vx/internal/domain/main-entities/encounter"
ere "simrs-vx/internal/domain/references/encounter"
ua "simrs-vx/internal/use-case/main-use-case/ambulatory"
ue "simrs-vx/internal/use-case/main-use-case/emergency"
ui "simrs-vx/internal/use-case/main-use-case/inpatient"
d "github.com/karincake/dodol"
rw "github.com/karincake/risoles"
@@ -11,6 +16,25 @@ import (
const dataValidationFail = "data-validation-fail"
func verifyClassCode(input e.CreateDto) (err error) {
switch input.Class_Code {
case ere.ECAmbulatory:
_, err = ua.CheckClassCode(input.SubClass_Code)
case ere.ECEmergency:
_, err = ue.CheckClassCode(input.SubClass_Code)
case ere.ECInpatient:
_, err = ui.CheckClassCode(input.SubClass_Code)
default:
return errors.New("invalid encounter class code")
}
if err != nil {
return
}
return nil
}
func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid bool) {
if *i.Discharge_Method_Code == ere.DMCDeath && i.DeathCause == nil {
rw.DataResponse(w, nil, d.FieldError{
@@ -19,15 +43,14 @@ func validateRequestCheckout(w http.ResponseWriter, i e.DischargeDto) (valid boo
})
return
}
return true
}
func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool) {
if i.Responsible_Doctor_Id == nil {
if i.Responsible_Doctor_Code == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "responsible_doctor_id required",
Message: "responsible_doctor_code required",
})
return
}
@@ -35,18 +58,30 @@ func validateRequestCheckIn(w http.ResponseWriter, i e.CheckinDto) (valid bool)
return true
}
func validateRequestCreate(w http.ResponseWriter, i e.CreateDto) (valid bool) {
switch {
case i.Class_Code == ere.ECAmbulatory:
// field allocatedVisitCount required if ambulatory visitMode_Code is adm
if ere.AmbulatoryClassCode(*i.SubClass_Code) == ere.ACCRehab && *i.VisitMode_Code == ere.VMCAdm {
if *i.AllocatedVisitCount == 0 {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "allocatedVisitCount required",
})
return
}
func validateRequestSwitchUnit(w http.ResponseWriter, i e.SwitchUnitDto) (valid bool) {
if i.InternalReferences == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: fmt.Sprintf("internalReferences required"),
})
return
}
for _, v := range *i.InternalReferences {
if v.Unit_Code == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "internalReferences.unit_code required",
})
return
}
if v.Doctor_Code == nil {
rw.DataResponse(w, nil, d.FieldError{
Code: dataValidationFail,
Message: "internalReferences.doctor_code required",
})
return
}
}
+16 -14
View File
@@ -145,17 +145,19 @@ func SetRoutes() http.Handler {
hc.RegCrud(r, "/v1/material-order-item", materialorderitem.O)
hk.GroupRoutes("/v1/encounter", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": encounter.O.GetList,
"GET /{id}": encounter.O.GetDetail,
"POST /": encounter.O.Create,
"PATCH /{id}": encounter.O.Update,
"DELETE /{id}": encounter.O.Delete,
"PATCH /{id}/check-out": encounter.O.CheckOut,
"PATCH /{id}/check-in": encounter.O.CheckIn,
"PATCH /{id}/proccess": encounter.O.Process,
"PATCH /{id}/cancel": encounter.O.Cancel,
"PATCH /{id}/reject": encounter.O.Reject,
"PATCH /{id}/skip": encounter.O.Skip,
"GET /": encounter.O.GetList,
"GET /{id}": encounter.O.GetDetail,
"POST /": encounter.O.Create,
"PATCH /{id}": encounter.O.Update,
"DELETE /{id}": encounter.O.Delete,
"PATCH /{id}/check-out": encounter.O.CheckOut,
"PATCH /{id}/check-in": encounter.O.CheckIn,
"PATCH /{id}/proccess": encounter.O.Process,
"PATCH /{id}/cancel": encounter.O.Cancel,
"PATCH /{id}/reject": encounter.O.Reject,
"PATCH /{id}/skip": encounter.O.Skip,
"PATCH /{id}/req-switch-unit": encounter.O.RequestSwitchUnit,
"PATCH /{id}/approve-switch-unit": encounter.O.ApproveSwitchUnit,
})
hk.GroupRoutes("/v1/mcu-order", r, auth.GuardMW, hk.MapHandlerFunc{
"GET /": mcuorder.O.GetList,
@@ -314,17 +316,17 @@ func SetRoutes() http.Handler {
hc.RegCrud(r, "/v1/medicine-group", medicinegroup.O)
hc.RegCrud(r, "/v1/medicine-method", medicinemethod.O)
hc.RegCrud(r, "/v1/mcu-src-category", mcusrccategory.O)
hc.RegCrud(r, "/v1/mcu-src", mcusrc.O)
hc.RegCrudByCode(r, "/v1/mcu-src", mcusrc.O)
hc.RegCrud(r, "/v1/ethnic", ethnic.O)
hc.RegCrud(r, "/v1/insurance-company", insurancecompany.O)
hc.RegCrudByCode(r, "/v1/medicine", medicine.O)
hc.RegCrudByCode(r, "/v1/device", device.O)
hc.RegCrudByCode(r, "/v1/material", material.O)
hc.RegCrud(r, "/v1/doctor-fee", doctorfee.O)
hc.RegCrud(r, "/v1/medical-action-src", medicalactionsrc.O)
hc.RegCrudByCode(r, "/v1/medical-action-src", medicalactionsrc.O)
hc.RegCrud(r, "/v1/medical-action-src-item", medicalactionsrcitem.O)
hc.RegCrud(r, "/v1/language", language.O)
hc.RegCrud(r, "/v1/mcu-sub-src", mcusubsrc.O)
hc.RegCrudByCode(r, "/v1/mcu-sub-src", mcusubsrc.O)
hc.RegCrud(r, "/v1/vehicle", vehicle.O)
hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O)
hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O)
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.DeleteDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.DeleteDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
dto.Code = &code
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.DeleteDto{}
dto.Id = uint(id)
dto.Code = &code
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
}
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "code", r.PathValue("code"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.ReadDetailDto{}
dto.Id = uint16(id)
dto.Code = &code
res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "code", r.PathValue("code"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return
}
dto.Id = uint(id)
dto.Code = &code
res, err := u.Update(dto)
rw.DataResponse(w, res, err)
}
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "code", r.PathValue("code"))
if id <= 0 {
code := rw.ValidateString(w, "code", r.PathValue("code"))
if code == "" {
return
}
dto := e.DeleteDto{}
dto.Id = uint(id)
dto.Code = &code
res, err := u.Delete(dto)
rw.DataResponse(w, res, err)
}
@@ -29,6 +29,7 @@ import (
employee "simrs-vx/internal/domain/main-entities/employee"
encounter "simrs-vx/internal/domain/main-entities/encounter"
ethnic "simrs-vx/internal/domain/main-entities/ethnic"
fileattachemnt "simrs-vx/internal/domain/main-entities/file-attachment"
generalconsent "simrs-vx/internal/domain/main-entities/general-consent"
infra "simrs-vx/internal/domain/main-entities/infra"
inpatient "simrs-vx/internal/domain/main-entities/inpatient"
@@ -207,5 +208,6 @@ func getMainEntities() []any {
&controlletter.ControlLetter{},
&rehab.Rehab{},
&chemoprotocol.ChemoProtocol{},
&fileattachemnt.FileAttachment{},
}
}
@@ -313,12 +313,12 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err
data.User_ContractPosition_code = checkStrClaims(claims, "contractPosition_code")
data.Employee_Position_Code = checkStrPtrClaims(claims, "employee_position_code")
data.Doctor_Code = checkStrPtrClaims(claims, "doctor_string")
data.Nurse_Code = checkStrPtrClaims(claims, "nurse_string")
data.Midwife_Code = checkStrPtrClaims(claims, "midwife_string")
data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_string")
data.Laborant_Code = checkStrPtrClaims(claims, "laborant_string")
data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_string")
data.Doctor_Code = checkStrPtrClaims(claims, "doctor_code")
data.Nurse_Code = checkStrPtrClaims(claims, "nurse_code")
data.Midwife_Code = checkStrPtrClaims(claims, "midwife_code")
data.Nutritionist_Code = checkStrPtrClaims(claims, "nutritionist_code")
data.Laborant_Code = checkStrPtrClaims(claims, "laborant_code")
data.Pharmachist_Code = checkStrPtrClaims(claims, "pharmachist_code")
data.Intern_Position_Code = checkStrPtrClaims(claims, "intern_position_code")
data.Employee_Id = checkUntPtrClaims(claims, "employee_id")
return
@@ -19,5 +19,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Chemo) {
data.Encounter_Id = inputSrc.Encounter_Id
data.Status_Code = inputSrc.Status_Code
data.SrcUnit_Id = inputSrc.SrcUnit_Id
data.SrcUnit_Code = inputSrc.SrcUnit_Code
}
@@ -7,8 +7,6 @@ import (
e "simrs-vx/internal/domain/main-entities/consultation"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
dg "github.com/karincake/apem/db-gorm-pg"
d "github.com/karincake/dodol"
@@ -314,12 +312,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if data.DstDoctor_Id != nil && data.DstDoctor_Id != doctor_id {
if data.DstDoctor_Code != nil && data.DstDoctor_Code != input.AuthInfo.Doctor_Code {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-handled-mismatch",
@@ -329,7 +322,7 @@ func Reply(input e.ReplyDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
data.DstDoctor_Id = doctor_id
data.DstDoctor_Code = input.AuthInfo.Doctor_Code
data.Solution = input.Solution
data.RepliedAt = pu.GetTimeNow()
err = tx.Save(&data).Error
@@ -20,5 +20,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Consultation) {
data.Encounter_Id = inputSrc.Encounter_Id
data.Date = inputSrc.Date
data.Problem = inputSrc.Problem
data.DstUnit_Id = inputSrc.DstUnit_Id
data.DstUnit_Code = inputSrc.DstUnit_Code
}
@@ -18,9 +18,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.ControlLetter) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Unit_Id = inputSrc.Unit_Id
data.Specialist_Id = inputSrc.Specialist_Id
data.Subspecialist_Id = inputSrc.Subspecialist_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Unit_Code = inputSrc.Unit_Code
data.Specialist_Code = inputSrc.Specialist_Code
data.Subspecialist_Code = inputSrc.Subspecialist_Code
data.Doctor_Code = inputSrc.Doctor_Code
data.Date = inputSrc.Date
}
@@ -18,6 +18,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DeviceOrderItem) {
}
data.DeviceOrder_Id = inputSrc.DeviceOrder_Id
data.Device_Id = inputSrc.Device_Id
data.Device_Code = inputSrc.Device_Code
data.Count = inputSrc.Count
}
@@ -6,7 +6,6 @@ import (
e "simrs-vx/internal/domain/main-entities/device-order"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
@@ -60,11 +59,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if resData, err := CreateData(input, &event, tx); err != nil {
return err
@@ -236,11 +231,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if !data.IsSameDoctor(doctor_id) {
if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "auth-forbidden",
@@ -250,7 +241,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if err := UpdateData(input, data, &event, tx); err != nil {
return err
@@ -21,5 +21,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.DeviceOrder) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Doctor_Code = inputSrc.Doctor_Code
}
@@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
}
func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.Doctor
var err error
@@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
}
func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.Doctor
var err error
@@ -84,7 +84,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
if input.Employee_Id != nil {
tx = tx.Where("\"Employee_Id\" = ?", *input.Employee_Id)
}
if input.Id > 0 {
if input.Id != nil {
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx.First(&data).Error; err != nil {
+242 -161
View File
@@ -2,7 +2,7 @@ package encounter
import (
"errors"
authhelper "simrs-vx/internal/lib/auth"
"fmt"
"strconv"
"time"
@@ -17,28 +17,18 @@ import (
ere "simrs-vx/internal/domain/references/encounter"
eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist"
ea "simrs-vx/internal/domain/main-entities/ambulatory"
ec "simrs-vx/internal/domain/main-entities/chemo"
edc "simrs-vx/internal/domain/main-entities/death-cause"
ed "simrs-vx/internal/domain/main-entities/doctor"
ee "simrs-vx/internal/domain/main-entities/emergency"
eem "simrs-vx/internal/domain/main-entities/employee"
e "simrs-vx/internal/domain/main-entities/encounter"
ei "simrs-vx/internal/domain/main-entities/inpatient"
er "simrs-vx/internal/domain/main-entities/rehab"
eir "simrs-vx/internal/domain/main-entities/internal-reference"
erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist"
es "simrs-vx/internal/domain/main-entities/soapi"
uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist"
ua "simrs-vx/internal/use-case/main-use-case/ambulatory"
uc "simrs-vx/internal/use-case/main-use-case/chemo"
udc "simrs-vx/internal/use-case/main-use-case/death-cause"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/emergency"
uem "simrs-vx/internal/use-case/main-use-case/employee"
ui "simrs-vx/internal/use-case/main-use-case/inpatient"
ur "simrs-vx/internal/use-case/main-use-case/rehab"
us "simrs-vx/internal/use-case/main-use-case/soapi"
uir "simrs-vx/internal/use-case/main-use-case/internal-reference"
urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist"
)
const source = "encounter"
@@ -46,8 +36,11 @@ const source = "encounter"
var now = time.Now()
func Create(input e.CreateDto) (*d.Data, error) {
data := e.Encounter{}
createSoapi := []es.CreateDto{}
var (
data e.Encounter
recentSoapiDataforCopy []es.CreateDto
err error
)
event := pl.Event{
Feature: "Create",
@@ -57,51 +50,36 @@ func Create(input e.CreateDto) (*d.Data, error) {
// Start log
pl.SetLogInfo(&event, input, "started", "create")
// validate SubClass
var subCode interface{}
subCode, err := verifyClassCode(input)
if err != nil {
return nil, err
}
// verify whether the allocated visit count has not exceeded the limit
if input.Class_Code == ere.ECAmbulatory && subCode.(ere.AmbulatoryClassCode) == ere.ACCRehab &&
*input.VisitMode_Code == ere.VMCSeries {
dataEncounter, valid, err := verifyAllocatedVisitCount(input, &event)
// validate rehab bpjs
if input.RefTypeCode == ere.RTCBpjs && input.Class_Code == ere.ECAmbulatory && ere.AmbulatoryClassCode(*input.SubClass_Code) == ere.ACCRehab {
// get latest rehab data
recentRehabData, err := getLatestRehabData(input, &event)
if err != nil {
return nil, err
}
if !valid {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "visit-limit-exceeded",
Detail: "Encounter has exceeded the allowed number of visits",
Raw: errors.New("visit count exceeds allowed limit"),
if recentRehabData != nil {
// determine VisitModeCode
input.VisitMode_Code, input.RecentEncounterAdm, err = determineVisitMode(recentRehabData, input, &event)
if err != nil {
return nil, err
}
return nil, pl.SetLogError(&event, input)
} else {
input.VisitMode_Code = ere.VMCAdm
}
// get data soapi
createSoapi, err = getSoapiEncounterAdm(dataEncounter, &event)
if err != nil {
return nil, err
// if visitMode_Code is series, then get data soapi for copy
if input.VisitMode_Code == ere.VMCSeries {
// get data soapi
recentSoapiDataforCopy, err = getSoapiEncounterAdm(*input.RecentEncounterAdm, &event)
if err != nil {
return nil, err
}
}
}
// check if patient is new in the hospital
dataPatient, err := ReadList(e.ReadListDto{
FilterDto: e.FilterDto{Patient_Id: input.Patient_Id},
AuthInfo: authhelper.AuthInfo{User_Id: input.User_Id}})
if err != nil {
return nil, err
}
if list, ok := dataPatient.Data.([]e.ResponseDto); ok {
if len(list) < 1 {
input.NewStatus = true
}
}
input.NewStatus, err = identifyPatientStatus(input)
err = dg.I.Transaction(func(tx *gorm.DB) error {
mwRunner := newMiddlewareRunner(&event, tx)
@@ -122,74 +100,18 @@ func Create(input e.CreateDto) (*d.Data, error) {
return err
} else {
data = *resData
input.Id = data.Id
}
switch input.Class_Code {
case ere.ECAmbulatory:
subCodeAmbulatory := subCode.(ere.AmbulatoryClassCode)
ambCreate := ea.CreateDto{
Encounter_Id: &data.Id,
Class_Code: subCodeAmbulatory,
VisitMode_Code: *input.VisitMode_Code,
}
_, err = ua.CreateData(ambCreate, &event, tx)
if err != nil {
return err
}
if subCodeAmbulatory == ere.ACCChemo {
chemoCreate := ec.CreateDto{
Encounter_Id: &data.Id,
Status_Code: erc.DVCNew,
SrcUnit_Id: input.Unit_Id,
}
_, err = uc.CreateData(chemoCreate, &event, tx)
if err != nil {
return err
}
}
if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCAdm {
// create data rehab
if _, err = ur.CreateData(er.CreateDto{
Encounter_Id: &data.Id,
Doctor_Id: input.Appointment_Doctor_Id,
AllocatedVisitCount: input.AllocatedVisitCount}, &event, tx); err != nil {
return err
}
} else if subCodeAmbulatory == ere.ACCRehab && *input.VisitMode_Code == ere.VMCSeries {
// Insert Soapi
if err = us.CreateBulkData(createSoapi, data.Id, &event, tx); err != nil {
return err
}
}
case ere.ECEmergency:
emerCreate := ee.CreateDto{
Encounter_Id: &data.Id,
Class_Code: subCode.(ere.EmergencyClassCode),
}
_, err = ue.CreateData(emerCreate, &event, tx)
if err != nil {
return err
}
case ere.ECInpatient:
inpCreate := ei.CreateDto{
Encounter_Id: &data.Id,
Class_Code: subCode.(ere.InpatientClassCode),
Infra_Id: input.Infra_Id,
}
_, err = ui.CreateData(inpCreate, &event, tx)
if err != nil {
return err
}
default:
return errors.New("invalid encounter class code")
// insert ambulatory/emergency/inpatient
err = insertdataClassCode(input, recentSoapiDataforCopy, &event, tx)
if err != nil {
return err
}
// insert adm_employee_hist
if _, err := uaeh.CreateData(eaeh.CreateDto{
Encounter_Id: &data.Main.Id,
Encounter_Id: &data.Id,
Employee_Id: data.Adm_Employee_Id,
StartedAt: &now}, &event, tx); err != nil {
return err
@@ -441,7 +363,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
}
func CheckOut(input e.DischargeDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory"}
rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Ambulatory,Rehab"}
var data *e.Encounter
var err error
@@ -471,10 +393,16 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) {
if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) {
// validate if soapi exist
err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-out")
if err != nil {
if err = getSoapiByTypeCode(data, &event, "check-out"); err != nil {
return err
}
if data.Ambulatory.Class_Code == ere.ACCRehab {
// verify and update rehabData if visit count has reached the allowed limit
if err = verifyRehabLimit(data, &event, tx); err != nil {
return err
}
}
} else {
// chemo TBC
if err := checkSoapiByDocExists(data.Id, &event, tx); err != nil {
@@ -497,17 +425,17 @@ func CheckOut(input e.DischargeDto) (*d.Data, error) {
}
// update finishedAt in latest responsible_doctor_hist
if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, StartedAt: &now}, &event, tx); err != nil {
if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil {
return err
}
// update finishedAt in latest adm_employee_hist
if err = updateLatestAdmEmployeeHist(e.CheckinDto{Id: input.Id, StartedAt: &now}, &event, tx); err != nil {
if err = updateLatestAdmEmployeeHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil {
return err
}
// insert data death-cause
if *input.Discharge_Method_Code == ere.DMCDeath {
// insert data death-cause
if _, err = udc.CreateData(edc.CreateDto{Encounter_Id: &input.Id, Value: input.DeathCause}, &event, tx); err != nil {
return err
}
@@ -639,25 +567,25 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) {
// validate if soapi exist
if data.Ambulatory != nil && (data.Ambulatory.Class_Code == ere.ACCReg || data.Ambulatory.Class_Code == ere.ACCRehab) {
err = getSoapiByTypeCode(input.Id, *data.Ambulatory, &event, "check-in")
err = getSoapiByTypeCode(data, &event, "check-in")
if err != nil {
return err
}
}
// Insert responsible_doctor_hist if responsible_doctor_id has changed && update latest history
if data.Responsible_Doctor_Id == nil || *input.Responsible_Doctor_Id != *data.Responsible_Doctor_Id {
// Upsert responsible_doctor_hist if responsible_doctor_id has changed
if data.Responsible_Doctor_Code == nil || *input.Responsible_Doctor_Code != *data.Responsible_Doctor_Code {
// upsert responsibleDoctorHist
if err = upsertResponsibleDoctorHist(erdh.CreateDto{
Encounter_Id: &data.Id,
Doctor_Id: input.Responsible_Doctor_Id,
Doctor_Code: input.Responsible_Doctor_Code,
StartedAt: input.StartedAt,
}, &event, tx); err != nil {
return err
}
}
// Insert adm_employee_hist if adm_employee_id has changed && update latest history
// Upsert adm_employee_hist if adm_employee_id has changed
if input.Adm_Employee_Id != nil && *input.Adm_Employee_Id != *data.Adm_Employee_Id {
// upsert admEmployeeHist
if err = upsertAdmEmployeeHist(eaeh.CreateDto{
@@ -674,15 +602,6 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) {
return err
}
if data.Ambulatory.Class_Code == ere.ACCRehab {
if err := updateRehabDoctor(er.UpdateDto{CreateDto: er.CreateDto{
Encounter_Id: &data.Id,
Doctor_Id: input.Responsible_Doctor_Id,
}}, &event, tx); err != nil {
return err
}
}
pl.SetLogInfo(&event, nil, "complete")
return nil
@@ -702,43 +621,205 @@ func CheckIn(input e.CheckinDto) (*d.Data, error) {
}, nil
}
func validateForeignKey(input e.CheckinDto) error {
// validate employee_Id
if input.Adm_Employee_Id != nil {
if _, err := uem.ReadDetail(eem.ReadDetailDto{Id: uint16(*input.Adm_Employee_Id)}); err != nil {
func RequestSwitchUnit(input e.SwitchUnitDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"}
var data *e.Encounter
var err error
event := pl.Event{
Feature: "RequestSwitchUnit",
Source: source,
}
// Start log
pl.SetLogInfo(&event, input, "started", "checkOut")
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.Doctor_Code != nil {
doctorCodes[*ref.Doctor_Code] = struct{}{}
}
}
// validate unit
if err = validateUnitCodes(unitCodes, &event); err != nil {
return nil, err
}
// validate doctor
if err = validateDoctorCodes(doctorCodes, &event); err != nil {
return nil, err
}
err = dg.I.Transaction(func(tx *gorm.DB) error {
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
return err
}
}
// validate doctor_id
if input.Responsible_Doctor_Id != nil {
if _, err := ud.ReadDetail(ed.ReadDetailDto{Id: uint16(*input.Responsible_Doctor_Id)}); err != nil {
//if data.IsDone() {
// event.Status = "failed"
// event.ErrInfo = pl.ErrorInfo{
// Code: "data-state-mismatch",
// Detail: "encounter is done",
// Raw: errors.New("encounter is done"),
// }
// return pl.SetLogError(&event, input)
//}
// verify Soapi exist for current responsible doctor
dataSoapi, err := getSoapiByResponsibleDoctor(*data, &event)
if err != nil {
return err
}
if len(dataSoapi) < 1 {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "missing-soapi",
Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"),
}
return pl.SetLogError(&event, input)
}
// bulk internal references
if err := uir.CreateBulkData(*input.InternalReferences, input.Id, &event, tx); err != nil {
return err
}
pl.SetLogInfo(&event, nil, "complete")
return nil
})
if err != nil {
return nil, err
}
return nil
return &d.Data{
Meta: d.IS{
"source": source,
"structure": "single-data",
"status": "requestSwitchUnit",
},
Data: data.ToResponse(),
}, nil
}
func verifyClassCode(input e.CreateDto) (subCode interface{}, err error) {
switch input.Class_Code {
case ere.ECAmbulatory:
subCode, err = ua.CheckClassCode(input.SubClass_Code)
if err != nil {
return nil, err
}
case ere.ECEmergency:
subCode, err = ue.CheckClassCode(input.SubClass_Code)
if err != nil {
return nil, err
}
case ere.ECInpatient:
subCode, err = ui.CheckClassCode(input.SubClass_Code)
if err != nil {
return nil, err
}
default:
return nil, errors.New("invalid encounter class code")
func ApproveSwitchUnit(input e.ApproveUnitDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id), Includes: "Responsible_Doctor"}
var data *e.Encounter
var err error
event := pl.Event{
Feature: "ApproveSwitchUnit",
Source: source,
}
return
// Start log
pl.SetLogInfo(&event, input, "started", "approveSwitchUnit")
err = dg.I.Transaction(func(tx *gorm.DB) error {
pl.SetLogInfo(&event, rdDto, "started", "DBReadDetail")
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
return err
}
// get internal reference
irData, err := uir.ReadDetailData(eir.ReadDetailDto{
Id: input.InternalReferences_Id, Includes: "Doctor"}, &event, tx)
if err != nil {
return err
}
if *irData.Status_Code != erc.DACNew {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-state-mismatch",
Detail: "internal references is approve",
Raw: errors.New("internal references is approve"),
}
return pl.SetLogError(&event, input)
}
//if data.IsDone() {
// event.Status = "failed"
// event.ErrInfo = pl.ErrorInfo{
// Code: "data-state-mismatch",
// Detail: "encounter is done",
// Raw: errors.New("encounter is done"),
// }
// return pl.SetLogError(&event, input)
//}
// verify Soapi exist for current responsible doctor
dataSoapi, err := getSoapiByResponsibleDoctor(*data, &event)
if err != nil {
return err
}
if len(dataSoapi) < 1 {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "missing-soapi",
Detail: fmt.Sprintf("Missing soapi from latest responsible doctor"),
}
return pl.SetLogError(&event, input)
}
// update internal reference
if err = uir.UpdateData(eir.UpdateDto{
Id: input.InternalReferences_Id,
CreateDto: eir.CreateDto{
Encounter_Id: &input.Id,
Doctor_Code: irData.Doctor_Code,
Unit_Code: irData.Unit_Code,
Status_Code: erc.DACApproved,
}}, irData, &event, tx); err != nil {
return err
}
// update encounter
if err = updateEncounterApproveSwitchUnit(*irData, &event, tx); err != nil {
return err
}
// update latest responsible doctor hist
if err = updateLatestResponsibleDoctorHist(e.CheckinDto{Id: input.Id, FinishedAt: &now}, &event, tx); err != nil {
return err
}
// create responsible doctor based on internal reference data
if _, err = urdh.CreateData(erdh.CreateDto{
Encounter_Id: &input.Id,
Doctor_Code: irData.Doctor_Code,
StartedAt: &now,
}, &event, tx); err != nil {
return err
}
// update data response
data.Responsible_Doctor_Code = irData.Doctor_Code
data.Unit = irData.Unit // TODO: check if this is correct
data.Specialist_Code = irData.Doctor.Specialist_Code
data.Subspecialist_Code = irData.Doctor.Subspecialist_Code
pl.SetLogInfo(&event, nil, "complete")
return nil
})
if err != nil {
return nil, err
}
return &d.Data{
Meta: d.IS{
"source": source,
"structure": "single-data",
"status": "updated",
},
Data: data.ToResponse(),
}, nil
}
@@ -10,6 +10,8 @@ import (
"strings"
"time"
authhelper "simrs-vx/internal/lib/auth"
dg "github.com/karincake/apem/db-gorm-pg"
"gorm.io/gorm"
@@ -23,9 +25,13 @@ import (
eaeh "simrs-vx/internal/domain/main-entities/adm-employee-hist"
ea "simrs-vx/internal/domain/main-entities/ambulatory"
ec "simrs-vx/internal/domain/main-entities/chemo"
edo "simrs-vx/internal/domain/main-entities/device-order"
ed "simrs-vx/internal/domain/main-entities/doctor"
ee "simrs-vx/internal/domain/main-entities/emergency"
eem "simrs-vx/internal/domain/main-entities/employee"
e "simrs-vx/internal/domain/main-entities/encounter"
ei "simrs-vx/internal/domain/main-entities/inpatient"
emo "simrs-vx/internal/domain/main-entities/material-order"
emco "simrs-vx/internal/domain/main-entities/mcu-order"
em "simrs-vx/internal/domain/main-entities/medication"
@@ -36,19 +42,26 @@ import (
epi "simrs-vx/internal/domain/main-entities/prescription-item"
er "simrs-vx/internal/domain/main-entities/rehab"
erdh "simrs-vx/internal/domain/main-entities/responsible-doctor-hist"
es "simrs-vx/internal/domain/main-entities/soapi"
eu "simrs-vx/internal/domain/main-entities/unit"
// udo "simrs-vx/internal/use-case/main-use-case/device-order"
es "simrs-vx/internal/domain/main-entities/soapi"
uaeh "simrs-vx/internal/use-case/main-use-case/adm-employee-hist"
uir "simrs-vx/internal/use-case/main-use-case/internal-reference"
ua "simrs-vx/internal/use-case/main-use-case/ambulatory"
uc "simrs-vx/internal/use-case/main-use-case/chemo"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/emergency"
uem "simrs-vx/internal/use-case/main-use-case/employee"
ui "simrs-vx/internal/use-case/main-use-case/inpatient"
um "simrs-vx/internal/use-case/main-use-case/medication"
umei "simrs-vx/internal/use-case/main-use-case/medication-item"
umi "simrs-vx/internal/use-case/main-use-case/medicine-mix"
ummi "simrs-vx/internal/use-case/main-use-case/medicine-mix-item"
up "simrs-vx/internal/use-case/main-use-case/prescription"
upi "simrs-vx/internal/use-case/main-use-case/prescription-item"
ur "simrs-vx/internal/use-case/main-use-case/rehab"
urdh "simrs-vx/internal/use-case/main-use-case/responsible-doctor-hist"
us "simrs-vx/internal/use-case/main-use-case/soapi"
)
func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
@@ -63,18 +76,18 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
data.Patient_Id = inputSrc.Patient_Id
data.RegisteredAt = inputSrc.RegisteredAt
data.Class_Code = inputSrc.Class_Code
data.Unit_Id = inputSrc.Unit_Id
data.Specialist_Id = inputSrc.Specialist_Id
data.Subspecialist_Id = inputSrc.Subspecialist_Id
data.Unit_Code = inputSrc.Unit_Code
data.Specialist_Code = inputSrc.Specialist_Code
data.Subspecialist_Code = inputSrc.Subspecialist_Code
data.VisitDate = inputSrc.VisitDate
data.PaymentMethod_Code = inputSrc.PaymentMethod_Code
data.InsuranceCompany_Id = inputSrc.InsuranceCompany_Id
data.InsuranceCompany_Code = inputSrc.InsuranceCompany_Code
data.Member_Number = inputSrc.Member_Number
data.Ref_Number = inputSrc.Ref_Number
data.Trx_Number = inputSrc.Trx_Number
data.Appointment_Doctor_Id = inputSrc.Appointment_Doctor_Id
data.Appointment_Doctor_Code = inputSrc.Appointment_Doctor_Code
data.Adm_Employee_Id = inputSrc.Adm_Employee_Id
data.Responsible_Doctor_Id = inputSrc.Responsible_Doctor_Id
data.Responsible_Doctor_Code = inputSrc.Responsible_Doctor_Code
data.RefSource_Name = inputSrc.RefSource_Name
data.Appointment_Id = inputSrc.Appointment_Id
data.Status_Code = erc.DSCProcess
@@ -83,11 +96,11 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Encounter) {
}
func setDataUpdate(src e.UpdateDto, dst *e.Encounter) {
dst.Appointment_Doctor_Id = src.Appointment_Doctor_Id
dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id
dst.Unit_Id = src.Unit_Id
dst.Specialist_Id = src.Specialist_Id
dst.Subspecialist_Id = src.Subspecialist_Id
dst.Appointment_Doctor_Code = src.Appointment_Doctor_Code
dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code
dst.Unit_Code = src.Unit_Code
dst.Specialist_Code = src.Specialist_Code
dst.Subspecialist_Code = src.Subspecialist_Code
dst.VisitDate = src.VisitDate
}
@@ -104,6 +117,19 @@ func setDataDischarge(src e.DischargeDto, dst *e.Encounter) {
dst.FinishedAt = &now
}
func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) {
dst.Status_Code = src.StatusCode
}
func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) {
if src.Adm_Employee_Id != nil {
dst.Adm_Employee_Id = src.Adm_Employee_Id
}
dst.Responsible_Doctor_Code = src.Responsible_Doctor_Code
dst.StartedAt = src.StartedAt
}
func checkSoapiByDocExists(encounter_id uint, event *pl.Event, tx *gorm.DB) error {
pl.SetLogInfo(event, nil, "started", "checkSoapiByDocExists")
var soapies []es.Soapi
@@ -335,113 +361,6 @@ func getMcuOrders(encounter_id uint, event *pl.Event, tx *gorm.DB) error {
return nil
}
func setDataUpdateStatus(src e.UpdateStatusDto, dst *e.Encounter) {
dst.Status_Code = src.StatusCode
}
func setDataCheckIn(src e.CheckinDto, dst *e.Encounter) {
if src.Adm_Employee_Id != nil {
dst.Adm_Employee_Id = src.Adm_Employee_Id
}
dst.Responsible_Doctor_Id = src.Responsible_Doctor_Id
dst.StartedAt = src.StartedAt
}
func createInternalReferences(input e.DischargeDto, event *pl.Event, tx *gorm.DB) error {
unitIDs := make(map[uint16]struct{})
doctorIDs := make(map[uint]struct{})
for _, ref := range *input.InternalReferences {
if ref.Unit_Id != nil {
unitIDs[*ref.Unit_Id] = struct{}{}
}
if ref.Doctor_Id != nil {
doctorIDs[*ref.Doctor_Id] = struct{}{}
}
}
// validate unitIds
if len(unitIDs) > 0 {
var ids []uint16
for id := range unitIDs {
ids = append(ids, id)
}
units, err := getUnits(ids, event, tx)
if err != nil {
return fmt.Errorf("failed to fetch units: %w", err)
}
if len(units) != len(ids) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-validation-fail",
Detail: "unit_id not found",
}
return pl.SetLogError(event, nil)
}
}
// validate doctorIds
if len(doctorIDs) > 0 {
var ids []uint
for id := range doctorIDs {
ids = append(ids, id)
}
doctors, err := getDoctors(ids, event, tx)
if err != nil {
return fmt.Errorf("failed to fetch doctors: %w", err)
}
if len(doctors) != len(ids) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-validation-fail",
Detail: "doctor_id not found",
}
return pl.SetLogError(event, nil)
}
}
if err := uir.CreateBulkData(*input.InternalReferences, input.Id, event, tx); err != nil {
return err
}
return nil
}
func getUnits(unitIds []uint16, event *pl.Event, tx *gorm.DB) ([]eu.Unit, error) {
pl.SetLogInfo(event, nil, "started", "getUnits")
var units []eu.Unit
err := tx.Where("\"Id\" IN ?", unitIds).Find(&units).Error
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-get-fail",
Detail: "get units",
Raw: err,
}
return nil, pl.SetLogError(event, nil)
}
return units, nil
}
func getDoctors(doctorIds []uint, event *pl.Event, tx *gorm.DB) ([]ed.Doctor, error) {
pl.SetLogInfo(event, nil, "started", "getDoctors")
var doctors []ed.Doctor
err := tx.Where("\"Id\" IN ?", doctorIds).Find(&doctors).Error
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-get-fail",
Detail: "get doctors",
Raw: err,
}
return nil, pl.SetLogError(event, nil)
}
return doctors, nil
}
func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...*gorm.DB) error {
pl.SetLogInfo(event, nil, "started", "DBCreate")
@@ -476,9 +395,9 @@ func upsertResponsibleDoctorHist(input erdh.CreateDto, event *pl.Event, dbx ...*
default:
// Update
if err := tx.Model(&latest).Updates(map[string]interface{}{
"Doctor_Id": input.Doctor_Id,
"StartedAt": input.StartedAt,
"UpdatedAt": time.Now(),
"Doctor_Code": input.Doctor_Code,
"StartedAt": input.StartedAt,
"UpdatedAt": time.Now(),
}).Error; err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
@@ -566,7 +485,7 @@ func updateLatestResponsibleDoctorHist(input e.CheckinDto, event *pl.Event, dbx
result := tx.
Model(&erdh.ResponsibleDoctorHist{}).
Where("\"Id\" = (?)", subQuery).
Update("\"FinishedAt\"", input.StartedAt)
Update("\"FinishedAt\"", input.FinishedAt)
if result.Error != nil {
event.Status = "failed"
@@ -607,7 +526,7 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go
result := tx.
Model(&eaeh.AdmEmployeeHist{}).
Where("\"Id\" = (?)", subQuery).
Update("\"FinishedAt\"", input.StartedAt)
Update("\"FinishedAt\"", input.FinishedAt)
if result.Error != nil {
event.Status = "failed"
@@ -628,9 +547,7 @@ func updateLatestAdmEmployeeHist(input e.CheckinDto, event *pl.Event, dbx ...*go
return nil
}
func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) {
var data []es.Soapi
func getSoapiByResponsibleDoctor(enc e.Encounter, event *pl.Event) (data []es.Soapi, err error) {
pl.SetLogInfo(event, enc, "started", "DBReadList")
if enc.Responsible_Doctor == nil {
@@ -642,6 +559,7 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea
}
err = dg.I.
Debug().
Model(&es.Soapi{}).
Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\"").
Where("\"Encounter_Id\" = ?", enc.Id).
@@ -653,21 +571,22 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Raw: err,
Raw: err,
Code: "read-fail",
Detail: "Database read failed",
}
if errors.Is(err, gorm.ErrRecordNotFound) {
event.ErrInfo.Code = "data-not-found"
event.ErrInfo.Detail = "Data not found"
return nil, pl.SetLogError(event, enc)
}
event.ErrInfo.Code = "read-fail"
event.ErrInfo.Detail = "Database read failed"
return nil, pl.SetLogError(event, enc)
}
pl.SetLogInfo(event, nil, "complete")
return
}
func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.CreateDto, err error) {
data, err := getSoapiByResponsibleDoctor(enc, event)
if err != nil {
return nil, err
}
for _, s := range data {
// set data soapi for copy
@@ -690,39 +609,46 @@ func getSoapiEncounterAdm(enc e.Encounter, event *pl.Event) (dataSoapi []es.Crea
return
}
func getSoapiByTypeCode(encounterId uint, dataAmbulatory ea.Ambulatory, event *pl.Event, mode string) (err error) {
pl.SetLogInfo(event, encounterId, "started", "DBReadList")
func getSoapiByTypeCode(encounter *e.Encounter, event *pl.Event, mode string) (err error) {
pl.SetLogInfo(event, encounter, "started", "DBReadList")
var (
dataSoapi []es.Soapi
amb = encounter.Ambulatory
rehab = encounter.Rehab
)
// Set Query for get data Soapi
tx := dg.I.
Model(&es.Soapi{}).
Joins("JOIN \"Employee\" ON \"Employee\".\"Id\" = \"Soapi\".\"Employee_Id\"").
Where("\"Encounter_Id\" = ?", encounterId).
Where("\"Encounter_Id\" = ?", encounter.Id).
Where("\"Employee\".\"Position_Code\" = ?", erg.EPCDoc)
// Set Case
switch {
case dataAmbulatory.Class_Code == ere.ACCReg:
case amb.Class_Code == ere.ACCReg:
tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEEarlyMedic)
case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm:
case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCAdm:
tx = tx.Where("\"Soapi\".\"TypeCode\" IN ?", []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab})
case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries:
case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCSeries:
tx = tx.Where("\"Soapi\".\"TypeCode\" = ?", ercl.STCEarlyRehab)
}
if err = tx.Find(&dataSoapi).Error; err != nil {
return setDBError(event, err, encounterId)
return setDBError(event, err, encounter)
}
pl.SetLogInfo(event, nil, "complete")
return validateExistedSoapi(dataSoapi, &dataAmbulatory, event, mode)
return validateExistedSoapi(dataSoapi, encounter, event, mode)
}
func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, event *pl.Event, mode string) error {
func validateExistedSoapi(dataSoapi []es.Soapi, dataEncounter *e.Encounter, event *pl.Event, mode string) error {
var (
amb = dataEncounter.Ambulatory
rehab = dataEncounter.Rehab
)
typeExist := make(map[ercl.SoapiTypeCode]bool)
for _, s := range dataSoapi {
typeExist[s.TypeCode] = true
@@ -731,11 +657,11 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e
required := []ercl.SoapiTypeCode{}
switch {
case dataAmbulatory.Class_Code == ere.ACCReg:
case amb.Class_Code == ere.ACCReg:
required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic}
case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCAdm:
case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCAdm:
required = []ercl.SoapiTypeCode{ercl.STCEEarlyMedic, ercl.STCFunc, ercl.STCEarlyRehab}
case dataAmbulatory.Class_Code == ere.ACCRehab && dataAmbulatory.VisitMode_Code == ere.VMCSeries:
case amb.Class_Code == ere.ACCRehab && *rehab.VisitMode_Code == ere.VMCSeries:
required = []ercl.SoapiTypeCode{ercl.STCEarlyRehab}
}
@@ -762,6 +688,231 @@ func validateExistedSoapi(dataSoapi []es.Soapi, dataAmbulatory *ea.Ambulatory, e
return nil
}
func identifyPatientStatus(input e.CreateDto) (isNewPatient bool, err error) {
dataPatient, err := ReadList(e.ReadListDto{
FilterDto: e.FilterDto{Patient_Id: input.Patient_Id},
AuthInfo: authhelper.AuthInfo{User_Id: input.User_Id}})
if err != nil {
return
}
if list, ok := dataPatient.Data.([]e.ResponseDto); ok {
if len(list) < 1 {
isNewPatient = true
}
}
return
}
func determineVisitMode(recentRehabData *er.Rehab, input e.CreateDto, event *pl.Event) (ere.VisitModeCode, *e.Encounter, error) {
var (
visitModeCode ere.VisitModeCode
recentAdmEncounterData e.Encounter
isQuotaValid bool
err error
)
switch *recentRehabData.Status_Code {
case erc.DSCProcess:
visitModeCode = ere.VMCSeries
// verify whether the allocated visit count has not exceeded the limit
recentAdmEncounterData, isQuotaValid, err = verifyAllocatedVisitCount(input, event)
if err != nil {
return "", nil, err
}
if !isQuotaValid || recentRehabData.ExpiredAt.Before(*pu.GetTimeNow()) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "visit-limit-exceeded",
Detail: "Encounter has exceeded the allowed number of visits or expired",
Raw: errors.New("visit count exceeds allowed limit"),
}
return "", nil, pl.SetLogError(event, input)
}
case erc.DSCDone:
visitModeCode = ere.VMCAdm
default:
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "invalid-status",
Detail: fmt.Sprintf("Unknown rehab status: %v", *recentRehabData.Status_Code),
Raw: errors.New("unsupported rehab status"),
}
return "", nil, pl.SetLogError(event, input)
}
return visitModeCode, &recentAdmEncounterData, nil
}
func insertdataClassCode(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) {
switch input.Class_Code {
case ere.ECAmbulatory:
subCode := ere.AmbulatoryClassCode(*input.SubClass_Code)
ambCreate := ea.CreateDto{
Encounter_Id: &input.Id,
Class_Code: subCode,
}
// create data Ambulatory
_, err = ua.CreateData(ambCreate, event, tx)
if err != nil {
return err
}
// insert chemo/rehab
err = insertDataSubClassAmbulatory(input, soapiData, event, tx)
if err != nil {
return err
}
case ere.ECEmergency:
subCode := ere.EmergencyClassCode(*input.SubClass_Code)
emerCreate := ee.CreateDto{
Encounter_Id: &input.Id,
Class_Code: subCode,
}
// create data emergency
_, err = ue.CreateData(emerCreate, event, tx)
if err != nil {
return err
}
case ere.ECInpatient:
subCode := ere.InpatientClassCode(*input.SubClass_Code)
inpCreate := ei.CreateDto{
Encounter_Id: &input.Id,
Class_Code: subCode,
Infra_Code: input.Infra_Code,
}
// create data inpatient
_, err = ui.CreateData(inpCreate, event, tx)
if err != nil {
return err
}
default:
return errors.New("invalid encounter class code")
}
return
}
func insertDataSubClassAmbulatory(input e.CreateDto, soapiData []es.CreateDto, event *pl.Event, tx *gorm.DB) (err error) {
subCode := ere.AmbulatoryClassCode(*input.SubClass_Code)
switch {
case subCode == ere.ACCChemo:
chemoCreate := ec.CreateDto{
Encounter_Id: &input.Id,
Status_Code: erc.DVCNew,
SrcUnit_Code: input.Unit_Code,
}
// create data chemo
_, err = uc.CreateData(chemoCreate, event, tx)
if err != nil {
return err
}
case subCode == ere.ACCRehab:
rehabData := er.CreateDto{
Encounter_Id: &input.Id,
VisitMode_Code: input.VisitMode_Code,
Status_Code: erc.DSCProcess,
}
// if visitMode_code is series, then bulk insert soapi
if input.VisitMode_Code == ere.VMCSeries {
rehabData.Parent_Encounter_Id = &input.RecentEncounterAdm.Id
// Insert Soapi
if err = us.CreateBulkData(soapiData, input.Id, event, tx); err != nil {
return err
}
}
// create rehab
if _, err = ur.CreateData(rehabData, event, tx); err != nil {
return err
}
}
return
}
func verifyRehabLimit(data *e.Encounter, event *pl.Event, tx *gorm.DB) error {
// get data encounter adm
encounterAdmData, _, err := verifyAllocatedVisitCount(e.CreateDto{Patient_Id: data.Patient_Id}, event)
if err != nil {
return err
}
// Check if the visit count has reached the allowed limit
// Mark latest rehab status as 'done' if exceeded.
if len(*encounterAdmData.RehabChildren) >= *encounterAdmData.Rehab.AllocatedVisitCount {
err = updateRehabStatus(er.UpdateDto{
Id: uint16(data.Rehab.Id),
CreateDto: er.CreateDto{Status_Code: erc.DSCDone}}, event, tx)
if err != nil {
return err
}
}
return nil
}
func updateRehabStatus(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error {
pl.SetLogInfo(event, "started", "DBUpdate")
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
result := tx.
Model(&er.Rehab{}).
Where("\"Id\" = (?)", input.Id).
Update("\"Status_Code\"", input.Status_Code)
if result.Error != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-update-fail",
Detail: "Database update failed",
Raw: result.Error,
}
return pl.SetLogError(event, input)
}
pl.SetLogInfo(event, nil, "complete")
return nil
}
func validateForeignKey(input e.CheckinDto) error {
// validate employee_Id
if input.Adm_Employee_Id != nil {
if _, err := uem.ReadDetail(eem.ReadDetailDto{Id: uint16(*input.Adm_Employee_Id)}); err != nil {
return err
}
}
// validate doctor_id
if input.Responsible_Doctor_Code != nil {
if _, err := ud.ReadDetail(ed.ReadDetailDto{Code: input.Responsible_Doctor_Code}); err != nil {
return err
}
}
return nil
}
func setSoapiError(event *pl.Event, detail string) error {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
@@ -781,31 +932,82 @@ func setDBError(event *pl.Event, err error, ctx any) error {
return pl.SetLogError(event, ctx)
}
func updateRehabDoctor(input er.UpdateDto, event *pl.Event, dbx ...*gorm.DB) error {
pl.SetLogInfo(event, "started", "DBUpdate")
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
result := tx.
Model(&er.Rehab{}).
Where("\"Encounter_Id\" = (?)", input.Encounter_Id).
Update("\"Doctor_Id\"", input.Doctor_Id)
if result.Error != nil {
func getUnits(unitIds []string, event *pl.Event) ([]eu.Unit, error) {
pl.SetLogInfo(event, nil, "started", "getUnits")
var units []eu.Unit
err := dg.I.Where("\"Code\" IN ?", unitIds).Find(&units).Error
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-update-fail",
Detail: "Database update failed",
Raw: result.Error,
Code: "data-get-fail",
Detail: "get units",
Raw: err,
}
return nil, pl.SetLogError(event, nil)
}
return units, nil
}
func getDoctors(doctorIds []string, event *pl.Event) ([]ed.Doctor, error) {
pl.SetLogInfo(event, nil, "started", "getDoctors")
var doctors []ed.Doctor
err := dg.I.Where("\"Id\" Code ?", doctorIds).Find(&doctors).Error
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-get-fail",
Detail: "get doctors",
Raw: err,
}
return nil, pl.SetLogError(event, nil)
}
return doctors, nil
}
func validateUnitCodes(unitCodes map[string]struct{}, event *pl.Event) error {
if len(unitCodes) > 0 {
var codes []string
for code := range unitCodes {
codes = append(codes, code)
}
units, err := getUnits(codes, event)
if err != nil {
return fmt.Errorf("failed to fetch units: %w", err)
}
if len(units) != len(codes) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-validation-fail",
Detail: "unit_id not found",
}
return pl.SetLogError(event, nil)
}
}
return nil
}
func validateDoctorCodes(doctorCodes map[string]struct{}, event *pl.Event) error {
if len(doctorCodes) > 0 {
var codes []string
for code := range doctorCodes {
codes = append(codes, code)
}
doctors, err := getDoctors(codes, event)
if err != nil {
return fmt.Errorf("failed to fetch doctors: %w", err)
}
if len(doctors) != len(codes) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "data-validation-fail",
Detail: "doctor_id not found",
}
return pl.SetLogError(event, nil)
}
return pl.SetLogError(event, input)
}
pl.SetLogInfo(event, nil, "complete")
return nil
}
@@ -3,7 +3,7 @@ package encounter
import (
// std
"errors"
ere "simrs-vx/internal/domain/references/encounter"
eir "simrs-vx/internal/domain/main-entities/internal-reference"
// external
dg "github.com/karincake/apem/db-gorm-pg"
@@ -15,9 +15,14 @@ import (
pl "simrs-vx/pkg/logger"
pu "simrs-vx/pkg/use-case-helper"
ere "simrs-vx/internal/domain/references/encounter"
e "simrs-vx/internal/domain/main-entities/encounter"
er "simrs-vx/internal/domain/main-entities/rehab"
)
const ErrorReadFailed = "Database read failed"
func CreateData(input e.CreateDto, event *pl.Event, dbx ...*gorm.DB) (*e.Encounter, error) {
pl.SetLogInfo(event, nil, "started", "DBCreate")
@@ -251,20 +256,49 @@ func updateCheckInData(input e.CheckinDto, data *e.Encounter, event *pl.Event, d
return nil
}
func getLatestRehabData(i e.CreateDto, event *pl.Event) (recentRehabData *er.Rehab, err error) {
pl.SetLogInfo(event, nil, "started", "DBGetLatestRehab")
var (
tx = dg.I
)
err = tx.
Joins("JOIN \"Encounter\" ON \"Encounter\".\"Id\" = \"Rehab\".\"Encounter_Id\"").
Where("\"Encounter\".\"Patient_Id\" = ?", i.Patient_Id).
Order("\"CreatedAt\" DESC").
First(&recentRehabData).Error
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, nil
}
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "read-recentRehab-fail",
Detail: ErrorReadFailed,
Raw: err,
}
return nil, pl.SetLogError(event, i)
}
return
}
func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, bool, error) {
pl.SetLogInfo(event, nil, "started", "DBGetRecentEncounterAdm")
var (
tx = dg.I
recentEncounterAdm e.Encounter
countEncounterSeries int64
tx = dg.I
recentEncounterAdm e.Encounter
valid = true
)
err := tx.
Scopes(gh.Preload("Rehab,Responsible_Doctor")).
Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\"").
Where("\"Patient_Id\" = ?", i.Patient_Id).
Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCAdm).
Scopes(gh.Preload("RehabChildren,Rehab,Responsible_Doctor")).
Joins("JOIN \"Rehab\" ON \"Rehab\".\"Encounter_Id\" = \"Encounter\".\"Id\"").
Where("\"Encounter\".\"Patient_Id\" = ?", i.Patient_Id).
Where("\"Rehab\".\"VisitMode_Code\" = ?", ere.VMCAdm).
Order("\"CreatedAt\" DESC").
First(&recentEncounterAdm).Error
if err != nil {
@@ -277,22 +311,41 @@ func verifyAllocatedVisitCount(i e.CreateDto, event *pl.Event) (e.Encounter, boo
return e.Encounter{}, false, pl.SetLogError(event, i)
}
err = tx.
Model(&e.Encounter{}).
Joins("JOIN \"Ambulatory\" ON \"Ambulatory\".\"Encounter_Id\" = \"Encounter\".\"Id\"").
Where("\"Patient_Id\" = ?", i.Patient_Id).
Where("\"Ambulatory\".\"Class_Code\" = ? AND \"Ambulatory\".\"VisitMode_Code\" = ?", ere.ACCRehab, ere.VMCSeries).
Where("\"Encounter\".\"CreatedAt\" > ?", recentEncounterAdm.CreatedAt).
Count(&countEncounterSeries).Error
if err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "read-countEncounter-fail",
Detail: "Database read failed",
Raw: err,
}
return e.Encounter{}, false, pl.SetLogError(event, i)
// validate count rehab children
if recentEncounterAdm.RehabChildren != nil {
valid = len(*recentEncounterAdm.RehabChildren) < *recentEncounterAdm.Rehab.AllocatedVisitCount
}
return recentEncounterAdm, countEncounterSeries < int64(*recentEncounterAdm.Rehab.AllocatedVisitCount), nil
return recentEncounterAdm, valid, nil
}
func updateEncounterApproveSwitchUnit(input eir.InternalReference, event *pl.Event, dbx ...*gorm.DB) (err error) {
pl.SetLogInfo(event, nil, "started", "DBCreate")
var tx *gorm.DB
if len(dbx) > 0 {
tx = dbx[0]
} else {
tx = dg.I
}
if err := tx.Model(&e.Encounter{}).
Where("\"Id\" = ?", input.Encounter_Id).
Updates(map[string]interface{}{
"Responsible_Doctor_Code": input.Doctor_Code,
"Unit_Code": input.Unit_Code,
"Specialist_Code": input.Doctor.Specialist_Code,
"Subspecialist_Code": input.Doctor.Subspecialist_Code,
}).Error; err != nil {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "update-fail",
Detail: "Failed to update encounter approve switch unit",
Raw: err,
}
return pl.SetLogError(event, input)
}
pl.SetLogInfo(event, input, "complete")
return nil
}
@@ -22,6 +22,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Inpatient) {
data.Encounter_Id = inputSrc.Encounter_Id
data.Class_Code = inputSrc.Class_Code
data.Infra_Code = inputSrc.Infra_Code
}
func CheckClassCode(input *string) (ere.InpatientClassCode, error) {
@@ -6,6 +6,7 @@ package internal_reference
import (
ir "simrs-vx/internal/domain/main-entities/internal-reference"
erc "simrs-vx/internal/domain/references/common"
)
func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReference) {
@@ -18,18 +19,21 @@ func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReferenc
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Unit_Id = inputSrc.Unit_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Unit_Code = inputSrc.Unit_Code
data.Doctor_Code = inputSrc.Doctor_Code
data.Status_Code = &inputSrc.Status_Code
}
func setBulkData(input []ir.CreateDto, encounterId uint) []ir.InternalReference {
var data []ir.InternalReference
for _, v := range input {
statusCode := erc.DACNew
data = append(data, ir.InternalReference{
Encounter_Id: &encounterId,
Unit_Id: v.Unit_Id,
Doctor_Id: v.Doctor_Id,
Unit_Code: v.Unit_Code,
Doctor_Code: v.Doctor_Code,
Status_Code: &statusCode,
})
}
@@ -18,6 +18,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MaterialOrderItem)
}
data.MaterialOrder_Id = inputSrc.MaterialOrder_Id
data.Material_Id = inputSrc.Material_Id
data.Material_Code = inputSrc.Material_Code
data.Count = inputSrc.Count
}
@@ -6,7 +6,6 @@ import (
e "simrs-vx/internal/domain/main-entities/material-order"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
@@ -56,11 +55,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if resData, err := CreateData(input, &event, tx); err != nil {
return err
@@ -233,12 +228,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if !data.IsSameDoctor(doctor_id) {
if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "auth-forbidden",
@@ -248,7 +238,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if err := UpdateData(input, data, &event, tx); err != nil {
return err
@@ -21,5 +21,5 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MaterialOrder) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Doctor_Code = inputSrc.Doctor_Code
}
@@ -6,7 +6,6 @@ import (
e "simrs-vx/internal/domain/main-entities/mcu-order"
ud "simrs-vx/internal/use-case/main-use-case/doctor"
ue "simrs-vx/internal/use-case/main-use-case/encounter"
erc "simrs-vx/internal/domain/references/common"
@@ -56,11 +55,7 @@ func Create(input e.CreateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if resData, err := CreateData(input, &event, tx); err != nil {
return err
@@ -233,12 +228,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
doctor_id, err := ud.GetIdByUserId(&input.AuthInfo.User_Id, &event, tx)
if err != nil {
return err
}
if !data.IsSameDoctor(doctor_id) {
if !data.IsSameDoctor(input.AuthInfo.Doctor_Code) {
event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{
Code: "auth-forbidden",
@@ -248,7 +238,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
return pl.SetLogError(&event, input)
}
input.Doctor_Id = doctor_id
input.Doctor_Code = input.AuthInfo.Doctor_Code
if err := UpdateData(input, data, &event, tx); err != nil {
return err
@@ -21,12 +21,11 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuOrder) {
}
data.Encounter_Id = inputSrc.Encounter_Id
data.Doctor_Id = inputSrc.Doctor_Id
data.Doctor_Code = inputSrc.Doctor_Code
data.SpecimenPickTime = inputSrc.SpecimenPickTime
data.ExaminationDate = inputSrc.ExaminationDate
data.Number = inputSrc.Number
data.Temperature = inputSrc.Temperature
data.UrgencyLevel_Code = inputSrc.UrgencyLevel_Code
data.Doctor_Id = inputSrc.Doctor_Id
data.Scope_Code = inputSrc.Scope_Code
}
@@ -170,7 +170,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
}
func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.McuSrc
var err error
@@ -226,7 +226,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
}
func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.McuSrc
var err error
@@ -27,14 +27,14 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSrc) {
inputSrc = &inputTemp.CreateDto
}
data.Code = inputSrc.Code
data.Code = *inputSrc.Code
data.Name = inputSrc.Name
data.McuSrcCategory_Code = inputSrc.McuSrcCategory_Code
}
func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
itemCreate := ei.CreateDto{
Code: pu.AddPrefix("mcu-", input.Code),
Code: pu.AddPrefix("mcu-", *input.Code),
Name: input.Name,
ItemGroup_Code: ero.ITGCMCU,
// Uom_Code: &input.Uom_Code,
@@ -45,6 +45,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
return err
}
input.Item_Id = &item.Id
input.Item_Code = &item.Code
return nil
}
@@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
tx = dg.I
}
if err := tx.First(&data, input.Id).Error; err != nil {
if input.Code != nil {
tx = tx.Where("\"Code\" = ?", *input.Code)
}
if input.Id != nil {
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx.First(&data).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr
}
@@ -170,7 +170,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
}
func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.McuSubSrc
var err error
@@ -226,7 +226,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
}
func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.McuSubSrc
var err error
@@ -27,15 +27,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSubSrc) {
inputSrc = &inputTemp.CreateDto
}
data.Code = inputSrc.Code
data.Code = *inputSrc.Code
data.Name = inputSrc.Name
data.McuSrc_Id = inputSrc.McuSrc_Id
data.Item_Id = inputSrc.Item_Id
data.McuSrc_Code = inputSrc.McuSrc_Code
data.Item_Code = inputSrc.Item_Code
}
func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
itemCreate := ei.CreateDto{
Code: pu.AddPrefix("mcuSub-", input.Code),
Code: pu.AddPrefix("mcuSub-", *input.Code),
Name: input.Name,
ItemGroup_Code: ero.ITGCMCUSub,
// Uom_Code: &input.Uom_Code,
@@ -46,6 +46,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
return err
}
input.Item_Id = &item.Id
input.Item_Code = &item.Code
return nil
}
@@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
tx = dg.I
}
if err := tx.First(&data, input.Id).Error; err != nil {
if input.Code != nil {
tx = tx.Where("\"Code\" = ?", *input.Code)
}
if input.Id != nil {
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx.First(&data).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr
}
@@ -16,7 +16,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrcIte
inputTemp := any(input).(*e.UpdateDto)
inputSrc = &inputTemp.CreateDto
}
data.MedicalActionSrc_Id = inputSrc.MedicalActionSrc_Id
data.ProcedureSrc_Id = inputSrc.ProcedureSrc_Id
data.Item_Id = inputSrc.Item_Id
data.MedicalActionSrc_Code = inputSrc.MedicalActionSrc_Code
data.ProcedureSrc_Code = inputSrc.ProcedureSrc_Code
data.Item_Code = inputSrc.Item_Code
}
@@ -169,7 +169,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
}
func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.MedicalActionSrc
var err error
@@ -225,7 +225,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
}
func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.MedicalActionSrc
var err error
@@ -27,15 +27,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrc) {
inputSrc = &inputTemp.CreateDto
}
data.Code = inputSrc.Code
data.Code = *inputSrc.Code
data.Name = inputSrc.Name
data.Type_Code = inputSrc.Type_Code
data.Item_Id = inputSrc.Item_Id
data.Item_Code = inputSrc.Item_Code
}
func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
itemCreate := ei.CreateDto{
Code: pu.AddPrefix("medAct-", input.Code),
Code: pu.AddPrefix("medAct-", *input.Code),
Name: input.Name,
ItemGroup_Code: ero.ITGCMedAct,
}
@@ -44,6 +44,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error {
return err
}
input.Item_Id = &item.Id
input.Item_Code = &item.Code
return nil
}
@@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
tx = dg.I
}
if err := tx.First(&data, input.Id).Error; err != nil {
if input.Code != nil {
tx = tx.Where("\"Code\" = ?", *input.Code)
}
if input.Id != nil {
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx.First(&data).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr
}
@@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
}
func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.Nurse
var err error
@@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
}
func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: uint16(input.Id)}
rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.Nurse
var err error

Some files were not shown because too many files have changed in this diff Show More