refactor (upload-file)

This commit is contained in:
dpurbosakti
2025-11-17 15:20:24 +07:00
parent cde7636639
commit 05f54e4e34
17 changed files with 169 additions and 379 deletions
@@ -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)
}