refactor (upload-file)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package encounter_document
|
||||
|
||||
import (
|
||||
eru "simrs-vx/internal/domain/references/upload"
|
||||
ere "simrs-vx/internal/domain/references/encounter"
|
||||
// internal - domain - base-entities
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
type CreateDto struct {
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Type_Code eru.DocTypeCode `json:"type_code"`
|
||||
Type_Code ere.DocTypeCode `json:"type_code"`
|
||||
Name string `json:"name"`
|
||||
FilePath string `json:"filePath"`
|
||||
Filename string `json:"-"`
|
||||
@@ -25,7 +25,7 @@ type ReadListDto struct {
|
||||
|
||||
type FilterDto struct {
|
||||
Encounter_Id *uint `json:"encounter-id"`
|
||||
Type_Code eru.DocTypeCode `json:"type-code"`
|
||||
Type_Code ere.DocTypeCode `json:"type-code"`
|
||||
Upload_Employee_Id *string `json:"encounter-document-employee-id"`
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ type MetaDto struct {
|
||||
type ResponseDto struct {
|
||||
ecore.Main
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Type_Code eru.DocTypeCode `json:"type_code"`
|
||||
Type_Code ere.DocTypeCode `json:"type_code"`
|
||||
Name string `json:"name"`
|
||||
FilePath *string `json:"filePath"`
|
||||
FileName *string `json:"fileName"`
|
||||
|
||||
@@ -3,13 +3,13 @@ package encounter_document
|
||||
import (
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
ee "simrs-vx/internal/domain/main-entities/employee"
|
||||
eru "simrs-vx/internal/domain/references/upload"
|
||||
ere "simrs-vx/internal/domain/references/encounter"
|
||||
)
|
||||
|
||||
type EncounterDocument struct {
|
||||
ecore.Main
|
||||
Encounter_Id *uint `json:"encounter_id"`
|
||||
Type_Code eru.DocTypeCode `json:"type_code"`
|
||||
Type_Code ere.DocTypeCode `json:"type_code"`
|
||||
Name string `json:"name"`
|
||||
FilePath *string `json:"filePath"`
|
||||
FileName *string `json:"fileName"`
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
epr "simrs-vx/internal/domain/main-entities/person-relative"
|
||||
|
||||
erc "simrs-vx/internal/domain/references/common"
|
||||
eru "simrs-vx/internal/domain/references/upload"
|
||||
ere "simrs-vx/internal/domain/references/encounter"
|
||||
|
||||
pa "simrs-vx/internal/lib/auth"
|
||||
)
|
||||
@@ -68,7 +68,7 @@ type SearchDto struct {
|
||||
|
||||
type UploadDto struct {
|
||||
Id uint `json:"-"`
|
||||
Code eru.DocTypeCode `json:"-"`
|
||||
Code ere.DocTypeCode `json:"-"`
|
||||
File multipart.File `json:"-"`
|
||||
FileHeader *multipart.FileHeader `json:"-"`
|
||||
Filename string `json:"-"`
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package upload
|
||||
|
||||
import (
|
||||
"mime/multipart"
|
||||
eru "simrs-vx/internal/domain/references/upload"
|
||||
|
||||
// internal - domain - base-entities
|
||||
ecore "simrs-vx/internal/domain/base-entities/core"
|
||||
)
|
||||
|
||||
type CreateDto struct {
|
||||
EntityType_Code eru.EntityTypeCode `form:"entityType_code"`
|
||||
Ref_Id *uint `form:"ref_id"`
|
||||
Type_Code eru.DocTypeCode `form:"type_code"`
|
||||
Name string `form:"name"`
|
||||
Upload_Employee_Id *uint `form:"upload_employee_id"`
|
||||
FilePath string `json:"-"`
|
||||
|
||||
File multipart.File `json:"-"`
|
||||
FileHeader *multipart.FileHeader `json:"-"`
|
||||
Filename string `json:"filename"`
|
||||
Size int64 `json:"-"`
|
||||
MimeType string `json:"-"`
|
||||
}
|
||||
|
||||
type ReadListDto struct {
|
||||
FilterDto
|
||||
Includes string `json:"includes"`
|
||||
Pagination ecore.Pagination
|
||||
}
|
||||
|
||||
type FilterDto struct {
|
||||
EntityType_Code eru.EntityTypeCode `json:"entityType-code"`
|
||||
Ref_Id *uint `json:"ref-id"`
|
||||
Type_Code eru.DocTypeCode `json:"type-code"`
|
||||
Name string `json:"name"`
|
||||
FilePath *string `json:"filePath"`
|
||||
FileName *string `json:"fileName"`
|
||||
Upload_Employee_Id *string `json:"encounter-document-employee-id"`
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Includes string `json:"includes"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
CreateDto
|
||||
}
|
||||
|
||||
type DeleteDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
}
|
||||
|
||||
type MetaDto struct {
|
||||
PageNumber int `json:"page_number"`
|
||||
PageSize int `json:"page_size"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type ResponseDto struct {
|
||||
EntityType_Code eru.EntityTypeCode `json:"entityType_code"`
|
||||
Ref_Id *uint `json:"ref_id"`
|
||||
Type_Code eru.DocTypeCode `json:"type_code"`
|
||||
Name string `json:"name"`
|
||||
Upload_Employee_Id *uint `json:"upload_employee_id"`
|
||||
FilePath string `json:"filePath"`
|
||||
Filename string `json:"filename"`
|
||||
FileHeader *multipart.FileHeader `json:"fileHeader"`
|
||||
Size int64 `json:"size"`
|
||||
MimeType string `json:"mimeType"`
|
||||
}
|
||||
|
||||
func (d CreateDto) ToResponse() ResponseDto {
|
||||
resp := ResponseDto{
|
||||
EntityType_Code: d.EntityType_Code,
|
||||
Ref_Id: d.Ref_Id,
|
||||
Type_Code: d.Type_Code,
|
||||
Name: d.Name,
|
||||
Upload_Employee_Id: d.Upload_Employee_Id,
|
||||
FilePath: d.FilePath,
|
||||
Filename: d.Filename,
|
||||
FileHeader: d.FileHeader,
|
||||
Size: d.Size,
|
||||
MimeType: d.MimeType,
|
||||
}
|
||||
return resp
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package encounter
|
||||
|
||||
import "fmt"
|
||||
|
||||
type (
|
||||
EncounterClassCode string
|
||||
QueueStatusCode string
|
||||
@@ -18,6 +20,8 @@ type (
|
||||
SEPRefTypeCode string
|
||||
VisitModeCode string
|
||||
PolySwitchCode string
|
||||
DocTypeCode string
|
||||
EntityTypeCode string
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -104,6 +108,22 @@ const (
|
||||
|
||||
PSCConsulPoly PolySwitchCode = "consul-poly" // Konsultasi Poliklinik Lain
|
||||
PSCConsulExecutive PolySwitchCode = "consul-executive" // Konsultasi Antar Dokter Eksekutif
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
func (ec EncounterClassCode) Code() string {
|
||||
@@ -118,3 +138,30 @@ func (ec EncounterClassCode) Code() string {
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
var validUploadCodesByEntity = map[EntityTypeCode][]DocTypeCode{
|
||||
ETCPerson: {
|
||||
DTCPRN, DTCPDL, DTCPP, DTCPFC,
|
||||
},
|
||||
ETCEncounter: {
|
||||
DTCSEP, DTCSIPP, DTCEnPatient, DTCEnSupport, DTCGC, DTCEnOther,
|
||||
},
|
||||
ETCMCU: {
|
||||
DTCMIR,
|
||||
},
|
||||
}
|
||||
|
||||
func IsValidUploadCode(entity EntityTypeCode, code DocTypeCode) (bool, string) {
|
||||
allowedCodes, ok := validUploadCodesByEntity[entity]
|
||||
if !ok {
|
||||
return false, fmt.Sprintf("unknown entityType_code: %s", entity)
|
||||
}
|
||||
|
||||
for _, c := range allowedCodes {
|
||||
if c == code {
|
||||
return true, ""
|
||||
}
|
||||
}
|
||||
|
||||
return false, fmt.Sprintf("invalid doctype_code '%s' for entityType_code '%s'", code, entity)
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package upload
|
||||
|
||||
import "fmt"
|
||||
|
||||
type (
|
||||
DocTypeCode string
|
||||
EntityTypeCode string
|
||||
)
|
||||
|
||||
const (
|
||||
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][]DocTypeCode{
|
||||
ETCPerson: {
|
||||
DTCPRN, DTCPDL, DTCPP, DTCPFC,
|
||||
},
|
||||
ETCEncounter: {
|
||||
DTCSEP, DTCSIPP, DTCEnPatient, DTCEnSupport, DTCEnOther,
|
||||
},
|
||||
ETCMCU: {
|
||||
DTCMIR,
|
||||
},
|
||||
}
|
||||
|
||||
func IsValidUploadCode(entity EntityTypeCode, code DocTypeCode) (bool, string) {
|
||||
allowedCodes, ok := validUploadCodesByEntity[entity]
|
||||
if !ok {
|
||||
return false, fmt.Sprintf("unknown entityType_code: %s", entity)
|
||||
}
|
||||
|
||||
for _, c := range allowedCodes {
|
||||
if c == code {
|
||||
return true, ""
|
||||
}
|
||||
}
|
||||
|
||||
return false, fmt.Sprintf("invalid doctype_code '%s' for entityType_code '%s'", code, entity)
|
||||
}
|
||||
Reference in New Issue
Block a user