package mapping import ( "reflect" "testing" ) func TestDocxStyleHealthRecordMappingBaseline(t *testing.T) { src := PHISHealthRecord{ SourceSystem: "PHIS", SourceRecordID: "docx-sample-001", UpdatedAt: "20260707100000", IDCard: "440000********0001", PersonName: "文档样例", SexCode: "2", Birthday: "1988-08-08", MobileNumber: "13800000001", RegionCode: "441625000000", ManaDoctorID: "D100", ManaUnitID: "123456789", NationCode: "01", EducationCode: "20", WorkCode: "4", MaritalStatusCode: "10", BloodTypeCode: "3", RhBloodCode: "3", InsuranceCode: "02", } got, errs := MapHealthRecord(src, MapContext{Dicts: DefaultDictSnapshot()}) if len(errs) != 0 { t.Fatalf("errors = %#v", errs) } assertMappedBaseline(t, got, MappedHealthRecord{ CheckID: GenerateCheckID("PHIS", "JKDA", "docx-sample-001"), IDCard: "440000********0001", PersonName: "文档样例", SexCode: "2", Birthday: "1988-08-08", MobileNumber: "13800000001", RegionCode: "441625000000", ManaDoctorID: "D100", ManaUnitID: "123456789", NationCode: "01", EducationCode: "20", WorkCode: "4", MaritalStatusCode: "10", BloodTypeCode: "3", RhBloodCode: "3", InsuranceCode: "02", }) } func TestJointDebugStyleHealthRecordMappingBaseline(t *testing.T) { src := PHISHealthRecord{ SourceSystem: "PHIS", SourceRecordID: "joint-debug-001", UpdatedAt: "20260707110000", IDCard: "440000********1234", PersonName: "联调样例", SexCode: "1", Birthday: "1970-01-01", MobileNumber: "13900000000", RegionCode: "441625000000", ManaDoctorID: "D001", ManaUnitID: "123456789", NationCode: "01", EducationCode: "31", WorkCode: "Y", MaritalStatusCode: "20", BloodTypeCode: "4", RhBloodCode: "1", InsuranceCode: "01", } got, errs := MapHealthRecord(src, MapContext{Dicts: DefaultDictSnapshot()}) if len(errs) != 0 { t.Fatalf("errors = %#v", errs) } if got.CheckID != GenerateCheckID("PHIS", "JKDA", "joint-debug-001") { t.Fatalf("checkId = %q", got.CheckID) } if got.IDCard != "440000********1234" || got.PersonName != "联调样例" || got.NationCode != "01" || got.WorkCode != "Y" { t.Fatalf("mapped = %#v", got) } } func TestHealthRecordMappingBaselineRejectsDirtySample(t *testing.T) { src := PHISHealthRecord{ SourceSystem: "PHIS", SourceRecordID: "dirty-001", UpdatedAt: "20260707120000", IDCard: "", PersonName: "脏数据样例", SexCode: "9", Birthday: "1970-01-01", MobileNumber: "", RegionCode: "441625000000", ManaDoctorID: "D001", ManaUnitID: "123456789", NationCode: "98", EducationCode: "31", WorkCode: "Y", MaritalStatusCode: "20", BloodTypeCode: "4", RhBloodCode: "1", InsuranceCode: "88", } _, errs := MapHealthRecord(src, MapContext{Dicts: DefaultDictSnapshot()}) assertValidationField(t, errs, "idCard", "required") assertValidationField(t, errs, "mobileNumber", "required") assertValidationCode(t, errs, "nationCode", "98") assertValidationCode(t, errs, "insuranceCode", "88") } func assertMappedBaseline(t *testing.T, got MappedHealthRecord, want MappedHealthRecord) { t.Helper() if !reflect.DeepEqual(got, want) { t.Fatalf("mapped = %#v\nwant = %#v", got, want) } } func assertValidationCode(t *testing.T, errs []ValidationError, field string, code string) { t.Helper() for _, err := range errs { if err.Field == field && err.Code == code { return } } t.Fatalf("missing validation error field=%s code=%s in %#v", field, code, errs) }