2026-07-07 14:36:40 +08:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
|
|
type PHISHealthRecord struct {
|
|
|
|
|
SourceSystem string
|
|
|
|
|
SourceRecordID string
|
|
|
|
|
UpdatedAt string
|
|
|
|
|
IDCard string
|
|
|
|
|
PersonName string
|
|
|
|
|
SexCode string
|
|
|
|
|
Birthday string
|
|
|
|
|
MobileNumber string
|
|
|
|
|
RegionCode string
|
2026-07-07 21:16:52 +08:00
|
|
|
RegionName string
|
2026-07-07 14:36:40 +08:00
|
|
|
ManaDoctorID string
|
2026-07-07 21:16:52 +08:00
|
|
|
ManaDoctorName string
|
2026-07-07 14:36:40 +08:00
|
|
|
ManaUnitID string
|
2026-07-07 21:16:52 +08:00
|
|
|
ManaUnitName string
|
2026-07-07 14:36:40 +08:00
|
|
|
NationCode string
|
|
|
|
|
EducationCode string
|
|
|
|
|
WorkCode string
|
|
|
|
|
MaritalStatusCode string
|
|
|
|
|
BloodTypeCode string
|
|
|
|
|
RhBloodCode string
|
|
|
|
|
InsuranceCode string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type MappedHealthRecord struct {
|
|
|
|
|
CheckID string
|
|
|
|
|
IDCard string
|
|
|
|
|
PersonName string
|
|
|
|
|
SexCode string
|
|
|
|
|
Birthday string
|
|
|
|
|
MobileNumber string
|
|
|
|
|
RegionCode string
|
|
|
|
|
ManaDoctorID string
|
|
|
|
|
ManaUnitID string
|
|
|
|
|
NationCode string
|
|
|
|
|
EducationCode string
|
|
|
|
|
WorkCode string
|
|
|
|
|
MaritalStatusCode string
|
|
|
|
|
BloodTypeCode string
|
|
|
|
|
RhBloodCode string
|
|
|
|
|
InsuranceCode string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DictSnapshot struct {
|
|
|
|
|
Sex Dict
|
|
|
|
|
Nation Dict
|
|
|
|
|
Education Dict
|
|
|
|
|
Work Dict
|
|
|
|
|
MaritalStatus Dict
|
|
|
|
|
BloodType Dict
|
|
|
|
|
RhBlood Dict
|
|
|
|
|
Insurance Dict
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 21:16:52 +08:00
|
|
|
type MasterDataLookup interface {
|
|
|
|
|
RegionCodeByName(name string) (string, bool)
|
|
|
|
|
DoctorIDByName(name string) (string, bool)
|
|
|
|
|
ManaUnitIDByName(name string) (string, bool)
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 14:36:40 +08:00
|
|
|
type MapContext struct {
|
2026-07-07 21:16:52 +08:00
|
|
|
Dicts DictSnapshot
|
|
|
|
|
MasterData MasterDataLookup
|
2026-07-07 14:36:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func DefaultDictSnapshot() DictSnapshot {
|
|
|
|
|
return DictSnapshot{
|
|
|
|
|
Sex: SexDict,
|
|
|
|
|
Nation: NationDict,
|
|
|
|
|
Education: EducationDict,
|
|
|
|
|
Work: WorkDict,
|
|
|
|
|
MaritalStatus: MaritalStatusDict,
|
|
|
|
|
BloodType: BloodTypeDict,
|
|
|
|
|
RhBlood: RhBloodDict,
|
|
|
|
|
Insurance: InsuranceDict,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func MapHealthRecord(src PHISHealthRecord, ctx MapContext) (MappedHealthRecord, []ValidationError) {
|
|
|
|
|
if ctx.Dicts.Sex.Name == "" {
|
|
|
|
|
ctx.Dicts = DefaultDictSnapshot()
|
|
|
|
|
}
|
2026-07-07 21:16:52 +08:00
|
|
|
resolveMasterData(&src, ctx.MasterData)
|
2026-07-07 14:36:40 +08:00
|
|
|
var errs []ValidationError
|
|
|
|
|
for _, field := range []struct {
|
|
|
|
|
name string
|
|
|
|
|
value string
|
|
|
|
|
}{
|
|
|
|
|
{name: "idCard", value: src.IDCard},
|
|
|
|
|
{name: "personName", value: src.PersonName},
|
|
|
|
|
{name: "sexCode", value: src.SexCode},
|
|
|
|
|
{name: "birthday", value: src.Birthday},
|
|
|
|
|
{name: "mobileNumber", value: src.MobileNumber},
|
|
|
|
|
{name: "regionCode", value: src.RegionCode},
|
|
|
|
|
{name: "manaDoctorId", value: src.ManaDoctorID},
|
|
|
|
|
{name: "manaUnitId", value: src.ManaUnitID},
|
|
|
|
|
} {
|
|
|
|
|
if field.value == "" {
|
|
|
|
|
errs = append(errs, ValidationError{Field: field.name, Reason: "required"})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapped := MappedHealthRecord{
|
|
|
|
|
CheckID: GenerateCheckID(src.SourceSystem, "JKDA", src.SourceRecordID, src.UpdatedAt),
|
|
|
|
|
IDCard: src.IDCard,
|
|
|
|
|
PersonName: src.PersonName,
|
|
|
|
|
Birthday: src.Birthday,
|
|
|
|
|
MobileNumber: src.MobileNumber,
|
|
|
|
|
RegionCode: src.RegionCode,
|
|
|
|
|
ManaDoctorID: src.ManaDoctorID,
|
|
|
|
|
ManaUnitID: src.ManaUnitID,
|
|
|
|
|
}
|
|
|
|
|
mapped.SexCode = mapCode(ctx.Dicts.Sex, src.SexCode, &errs)
|
|
|
|
|
mapped.NationCode = mapCode(ctx.Dicts.Nation, src.NationCode, &errs)
|
|
|
|
|
mapped.EducationCode = mapCode(ctx.Dicts.Education, src.EducationCode, &errs)
|
|
|
|
|
mapped.WorkCode = mapCode(ctx.Dicts.Work, src.WorkCode, &errs)
|
|
|
|
|
mapped.MaritalStatusCode = mapCode(ctx.Dicts.MaritalStatus, src.MaritalStatusCode, &errs)
|
|
|
|
|
mapped.BloodTypeCode = mapCode(ctx.Dicts.BloodType, src.BloodTypeCode, &errs)
|
|
|
|
|
mapped.RhBloodCode = mapCode(ctx.Dicts.RhBlood, src.RhBloodCode, &errs)
|
|
|
|
|
mapped.InsuranceCode = mapCode(ctx.Dicts.Insurance, src.InsuranceCode, &errs)
|
|
|
|
|
return mapped, errs
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 21:16:52 +08:00
|
|
|
func resolveMasterData(src *PHISHealthRecord, lookup MasterDataLookup) {
|
|
|
|
|
if lookup == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if src.RegionCode == "" && src.RegionName != "" {
|
|
|
|
|
if code, ok := lookup.RegionCodeByName(src.RegionName); ok {
|
|
|
|
|
src.RegionCode = code
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if src.ManaDoctorID == "" && src.ManaDoctorName != "" {
|
|
|
|
|
if code, ok := lookup.DoctorIDByName(src.ManaDoctorName); ok {
|
|
|
|
|
src.ManaDoctorID = code
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if src.ManaUnitID == "" && src.ManaUnitName != "" {
|
|
|
|
|
if code, ok := lookup.ManaUnitIDByName(src.ManaUnitName); ok {
|
|
|
|
|
src.ManaUnitID = code
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-07-07 14:36:40 +08:00
|
|
|
func mapCode(dict Dict, code string, errs *[]ValidationError) string {
|
|
|
|
|
if code == "" {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
mapped, err := dict.PHISToOSI(code)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if validationErr, ok := err.(ValidationError); ok {
|
|
|
|
|
*errs = append(*errs, validationErr)
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
*errs = append(*errs, ValidationError{Field: dict.Field, Code: code, Reason: err.Error()})
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
return mapped
|
|
|
|
|
}
|