From 13ddfaab5f49f40944ead52b1f99d7cfd8885293 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 17 Nov 2025 14:49:34 +0700 Subject: [PATCH 1/2] rename and adjust upload code into doctypecode --- .../main-entities/encounter-document/dto.go | 32 ++++++++--------- .../encounter-document/entity.go | 14 ++++---- internal/domain/main-entities/patient/dto.go | 2 +- internal/domain/main-entities/upload/dto.go | 7 ++-- internal/domain/references/upload/upload.go | 35 ++++++++++--------- .../interface/main-handler/upload/handler.go | 2 +- .../use-case/main-use-case/upload/helper.go | 10 +++--- pkg/upload-helper/upload-helper.go | 14 ++++---- 8 files changed, 59 insertions(+), 57 deletions(-) diff --git a/internal/domain/main-entities/encounter-document/dto.go b/internal/domain/main-entities/encounter-document/dto.go index c1e0894c..4bc76994 100644 --- a/internal/domain/main-entities/encounter-document/dto.go +++ b/internal/domain/main-entities/encounter-document/dto.go @@ -9,12 +9,12 @@ import ( ) type CreateDto struct { - Encounter_Id *uint `json:"encounter_id"` - Type_Code eru.UploadCode `json:"type_code"` - Name string `json:"name"` - FilePath string `json:"filePath"` - Filename string `json:"-"` - Upload_Employee_Id *uint `form:"upload_employee_id"` + Encounter_Id *uint `json:"encounter_id"` + Type_Code eru.DocTypeCode `json:"type_code"` + Name string `json:"name"` + FilePath string `json:"filePath"` + Filename string `json:"-"` + Upload_Employee_Id *uint `form:"upload_employee_id"` } type ReadListDto struct { @@ -24,9 +24,9 @@ type ReadListDto struct { } type FilterDto struct { - Encounter_Id *uint `json:"encounter-id"` - Type_Code eru.UploadCode `json:"type-code"` - Upload_Employee_Id *string `json:"encounter-document-employee-id"` + Encounter_Id *uint `json:"encounter-id"` + Type_Code eru.DocTypeCode `json:"type-code"` + Upload_Employee_Id *string `json:"encounter-document-employee-id"` } type ReadDetailDto struct { @@ -51,13 +51,13 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Type_Code eru.UploadCode `json:"type_code"` - Name string `json:"name"` - FilePath *string `json:"filePath"` - FileName *string `json:"fileName"` - Upload_Employee_Id *uint `json:"upload_employee_id"` - Upload_Employee *ee.Employee `json:"upload_employee,omitempty"` + Encounter_Id *uint `json:"encounter_id"` + Type_Code eru.DocTypeCode `json:"type_code"` + Name string `json:"name"` + FilePath *string `json:"filePath"` + FileName *string `json:"fileName"` + Upload_Employee_Id *uint `json:"upload_employee_id"` + Upload_Employee *ee.Employee `json:"upload_employee,omitempty"` } func (d EncounterDocument) ToResponse() ResponseDto { diff --git a/internal/domain/main-entities/encounter-document/entity.go b/internal/domain/main-entities/encounter-document/entity.go index 6c98e1e2..b0b040fc 100644 --- a/internal/domain/main-entities/encounter-document/entity.go +++ b/internal/domain/main-entities/encounter-document/entity.go @@ -8,11 +8,11 @@ import ( type EncounterDocument struct { ecore.Main - Encounter_Id *uint `json:"encounter_id"` - Type_Code eru.UploadCode `json:"type_code"` - Name string `json:"name"` - FilePath *string `json:"filePath"` - FileName *string `json:"fileName"` - Upload_Employee_Id *uint `json:"upload_employee_id"` - Upload_Employee *ee.Employee `json:"upload_employee,omitempty" gorm:"foreignKey:Upload_Employee_Id;references:Id"` + Encounter_Id *uint `json:"encounter_id"` + Type_Code eru.DocTypeCode `json:"type_code"` + Name string `json:"name"` + FilePath *string `json:"filePath"` + FileName *string `json:"fileName"` + Upload_Employee_Id *uint `json:"upload_employee_id"` + Upload_Employee *ee.Employee `json:"upload_employee,omitempty" gorm:"foreignKey:Upload_Employee_Id;references:Id"` } diff --git a/internal/domain/main-entities/patient/dto.go b/internal/domain/main-entities/patient/dto.go index dd6c1f00..ec270abf 100644 --- a/internal/domain/main-entities/patient/dto.go +++ b/internal/domain/main-entities/patient/dto.go @@ -68,7 +68,7 @@ type SearchDto struct { type UploadDto struct { Id uint `json:"-"` - Code eru.UploadCode `json:"-"` + Code eru.DocTypeCode `json:"-"` File multipart.File `json:"-"` FileHeader *multipart.FileHeader `json:"-"` Filename string `json:"-"` diff --git a/internal/domain/main-entities/upload/dto.go b/internal/domain/main-entities/upload/dto.go index ca8e101b..445b1402 100644 --- a/internal/domain/main-entities/upload/dto.go +++ b/internal/domain/main-entities/upload/dto.go @@ -3,6 +3,7 @@ package upload import ( "mime/multipart" eru "simrs-vx/internal/domain/references/upload" + // internal - domain - base-entities ecore "simrs-vx/internal/domain/base-entities/core" ) @@ -10,7 +11,7 @@ import ( type CreateDto struct { EntityType_Code eru.EntityTypeCode `form:"entityType_code"` Ref_Id *uint `form:"ref_id"` - Type_Code eru.UploadCode `form:"type_code"` + Type_Code eru.DocTypeCode `form:"type_code"` Name string `form:"name"` Upload_Employee_Id *uint `form:"upload_employee_id"` FilePath string `json:"-"` @@ -31,7 +32,7 @@ type ReadListDto struct { type FilterDto struct { EntityType_Code eru.EntityTypeCode `json:"entityType-code"` Ref_Id *uint `json:"ref-id"` - Type_Code eru.UploadCode `json:"type-code"` + Type_Code eru.DocTypeCode `json:"type-code"` Name string `json:"name"` FilePath *string `json:"filePath"` FileName *string `json:"fileName"` @@ -61,7 +62,7 @@ type MetaDto struct { type ResponseDto struct { EntityType_Code eru.EntityTypeCode `json:"entityType_code"` Ref_Id *uint `json:"ref_id"` - Type_Code eru.UploadCode `json:"type_code"` + Type_Code eru.DocTypeCode `json:"type_code"` Name string `json:"name"` Upload_Employee_Id *uint `json:"upload_employee_id"` FilePath string `json:"filePath"` diff --git a/internal/domain/references/upload/upload.go b/internal/domain/references/upload/upload.go index b22960f4..0817e23c 100644 --- a/internal/domain/references/upload/upload.go +++ b/internal/domain/references/upload/upload.go @@ -3,40 +3,41 @@ package upload import "fmt" type ( - UploadCode string + DocTypeCode 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 - UCEnPatient UploadCode = "encounter-patient" - UCEnSupport UploadCode = "encounter-support" - UcEnOther UploadCode = "encounter-other" - UCSEP UploadCode = "vclaim-sep" // SEP - UCSIPP UploadCode = "vclaim-sipp" // SIPP + DTCPRN DocTypeCode = "person-resident-number" // Person Resident Number + DTCPDL DocTypeCode = "person-driver-license" // Person Driver License + DTCPP DocTypeCode = "person-passport" // Person Passport + DTCPFC DocTypeCode = "person-family-card" // Person Family Card + DTCMIR DocTypeCode = "mcu-item-result" // Mcu Item Result + DTCEnPatient DocTypeCode = "encounter-patient" + DTCEnSupport DocTypeCode = "encounter-support" + DTCEnOther DocTypeCode = "encounter-other" + DTCSEP DocTypeCode = "vclaim-sep" // SEP + DTCSIPP DocTypeCode = "vclaim-sipp" // SIPP + DTCGC DocTypeCode = "general-consent" ETCPerson EntityTypeCode = "person" ETCEncounter EntityTypeCode = "encounter" ETCMCU EntityTypeCode = "mcu" ) -var validUploadCodesByEntity = map[EntityTypeCode][]UploadCode{ +var validUploadCodesByEntity = map[EntityTypeCode][]DocTypeCode{ ETCPerson: { - UCPRN, UCPDL, UCPP, UCPFC, + DTCPRN, DTCPDL, DTCPP, DTCPFC, }, ETCEncounter: { - UCSEP, UCSIPP, UCEnPatient, UCEnSupport, UcEnOther, + DTCSEP, DTCSIPP, DTCEnPatient, DTCEnSupport, DTCEnOther, }, ETCMCU: { - UCMIR, + DTCMIR, }, } -func IsValidUploadCode(entity EntityTypeCode, code UploadCode) (bool, string) { +func IsValidUploadCode(entity EntityTypeCode, code DocTypeCode) (bool, string) { allowedCodes, ok := validUploadCodesByEntity[entity] if !ok { return false, fmt.Sprintf("unknown entityType_code: %s", entity) @@ -48,5 +49,5 @@ func IsValidUploadCode(entity EntityTypeCode, code UploadCode) (bool, string) { } } - return false, fmt.Sprintf("invalid upload_code '%s' for entityType_code '%s'", code, entity) + return false, fmt.Sprintf("invalid doctype_code '%s' for entityType_code '%s'", code, entity) } diff --git a/internal/interface/main-handler/upload/handler.go b/internal/interface/main-handler/upload/handler.go index 72a71fbf..8a09c9ae 100644 --- a/internal/interface/main-handler/upload/handler.go +++ b/internal/interface/main-handler/upload/handler.go @@ -52,7 +52,7 @@ func (obj myBase) Create(w http.ResponseWriter, r *http.Request) { dto := e.CreateDto{ EntityType_Code: eru.EntityTypeCode(r.FormValue("entityType_code")), Ref_Id: refID, - Type_Code: eru.UploadCode(r.FormValue("type_code")), + Type_Code: eru.DocTypeCode(r.FormValue("type_code")), Name: r.FormValue("name"), Upload_Employee_Id: employeeId, File: file, diff --git a/internal/use-case/main-use-case/upload/helper.go b/internal/use-case/main-use-case/upload/helper.go index e9e0ff29..1880676f 100644 --- a/internal/use-case/main-use-case/upload/helper.go +++ b/internal/use-case/main-use-case/upload/helper.go @@ -106,22 +106,22 @@ func setPersonAttachment(input e.CreateDto, event *pl.Event, tx *gorm.DB) (*ep.P var removeUrl string switch input.Type_Code { - case eru.UCPRN: + case eru.DTCPRN: if dataPerson.ResidentIdentityFileUrl != nil { removeUrl = *dataPerson.ResidentIdentityFileUrl } dataPerson.ResidentIdentityFileUrl = &input.FilePath - case eru.UCPDL: + case eru.DTCPDL: if dataPerson.DrivingLicenseFileUrl != nil { removeUrl = *dataPerson.DrivingLicenseFileUrl } dataPerson.DrivingLicenseFileUrl = &input.FilePath - case eru.UCPP: + case eru.DTCPP: if dataPerson.PassportFileUrl != nil { removeUrl = *dataPerson.PassportFileUrl } dataPerson.PassportFileUrl = &input.FilePath - case eru.UCPFC: + case eru.DTCPFC: if dataPerson.FamilyIdentityFileUrl != nil { removeUrl = *dataPerson.FamilyIdentityFileUrl } @@ -164,7 +164,7 @@ func setEncounterDocument(input e.CreateDto, event *pl.Event, tx *gorm.DB) (*ee. Upload_Employee_Id: input.Upload_Employee_Id, } - if input.Type_Code == eru.UCSEP || input.Type_Code == eru.UCSIPP { + if input.Type_Code == eru.DTCSEP || input.Type_Code == eru.DTCSIPP { if len(dataUpload) > 0 { data = dataUpload[0] diff --git a/pkg/upload-helper/upload-helper.go b/pkg/upload-helper/upload-helper.go index d6f1cd29..85f5448f 100644 --- a/pkg/upload-helper/upload-helper.go +++ b/pkg/upload-helper/upload-helper.go @@ -11,15 +11,15 @@ import ( func getBucketForType(docType string) (string, error) { switch strings.ToLower(docType) { case "resident", "resident-number", "ktp": - return string(ere.UCPRN), nil + return string(ere.DTCPRN), nil case "driver-license", "sim", "license": - return string(ere.UCPDL), nil + return string(ere.DTCPDL), nil case "passport", "paspor": - return string(ere.UCPP), nil + return string(ere.DTCPP), nil case "family-card", "kk", "family": - return string(ere.UCPFC), nil + return string(ere.DTCPFC), nil case "mcu", "medical", "mcu-result": - return string(ere.UCMIR), nil + return string(ere.DTCMIR), nil default: return "", fmt.Errorf("unknown document type: %s", docType) } @@ -28,9 +28,9 @@ func getBucketForType(docType string) (string, error) { // getValidFileTypesForBucket returns allowed file types for each bucket func getValidFileTypesForBucket(bucketName string) []string { switch bucketName { - case string(ere.UCPRN), string(ere.UCPDL), string(ere.UCPP), string(ere.UCPFC): + case string(ere.DTCPRN), string(ere.DTCPDL), string(ere.DTCPP), string(ere.DTCPFC): return []string{".jpg", ".jpeg", ".png", ".pdf", ".gif"} - case string(ere.UCMIR): + case string(ere.DTCMIR): return []string{".jpg", ".jpeg", ".png", ".pdf", ".gif", ".doc", ".docx", ".xls", ".xlsx"} default: return []string{".jpg", ".jpeg", ".png", ".pdf"} From 0bec4c3095c62f0f191e7e364f8799ae7ae6bf2d Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 17 Nov 2025 14:55:10 +0700 Subject: [PATCH 2/2] add fileUrl into general-consent --- cmd/main-migration/migrations/20251117075427.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 5 +++-- internal/domain/main-entities/general-consent/entity.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 cmd/main-migration/migrations/20251117075427.sql diff --git a/cmd/main-migration/migrations/20251117075427.sql b/cmd/main-migration/migrations/20251117075427.sql new file mode 100644 index 00000000..a6e0599b --- /dev/null +++ b/cmd/main-migration/migrations/20251117075427.sql @@ -0,0 +1,2 @@ +-- Modify "GeneralConsent" table +ALTER TABLE "public"."GeneralConsent" ADD COLUMN "FileUrl" character varying(1024) NULL; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index a6e1b68c..94a7b195 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:fNeqUpbdIqGDiH68u1bwwMgHTEOmmEWeI+IIYEq6pto= +h1:2JitBq/ClDO+w/9iPRmvv946fDfbSDFoHbpHL20aqNI= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -118,4 +118,5 @@ h1:fNeqUpbdIqGDiH68u1bwwMgHTEOmmEWeI+IIYEq6pto= 20251113101344.sql h1:xaOZvAUP1fFfnO+syEFOzJUIg5lTfBe5AWHPbBWuCLA= 20251113120533.sql h1:f3/U1Ve2yF2zSMhkt+xtwF8wUYfUKYwgbNeGfE37EW4= 20251114062746.sql h1:FInLaEFQByESEwFJKuKnuUSTKmcDpi3ZXaxkKwz2+D8= -20251117005942.sql h1:mW/TC8GgFgPLZ7PBVQnn9mChEekAcwfQMCbzXnoaw9w= +20251117005942.sql h1:wD3BWrUSmo1HlW16V3lkaBkJvbAZ0fNk77te7J9NhOc= +20251117075427.sql h1:/PZovLaMdWILT6y1uNuBo9EyMHyxp3vQ7BwndRpQriY= diff --git a/internal/domain/main-entities/general-consent/entity.go b/internal/domain/main-entities/general-consent/entity.go index 96758406..f5ce6394 100644 --- a/internal/domain/main-entities/general-consent/entity.go +++ b/internal/domain/main-entities/general-consent/entity.go @@ -10,4 +10,5 @@ type GeneralConsent struct { Encounter_Id *uint `json:"encounter_id" gorm:"not null"` Encounter *ee.Encounter `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"` Value *string `json:"value"` + FileUrl *string `json:"fileUrl" gorm:"size:1024"` }