feat(contract): 建立 JKDA 查询响应契约(T-201)
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package contract
|
||||
|
||||
type FindHealthRecordResponse struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data []FindHealthRecord `json:"data"`
|
||||
}
|
||||
|
||||
// FindHealthRecord is one JKDA00002 data item: a health record aggregate returned by OSI.
|
||||
type FindHealthRecord struct {
|
||||
HealthRecord HealthRecord `json:"healthRecord"`
|
||||
PastHistory *PastHistory `json:"pastHistory,omitempty"`
|
||||
PastDiseases []PastDisease `json:"jwsjb,omitempty"`
|
||||
PastSurgeries []PastSurgery `json:"jwsss,omitempty"`
|
||||
PastTraumas []PastTrauma `json:"jwsws,omitempty"`
|
||||
PastTransfusions []PastBloodTx `json:"jwssx,omitempty"`
|
||||
FamilyMiddle *FamilyMiddle `json:"familyMiddle,omitempty"`
|
||||
}
|
||||
|
||||
type HealthRecord struct {
|
||||
IDCard string `json:"idCard,omitempty"`
|
||||
PersonName string `json:"personName,omitempty"`
|
||||
SexCode string `json:"sexCode,omitempty"`
|
||||
Birthday string `json:"birthday,omitempty"`
|
||||
PhrID string `json:"phrId,omitempty"`
|
||||
EmpiID string `json:"empiId,omitempty"`
|
||||
CheckID *string `json:"checkId,omitempty"`
|
||||
ManaUnitID string `json:"manaUnitId,omitempty"`
|
||||
CreateUnit string `json:"createUnit,omitempty"`
|
||||
ManaDoctorID string `json:"manaDoctorId,omitempty"`
|
||||
CreateUser string `json:"createUser,omitempty"`
|
||||
RegionCode string `json:"regionCode,omitempty"`
|
||||
AddressCode string `json:"addressCode,omitempty"`
|
||||
HomePlaceCode string `json:"homePlaceCode,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
AdressNumber string `json:"adressNumber,omitempty"`
|
||||
HomePlace string `json:"homePlace,omitempty"`
|
||||
HomePlaceNumber string `json:"homePlaceNumber,omitempty"`
|
||||
NationCode string `json:"nationCode,omitempty"`
|
||||
EducationCode string `json:"educationCode,omitempty"`
|
||||
WorkCode string `json:"workCode,omitempty"`
|
||||
MaritalStatusCode string `json:"maritalStatusCode,omitempty"`
|
||||
BloodTypeCode string `json:"bloodTypeCode,omitempty"`
|
||||
RhBloodCode string `json:"rhBloodCode,omitempty"`
|
||||
InsuranceCode string `json:"insuranceCode,omitempty"`
|
||||
InsuranceType *string `json:"insuranceType,omitempty"`
|
||||
PersonGroup string `json:"personGroup,omitempty"`
|
||||
OtherPersonGroup *string `json:"otherPersonGroup,omitempty"`
|
||||
IsFillSHHJ string `json:"isFillShhj,omitempty"`
|
||||
Contact string `json:"contact,omitempty"`
|
||||
ContactPhone string `json:"contactPhone,omitempty"`
|
||||
MobileNumber string `json:"mobileNumber,omitempty"`
|
||||
PhoneNumber string `json:"phoneNumber,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
CreateDate string `json:"createDate,omitempty"`
|
||||
}
|
||||
|
||||
type PastHistory struct {
|
||||
YWGMS string `json:"ywgms,omitempty"`
|
||||
JWSJB string `json:"jwsjb,omitempty"`
|
||||
BLS string `json:"bls,omitempty"`
|
||||
YCBS string `json:"ycbs,omitempty"`
|
||||
CJQK string `json:"cjqk,omitempty"`
|
||||
JZSFQN string `json:"jzsfqn,omitempty"`
|
||||
JZSMQ string `json:"jzsmq,omitempty"`
|
||||
JZSZN string `json:"jzszn,omitempty"`
|
||||
JZSXDJM string `json:"jzsxdjm,omitempty"`
|
||||
}
|
||||
|
||||
type PastDisease struct {
|
||||
Code string `json:"jwsjbcode,omitempty"`
|
||||
Name string `json:"jwsjbmc,omitempty"`
|
||||
ConfirmedDate string `json:"jwsjbqzsj,omitempty"`
|
||||
}
|
||||
|
||||
type PastSurgery struct {
|
||||
Code string `json:"jwssscode,omitempty"`
|
||||
Name string `json:"jwsssmc,omitempty"`
|
||||
ConfirmedDate string `json:"jwsssqzsj,omitempty"`
|
||||
}
|
||||
|
||||
type PastTrauma struct {
|
||||
Code string `json:"jwswscode,omitempty"`
|
||||
Name string `json:"jwswsmc,omitempty"`
|
||||
}
|
||||
|
||||
type PastBloodTx struct {
|
||||
Code string `json:"jwssxcode,omitempty"`
|
||||
Reason string `json:"jwssxyy,omitempty"`
|
||||
}
|
||||
|
||||
type FamilyMiddle struct {
|
||||
WaterSourceCode string `json:"waterSourceCode,omitempty"`
|
||||
FuelType string `json:"fuelType,omitempty"`
|
||||
CookAirTool string `json:"cookAirTool,omitempty"`
|
||||
Washroom string `json:"washroom,omitempty"`
|
||||
LivestockColumn string `json:"livestockColumn,omitempty"`
|
||||
IsFillSHHJ string `json:"isFillShhj,omitempty"`
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFindHealthRecordDeserializesMeasuredJKDA00002Data(t *testing.T) {
|
||||
raw := []byte(`[
|
||||
{
|
||||
"healthRecord": {
|
||||
"idCard": "440000********1234",
|
||||
"personName": "测试人员",
|
||||
"sexCode": "1",
|
||||
"birthday": "1970-01-01",
|
||||
"phrId": "PHR001",
|
||||
"empiId": "0123456789abcdef0123456789abcdef",
|
||||
"checkId": null,
|
||||
"manaUnitId": "123456789",
|
||||
"createUnit": "123456789",
|
||||
"manaDoctorId": "D001",
|
||||
"createUser": "U001",
|
||||
"regionCode": "441625000000",
|
||||
"addressCode": "441625000001",
|
||||
"homePlaceCode": "441625000002",
|
||||
"address": "现住址",
|
||||
"adressNumber": "101号",
|
||||
"homePlace": "户籍地",
|
||||
"homePlaceNumber": "202号",
|
||||
"nationCode": "01",
|
||||
"educationCode": "30",
|
||||
"workCode": "90",
|
||||
"maritalStatusCode": "20",
|
||||
"bloodTypeCode": "1",
|
||||
"rhBloodCode": "1",
|
||||
"insuranceCode": "01",
|
||||
"insuranceType": null,
|
||||
"personGroup": "01",
|
||||
"otherPersonGroup": null,
|
||||
"isFillShhj": "y",
|
||||
"contact": "联系人",
|
||||
"contactPhone": "13800000000",
|
||||
"mobileNumber": "13900000000",
|
||||
"phoneNumber": "02000000000",
|
||||
"status": "1",
|
||||
"createDate": "2026-07-06"
|
||||
},
|
||||
"pastHistory": {
|
||||
"ywgms": "2",
|
||||
"jwsjb": "1",
|
||||
"bls": "2",
|
||||
"ycbs": "2",
|
||||
"cjqk": "2",
|
||||
"jzsfqn": "2",
|
||||
"jzsmq": "2",
|
||||
"jzszn": "2",
|
||||
"jzsxdjm": "2"
|
||||
},
|
||||
"jwsjb": [{"jwsjbcode":"2","jwsjbmc":"高血压","jwsjbqzsj":"2020-01-02"}],
|
||||
"jwsss": [{"jwssscode":"1","jwsssmc":"手术史","jwsssqzsj":"2019-03-04"}],
|
||||
"jwsws": [{"jwswscode":"1","jwswsmc":"外伤史"}],
|
||||
"jwssx": [{"jwssxcode":"1","jwssxyy":"输血原因"}],
|
||||
"familyMiddle": {
|
||||
"waterSourceCode": "1",
|
||||
"fuelType": "2",
|
||||
"cookAirTool": "3",
|
||||
"washroom": "4",
|
||||
"livestockColumn": "5",
|
||||
"isFillShhj": "y"
|
||||
}
|
||||
}
|
||||
]`)
|
||||
|
||||
var records []FindHealthRecord
|
||||
if err := json.Unmarshal(raw, &records); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
if len(records) != 1 {
|
||||
t.Fatalf("records length = %d", len(records))
|
||||
}
|
||||
|
||||
record := records[0]
|
||||
if record.HealthRecord.PhrID != "PHR001" {
|
||||
t.Fatalf("phrId = %q", record.HealthRecord.PhrID)
|
||||
}
|
||||
if record.HealthRecord.AdressNumber != "101号" {
|
||||
t.Fatalf("adressNumber = %q", record.HealthRecord.AdressNumber)
|
||||
}
|
||||
if record.HealthRecord.CheckID != nil {
|
||||
t.Fatalf("checkId = %#v, want nil", record.HealthRecord.CheckID)
|
||||
}
|
||||
if record.HealthRecord.InsuranceType != nil {
|
||||
t.Fatalf("insuranceType = %#v, want nil", record.HealthRecord.InsuranceType)
|
||||
}
|
||||
if record.HealthRecord.OtherPersonGroup != nil {
|
||||
t.Fatalf("otherPersonGroup = %#v, want nil", record.HealthRecord.OtherPersonGroup)
|
||||
}
|
||||
if record.PastHistory == nil || record.PastHistory.JWSJB != "1" {
|
||||
t.Fatalf("pastHistory = %#v", record.PastHistory)
|
||||
}
|
||||
if len(record.PastDiseases) != 1 || record.PastDiseases[0].Code != "2" || record.PastDiseases[0].ConfirmedDate != "2020-01-02" {
|
||||
t.Fatalf("past diseases = %#v", record.PastDiseases)
|
||||
}
|
||||
if len(record.PastSurgeries) != 1 || record.PastSurgeries[0].Name != "手术史" {
|
||||
t.Fatalf("past surgeries = %#v", record.PastSurgeries)
|
||||
}
|
||||
if len(record.PastTraumas) != 1 || record.PastTraumas[0].Name != "外伤史" {
|
||||
t.Fatalf("past traumas = %#v", record.PastTraumas)
|
||||
}
|
||||
if len(record.PastTransfusions) != 1 || record.PastTransfusions[0].Reason != "输血原因" {
|
||||
t.Fatalf("past transfusions = %#v", record.PastTransfusions)
|
||||
}
|
||||
if record.FamilyMiddle == nil || record.FamilyMiddle.IsFillSHHJ != "y" {
|
||||
t.Fatalf("familyMiddle = %#v", record.FamilyMiddle)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindHealthRecordResponseDeserializesDataArray(t *testing.T) {
|
||||
raw := []byte(`{"code":"01","message":"操作成功","data":[{"healthRecord":{"phrId":"PHR001","checkId":null,"adressNumber":"101号"}}]}`)
|
||||
|
||||
var response FindHealthRecordResponse
|
||||
if err := json.Unmarshal(raw, &response); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
if response.Code != "01" || response.Message != "操作成功" {
|
||||
t.Fatalf("response = %#v", response)
|
||||
}
|
||||
if len(response.Data) != 1 {
|
||||
t.Fatalf("data length = %d", len(response.Data))
|
||||
}
|
||||
if response.Data[0].HealthRecord.PhrID != "PHR001" {
|
||||
t.Fatalf("phrId = %q", response.Data[0].HealthRecord.PhrID)
|
||||
}
|
||||
if response.Data[0].HealthRecord.CheckID != nil {
|
||||
t.Fatalf("checkId = %#v, want nil", response.Data[0].HealthRecord.CheckID)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user