245 lines
6.8 KiB
Go
245 lines
6.8 KiB
Go
package mapping
|
|||
|
|
|
||
|
|
import "fmt"
|
||
|
|
|
||
|
|
type Direction string
|
||
|
|
|
||
|
|
const (
|
||
|
|
DirectionPHISToOSI Direction = "phis_to_osi"
|
||
|
|
DirectionOSIToPHIS Direction = "osi_to_phis"
|
||
|
|
)
|
||
|
|
|
||
|
|
type ValidationError struct {
|
||
|
|
Field string
|
||
|
|
DictName string
|
||
|
|
Direction Direction
|
||
|
|
Code string
|
||
|
|
}
|
||
|
|
|
||
|
|
func (e ValidationError) Error() string {
|
||
|
|
return fmt.Sprintf("mapping %s %s unknown code %q for %s", e.DictName, e.Direction, e.Code, e.Field)
|
||
|
|
}
|
||
|
|
|
||
|
|
type Entry struct {
|
||
|
|
PHIS string
|
||
|
|
OSI string
|
||
|
|
Name string
|
||
|
|
}
|
||
|
|
|
||
|
|
type Dict struct {
|
||
|
|
Name string
|
||
|
|
Field string
|
||
|
|
Entries []Entry
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d Dict) PHISToOSI(code string) (string, error) {
|
||
|
|
for _, entry := range d.Entries {
|
||
|
|
if entry.PHIS == code {
|
||
|
|
return entry.OSI, nil
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return "", ValidationError{Field: d.Field, DictName: d.Name, Direction: DirectionPHISToOSI, Code: code}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d Dict) OSIToPHIS(code string) (string, error) {
|
||
|
|
for _, entry := range d.Entries {
|
||
|
|
if entry.OSI == code {
|
||
|
|
return entry.PHIS, nil
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return "", ValidationError{Field: d.Field, DictName: d.Name, Direction: DirectionOSIToPHIS, Code: code}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d Dict) EntryByOSI(code string) (Entry, bool) {
|
||
|
|
for _, entry := range d.Entries {
|
||
|
|
if entry.OSI == code {
|
||
|
|
return entry, true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return Entry{}, false
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d Dict) Len() int {
|
||
|
|
return len(d.Entries)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (d Dict) Validate() error {
|
||
|
|
phisSeen := make(map[string]bool, len(d.Entries))
|
||
|
|
osiSeen := make(map[string]bool, len(d.Entries))
|
||
|
|
for _, entry := range d.Entries {
|
||
|
|
if entry.PHIS == "" || entry.OSI == "" {
|
||
|
|
return fmt.Errorf("%s contains empty code: %#v", d.Name, entry)
|
||
|
|
}
|
||
|
|
if phisSeen[entry.PHIS] {
|
||
|
|
return fmt.Errorf("%s duplicate PHIS code %q", d.Name, entry.PHIS)
|
||
|
|
}
|
||
|
|
if osiSeen[entry.OSI] {
|
||
|
|
return fmt.Errorf("%s duplicate OSI code %q", d.Name, entry.OSI)
|
||
|
|
}
|
||
|
|
phisSeen[entry.PHIS] = true
|
||
|
|
osiSeen[entry.OSI] = true
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func sameCodeDict(name, field string, entries ...Entry) Dict {
|
||
|
|
for i := range entries {
|
||
|
|
if entries[i].PHIS == "" {
|
||
|
|
entries[i].PHIS = entries[i].OSI
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return Dict{Name: name, Field: field, Entries: entries}
|
||
|
|
}
|
||
|
|
|
||
|
|
var SexDict = sameCodeDict("sex", "sexCode",
|
||
|
|
Entry{OSI: "0", Name: "未知"},
|
||
|
|
Entry{OSI: "1", Name: "男"},
|
||
|
|
Entry{OSI: "2", Name: "女"},
|
||
|
|
Entry{OSI: "9", Name: "未说明"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var BloodTypeDict = sameCodeDict("bloodType", "bloodTypeCode",
|
||
|
|
Entry{OSI: "1", Name: "A"},
|
||
|
|
Entry{OSI: "2", Name: "B"},
|
||
|
|
Entry{OSI: "3", Name: "O"},
|
||
|
|
Entry{OSI: "4", Name: "AB"},
|
||
|
|
Entry{OSI: "5", Name: "不详"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var RhBloodDict = sameCodeDict("rhBlood", "rhBloodCode",
|
||
|
|
Entry{OSI: "1", Name: "阳性"},
|
||
|
|
Entry{OSI: "2", Name: "阴性"},
|
||
|
|
Entry{OSI: "3", Name: "不详"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var EducationDict = sameCodeDict("education", "educationCode",
|
||
|
|
Entry{OSI: "10", Name: "研究生"},
|
||
|
|
Entry{OSI: "20", Name: "本科"},
|
||
|
|
Entry{OSI: "31", Name: "大专"},
|
||
|
|
Entry{OSI: "41", Name: "中专"},
|
||
|
|
Entry{OSI: "47", Name: "技校"},
|
||
|
|
Entry{OSI: "60", Name: "高中"},
|
||
|
|
Entry{OSI: "70", Name: "初中"},
|
||
|
|
Entry{OSI: "80", Name: "小学"},
|
||
|
|
Entry{OSI: "90", Name: "文盲"},
|
||
|
|
Entry{OSI: "91", Name: "不详"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var WorkDict = sameCodeDict("work", "workCode",
|
||
|
|
Entry{OSI: "0", Name: "负责人"},
|
||
|
|
Entry{OSI: "1", Name: "专业技术人员"},
|
||
|
|
Entry{OSI: "2", Name: "专业技术人员"},
|
||
|
|
Entry{OSI: "3", Name: "办事人员"},
|
||
|
|
Entry{OSI: "4", Name: "商业服务业人员"},
|
||
|
|
Entry{OSI: "5", Name: "农林牧渔人员"},
|
||
|
|
Entry{OSI: "9", Name: "生产运输人员"},
|
||
|
|
Entry{OSI: "X", Name: "军人"},
|
||
|
|
Entry{OSI: "Y", Name: "其他"},
|
||
|
|
Entry{OSI: "8", Name: "无职业"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var MaritalStatusDict = sameCodeDict("maritalStatus", "maritalStatusCode",
|
||
|
|
Entry{OSI: "10", Name: "未婚"},
|
||
|
|
Entry{OSI: "20", Name: "已婚"},
|
||
|
|
Entry{OSI: "30", Name: "丧偶"},
|
||
|
|
Entry{OSI: "40", Name: "离婚"},
|
||
|
|
Entry{OSI: "90", Name: "未说明"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var InsuranceDict = sameCodeDict("insurance", "insuranceCode",
|
||
|
|
Entry{OSI: "01", Name: "城镇职工"},
|
||
|
|
Entry{OSI: "02", Name: "城乡居民"},
|
||
|
|
Entry{OSI: "04", Name: "贫困救助"},
|
||
|
|
Entry{OSI: "05", Name: "商业"},
|
||
|
|
Entry{OSI: "06", Name: "全公费"},
|
||
|
|
Entry{OSI: "07", Name: "全自费"},
|
||
|
|
Entry{OSI: "99", Name: "其他"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var PersonSignDict = sameCodeDict("personSign", "personSign",
|
||
|
|
Entry{OSI: "PU", Name: "普通"},
|
||
|
|
Entry{OSI: "GRQY", Name: "已签约"},
|
||
|
|
Entry{OSI: "LAO", Name: "老年"},
|
||
|
|
Entry{OSI: "GAO", Name: "高血压"},
|
||
|
|
Entry{OSI: "TANG", Name: "糖尿病"},
|
||
|
|
Entry{OSI: "FU", Name: "孕产妇"},
|
||
|
|
Entry{OSI: "ER", Name: "儿童"},
|
||
|
|
Entry{OSI: "FEI", Name: "肺结核"},
|
||
|
|
Entry{OSI: "JING", Name: "精神障碍"},
|
||
|
|
Entry{OSI: "CAN", Name: "残疾"},
|
||
|
|
)
|
||
|
|
|
||
|
|
var NationDict = sameCodeDict("nation", "nationCode",
|
||
|
|
Entry{OSI: "01", Name: "汉族"},
|
||
|
|
Entry{OSI: "02", Name: "蒙古族"},
|
||
|
|
Entry{OSI: "03", Name: "回族"},
|
||
|
|
Entry{OSI: "04", Name: "藏族"},
|
||
|
|
Entry{OSI: "05", Name: "维吾尔族"},
|
||
|
|
Entry{OSI: "06", Name: "苗族"},
|
||
|
|
Entry{OSI: "07", Name: "彝族"},
|
||
|
|
Entry{OSI: "08", Name: "壮族"},
|
||
|
|
Entry{OSI: "09", Name: "布依族"},
|
||
|
|
Entry{OSI: "10", Name: "朝鲜族"},
|
||
|
|
Entry{OSI: "11", Name: "满族"},
|
||
|
|
Entry{OSI: "12", Name: "侗族"},
|
||
|
|
Entry{OSI: "13", Name: "瑶族"},
|
||
|
|
Entry{OSI: "14", Name: "白族"},
|
||
|
|
Entry{OSI: "15", Name: "土家族"},
|
||
|
|
Entry{OSI: "16", Name: "哈尼族"},
|
||
|
|
Entry{OSI: "17", Name: "哈萨克族"},
|
||
|
|
Entry{OSI: "18", Name: "傣族"},
|
||
|
|
Entry{OSI: "19", Name: "黎族"},
|
||
|
|
Entry{OSI: "20", Name: "傈僳族"},
|
||
|
|
Entry{OSI: "21", Name: "佤族"},
|
||
|
|
Entry{OSI: "22", Name: "畲族"},
|
||
|
|
Entry{OSI: "23", Name: "高山族"},
|
||
|
|
Entry{OSI: "24", Name: "拉祜族"},
|
||
|
|
Entry{OSI: "25", Name: "水族"},
|
||
|
|
Entry{OSI: "26", Name: "东乡族"},
|
||
|
|
Entry{OSI: "27", Name: "纳西族"},
|
||
|
|
Entry{OSI: "28", Name: "景颇族"},
|
||
|
|
Entry{OSI: "29", Name: "柯尔克孜族"},
|
||
|
|
Entry{OSI: "30", Name: "土族"},
|
||
|
|
Entry{OSI: "31", Name: "达斡尔族"},
|
||
|
|
Entry{OSI: "32", Name: "仫佬族"},
|
||
|
|
Entry{OSI: "33", Name: "羌族"},
|
||
|
|
Entry{OSI: "34", Name: "布朗族"},
|
||
|
|
Entry{OSI: "35", Name: "撒拉族"},
|
||
|
|
Entry{OSI: "36", Name: "毛南族"},
|
||
|
|
Entry{OSI: "37", Name: "仡佬族"},
|
||
|
|
Entry{OSI: "38", Name: "锡伯族"},
|
||
|
|
Entry{OSI: "39", Name: "阿昌族"},
|
||
|
|
Entry{OSI: "40", Name: "普米族"},
|
||
|
|
Entry{OSI: "41", Name: "塔吉克族"},
|
||
|
|
Entry{OSI: "42", Name: "怒族"},
|
||
|
|
Entry{OSI: "43", Name: "乌孜别克族"},
|
||
|
|
Entry{OSI: "44", Name: "俄罗斯族"},
|
||
|
|
Entry{OSI: "45", Name: "鄂温克族"},
|
||
|
|
Entry{OSI: "46", Name: "德昂族"},
|
||
|
|
Entry{OSI: "47", Name: "保安族"},
|
||
|
|
Entry{OSI: "48", Name: "裕固族"},
|
||
|
|
Entry{OSI: "49", Name: "京族"},
|
||
|
|
Entry{OSI: "50", Name: "塔塔尔族"},
|
||
|
|
Entry{OSI: "51", Name: "独龙族"},
|
||
|
|
Entry{OSI: "52", Name: "鄂伦春族"},
|
||
|
|
Entry{OSI: "53", Name: "赫哲族"},
|
||
|
|
Entry{OSI: "54", Name: "门巴族"},
|
||
|
|
Entry{OSI: "55", Name: "珞巴族"},
|
||
|
|
Entry{OSI: "56", Name: "基诺族"},
|
||
|
|
Entry{OSI: "99", Name: "其他"},
|
||
|
|
)
|
||
|
|
|
||
|
|
func AllDicts() []Dict {
|
||
|
|
return []Dict{
|
||
|
|
SexDict,
|
||
|
|
BloodTypeDict,
|
||
|
|
RhBloodDict,
|
||
|
|
EducationDict,
|
||
|
|
WorkDict,
|
||
|
|
MaritalStatusDict,
|
||
|
|
InsuranceDict,
|
||
|
|
NationDict,
|
||
|
|
PersonSignDict,
|
||
|
|
}
|
||
|
|
}
|