package controllers import ( "XT_New/enums" "XT_New/models" "XT_New/service" "XT_New/utils" "bytes" "encoding/json" "fmt" "github.com/astaxie/beego" "io/ioutil" "math/rand" "net/http" "reflect" "strconv" "strings" "time" ) type HisApiController struct { BaseAuthAPIController } func HisManagerApiRegistRouters() { beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList") beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo") beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig") beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription") beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice") beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject") beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription") beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList") beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory") beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "post:CreateHisPatientCaseHistory") beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "post:CreateCaseHistoryTemplate") beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate") beego.Router("/api/doctorworkstation/printcasehistory/get", &HisApiController{}, "get:GetPrintHisPatientCaseHistory") beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo") beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo") } func (c *HisApiController) GetHisPatientList() { types, _ := c.GetInt64("type", 0) record_date := c.GetString("record_date") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime) if types == 0 { c.ServeSuccessJSON(map[string]interface{}{ "list": patients, }) } else if types == 1 { //未就诊 var patientsOne []*service.Schedule for _, item := range patients { if item.HisPrescription == nil || len(item.HisPrescription) <= 0 { patientsOne = append(patientsOne, item) } } c.ServeSuccessJSON(map[string]interface{}{ "list": patientsOne, }) } else if types == 2 { //已就诊 var patientsTwo []*service.Schedule for _, item := range patients { if item.HisPrescription != nil && len(item.HisPrescription) > 0 { patientsTwo = append(patientsTwo, item) } } c.ServeSuccessJSON(map[string]interface{}{ "list": patientsTwo, }) } } func (c *HisApiController) GetHisPatientInfo() { patient_id, _ := c.GetInt64("patient_id") record_date := c.GetString("record_date") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() admin := c.GetAdminUserInfo() his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime) xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id) prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime) case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime) c.ServeSuccessJSON(map[string]interface{}{ "his_info": his_patient_info, "xt_info": xt_patient_info, "prescription": prescriptions, "case_history": case_history, }) return } func (c *HisApiController) GetHisPrescriptionConfig() { adminInfo := c.GetAdminUserInfo() //获取医嘱模版 advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId) //获取所有基础药 drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId) drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId) efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId) doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId) //获取所有科室信息 department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId) c.ServeSuccessJSON(map[string]interface{}{ "drugs": drugs, "advices_template": advices, "drugways": drugways, "efs": efs, "doctors": doctors, "department": department, }) } func (c *HisApiController) CreateHisPrescription() { record_date := c.GetString("record_date") fmt.Println("record_date", record_date) patient_id, _ := c.GetInt64("patient_id") reg_type, _ := c.GetInt64("reg_type") diagnose := c.GetString("diagnose") sick_history := c.GetString("sick_history") doctor, _ := c.GetInt64("doctor") department, _ := c.GetInt64("department") his_patient_id, _ := c.GetInt64("his_patient_id") dataBody := make(map[string]interface{}, 0) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := c.GetAdminUserInfo() recordDateTime := theTime.Unix() info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime) if info.ID == 0 { hpInfo := models.HisPrescriptionInfo{ UserOrgId: adminInfo.CurrentOrgId, RecordDate: theTime.Unix(), PatientId: patient_id, Status: 1, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Creator: adminInfo.AdminUser.Id, Modifier: adminInfo.AdminUser.Id, Diagnosis: diagnose, SickHistory: sick_history, Departments: department, RegisterType: reg_type, } service.SavePatientPrescriptionInfo(hpInfo) } else { hpInfo := models.HisPrescriptionInfo{ ID: info.ID, UserOrgId: adminInfo.CurrentOrgId, RecordDate: info.RecordDate, PatientId: info.PatientId, Status: 1, Ctime: info.Ctime, Mtime: time.Now().Unix(), Creator: info.Creator, Modifier: adminInfo.AdminUser.Id, Diagnosis: diagnose, SickHistory: sick_history, Departments: department, RegisterType: reg_type, } service.SavePatientPrescriptionInfo(hpInfo) } if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" { prescriptions, _ := dataBody["prescriptions"].([]interface{}) if len(prescriptions) > 0 { for _, item := range prescriptions { items := item.(map[string]interface{}) if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" { utils.ErrorLog("id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } id := int64(items["id"].(float64)) if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" { utils.ErrorLog("type") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } types := int64(items["type"].(float64)) ctime := time.Now().Unix() prescription := &models.HisPrescription{ ID: id, PatientId: patient_id, UserOrgId: adminInfo.CurrentOrgId, RecordDate: recordDateTime, Ctime: ctime, Mtime: ctime, Type: types, Modifier: adminInfo.AdminUser.Id, Creator: adminInfo.AdminUser.Id, Status: 1, Doctor: doctor, HisPatientId: his_patient_id, IsFinish: 1, BatchNumber: "", } service.SaveHisPrescription(prescription) if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" { advices := items["advices"].([]interface{}) group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId) groupNo := group + 1 ctime := time.Now().Unix() mtime := ctime if len(advices) > 0 { for _, advice := range advices { var s models.HisDoctorAdviceInfo s.PrescriptionId = prescription.ID s.AdviceType = 2 s.AdviceDoctor = adminInfo.AdminUser.Id s.StopState = 2 s.ExecutionState = 2 s.AdviceDate = recordDateTime s.Status = 1 s.UserOrgId = adminInfo.CurrentOrgId s.RecordDate = recordDateTime s.StartTime = recordDateTime s.Groupno = groupNo s.CreatedTime = ctime s.UpdatedTime = mtime s.PatientId = patient_id s.HisPatientId = his_patient_id errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{})) if errcode > 0 { c.ServeFailJSONWithSGJErrorCode(errcode) return } service.CreateHisDoctorAdvice(&s) var randNum int randNum = rand.Intn(10000) + 1000 timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10) service.CreateHisDoctorAdvice(&s) } } } if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" { projects := items["project"].([]interface{}) if len(projects) > 0 { for _, project := range projects { var p models.HisPrescriptionProject p.PrescriptionId = prescription.ID p.Ctime = time.Now().Unix() p.Mtime = time.Now().Unix() p.PatientId = patient_id p.RecordDate = recordDateTime p.UserOrgId = adminInfo.CurrentOrgId p.HisPatientId = his_patient_id p.Status = 1 errcode := c.setProjectWithJSON(&p, project.(map[string]interface{})) if errcode > 0 { c.ServeFailJSONWithSGJErrorCode(errcode) return } service.CreateHisProjectTwo(&p) var randNum int randNum = rand.Intn(10000) + 1000 timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10) service.SaveHisProjectTwo(&p) } } } } } } if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "保存成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *HisApiController) DeletePrescription() { prescription_id, _ := c.GetInt64("id") //TODO 需要判断是否已经结算 err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "删除成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *HisApiController) DeleteDoctorAdvice() { id, _ := c.GetInt64("id") //TODO 需要判断是否已经结算 err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "删除成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *HisApiController) DeleteProject() { id, _ := c.GetInt64("id") //TODO 需要判断是否已经结算 err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "删除成功", }) return } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *HisApiController) CreateHisAdditionalCharge() { his_patient_id, _ := c.GetInt64("his_patient_id") patient_id, _ := c.GetInt64("patient_id") record_date := c.GetString("record_date") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } adminInfo := c.GetAdminUserInfo() recordDateTime := theTime.Unix() dataBody := make(map[string]interface{}, 0) err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody) if err != nil { utils.ErrorLog(err.Error()) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } var additions []*models.HisAdditionalCharge if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" { additions, _ := dataBody["addition"].([]interface{}) if len(additions) > 0 { for _, item := range additions { items := item.(map[string]interface{}) if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" { utils.ErrorLog("item_id") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } item_id := int64(items["item_id"].(float64)) if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" { utils.ErrorLog("item_name") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } item_name := items["item_name"].(string) if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" { utils.ErrorLog("price") c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } price, _ := strconv.ParseFloat(items["price"].(string), 64) ctime := time.Now().Unix() additional := &models.HisAdditionalCharge{ PatientId: patient_id, HisPatientId: his_patient_id, UserOrgId: adminInfo.CurrentOrgId, RecordDate: recordDateTime, CreatedTime: ctime, UpdatedTime: ctime, Modifier: adminInfo.AdminUser.Id, Creator: adminInfo.AdminUser.Id, Price: price, ItemName: item_name, ItemId: item_id, Status: 1, } additions = append(additions, additional) } } } for _, item := range additions { service.CreateAddtionalCharge(item) } c.ServeSuccessJSON(map[string]interface{}{ "msg": "创建成功", }) } func (c *HisApiController) CreateHisPatientCaseHistory() { diagnostic := c.GetString("diagnostic") temperature, _ := c.GetFloat("temperature") blood_sugar, _ := c.GetFloat("blood_sugar") pulse, _ := c.GetFloat("pulse") sbp, _ := c.GetFloat("sbp") dbp, _ := c.GetFloat("dbp") blood_fat, _ := c.GetFloat("blood_fat") height, _ := c.GetFloat("height") sick_type, _ := c.GetInt64("sick_type") symptom := c.GetString("symptom") sick_date := c.GetString("sick_date") is_infect, _ := c.GetInt64("is_infect") chief_conplaint := c.GetString("chief_conplaint") history_of_present_illness := c.GetString("history_of_present_illness") past_history := c.GetString("past_history") personal_history := c.GetString("personal_history") family_history := c.GetString("family_history") record_date := c.GetString("record_date") patient_id, _ := c.GetInt64("patient_id") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } sickTimes := sickTime.Unix() ctime := time.Now().Unix() caseHistory := models.HisPatientCaseHistory{ HisPatientId: patient_id, Temperature: temperature, BloodSugar: blood_sugar, Pulse: pulse, Sbp: sbp, Dbp: dbp, Height: height, BloodFat: blood_fat, SickType: sick_type, Symptom: symptom, SickDate: sickTimes, IsInfect: is_infect, HistoryOfPresentIllness: history_of_present_illness, PastHistory: past_history, Doctor: c.GetAdminUserInfo().AdminUser.Id, ChiefConplaint: chief_conplaint, PersonalHistory: personal_history, FamilyHistory: family_history, Diagnostic: diagnostic, UserOrgId: c.GetAdminUserInfo().CurrentOrgId, Status: 1, Ctime: ctime, Mtime: ctime, RecordDate: recordDateTime, } err = service.SaveHisPatientCaseHistory(caseHistory) if err != nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "保存成功", }) } } func (c *HisApiController) GetHisPatientCaseHistoryList() { patient_id, _ := c.GetInt64("patient_id", 0) adminUser := c.GetAdminUserInfo() caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id) c.ServeSuccessJSON(map[string]interface{}{ "list": caseHistorys, }) } func (c *HisApiController) GetHisPatientCaseHistory() { record_date, _ := c.GetInt64("record_date", 0) patient_id, _ := c.GetInt64("patient_id", 0) admin := c.GetAdminUserInfo() info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date) case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date) c.ServeSuccessJSON(map[string]interface{}{ "info": info, "case_history": case_history, }) } func (c *HisApiController) CreateCaseHistoryTemplate() { template_name := c.GetString("template_name") template_remark := c.GetString("template_remark") doctor := c.GetAdminUserInfo().AdminUser.Id diagnostic := c.GetString("diagnostic") chief_conplaint := c.GetString("chief_conplaint") history_of_present_illness := c.GetString("history_of_present_illness") past_history := c.GetString("past_history") personal_history := c.GetString("personal_history") family_history := c.GetString("family_history") record_date := c.GetString("record_date") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() ctime := time.Now().Unix() template := models.HisCaseHistoryTemplate{ HistoryOfPresentIllness: history_of_present_illness, PastHistory: past_history, ChiefConplaint: chief_conplaint, PersonalHistory: personal_history, FamilyHistory: family_history, Diagnostic: diagnostic, UserOrgId: c.GetAdminUserInfo().CurrentOrgId, Status: 1, Ctime: ctime, Mtime: ctime, RecordDate: recordDateTime, TemplateName: template_name, TemplateRemark: template_remark, Creator: doctor, Modifier: doctor, } err = service.SaveHisPatientCaseHistoryTemplate(template) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "保存成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } func (c *HisApiController) GetCaseHistoryTemplate() { admin := c.GetAdminUserInfo() template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId) c.ServeSuccessJSON(map[string]interface{}{ "template": template, }) } type ResultTwo struct { ErrMsg interface{} `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { Baseinfo struct { Age float64 `json:"age"` Brdy string `json:"brdy"` Certno string `json:"certno"` Gend string `json:"gend"` Naty string `json:"naty"` PsnCertType string `json:"psn_cert_type"` PsnName string `json:"psn_name"` PsnNo string `json:"psn_no"` } `json:"baseinfo"` Idetinfo []interface{} `json:"idetinfo"` Iinfo []struct { Balc int64 `json:"balc"` CvlservFlag string `json:"cvlserv_flag"` EmpName string `json:"emp_name"` InsuplcAdmdvs string `json:"insuplc_admdvs"` Insutype string `json:"insutype"` PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"` PausInsuDate interface{} `json:"paus_insu_date"` PsnInsuDate string `json:"psn_insu_date"` PsnInsuStas string `json:"psn_insu_stas"` PsnType string `json:"psn_type"` } `json:"insuinfo"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnInfo interface{} `json:"warn_info"` } type ResultThree struct { Cainfo interface{} `json:"cainfo"` ErrMsg interface{} `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { Data struct { IptOtpNo string `json:"ipt_otp_no"` MdtrtID string `json:"mdtrt_id"` PsnNo string `json:"psn_no"` } `json:"data"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } func (c *HisApiController) GetRegisterInfo() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") adminInfo := c.GetAdminUserInfo() patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id) if patient == nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(patient.IdCardNo) == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo) return } timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo resp, requestErr := http.Get(api) if requestErr != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } defer resp.Body.Close() body, ioErr := ioutil.ReadAll(resp.Body) if ioErr != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON map[string]interface{} if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{}) userJSONBytes, _ := json.Marshal(userJSON) var res ResultTwo if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } Iinfos, _ := json.Marshal(res.Output.Iinfo) Idetinfos, _ := json.Marshal(res.Output.Idetinfo) infoStr := string(Iinfos) idetinfoStr := string(Idetinfos) his := models.VMHisPatient{ PsnNo: res.Output.Baseinfo.PsnNo, PsnCertType: res.Output.Baseinfo.PsnCertType, Certno: res.Output.Baseinfo.Certno, PsnName: res.Output.Baseinfo.PsnName, Gend: res.Output.Baseinfo.Gend, Naty: res.Output.Baseinfo.Naty, Brdy: res.Output.Baseinfo.Brdy, Age: res.Output.Baseinfo.Age, Iinfo: infoStr, Idetinfo: idetinfoStr, PatientId: patient.ID, RecordDate: theTime.Unix(), } fmt.Println(his) if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException) return } count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId) if count <= 0 { api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" + res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo resp, requestErr := http.Get(api) if requestErr != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } defer resp.Body.Close() body, ioErr := ioutil.ReadAll(resp.Body) if ioErr != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON map[string]interface{} if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{}) userJSONBytes, _ := json.Marshal(respJSON) var res ResultThree if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == -1 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException) return } fmt.Println("000!!!!!!") fmt.Println(res) fmt.Println(res.Output.Data.MdtrtID) fmt.Println(res.Output.Data.PsnNo) fmt.Println(res.Output.Data.IptOtpNo) his.Number = res.Output.Data.MdtrtID his.PsnNo = res.Output.Data.PsnNo his.IptOtpNo = res.Output.Data.IptOtpNo his.IdCardNo = patient.IdCardNo his.PhoneNumber = patient.Phone his.UserOrgId = adminInfo.CurrentOrgId his.Status = 1 his.Ctime = time.Now().Unix() his.Mtime = time.Now().Unix() err := service.CreateHisPatientTwo(&his) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "his_info": his, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } func (c *HisApiController) GetPrintHisPatientCaseHistory() { } func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int { if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" { utils.ErrorLog("drug_name") return enums.ErrorCodeParamWrong } adviceName, _ := json["drug_name"].(string) if len(adviceName) == 0 { utils.ErrorLog("len(advice_name) == 0") return enums.ErrorCodeParamWrong } advice.AdviceName = adviceName adviceDesc, _ := json["advice_desc"].(string) advice.AdviceDesc = adviceDesc if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" { drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64) advice.DrugSpec = drugSpec } if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" { remark, _ := json["remark"].(string) advice.Remark = remark } if json["id"] == nil { advice.DrugId = 0 } else { if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" { drug_id := int64(json["id"].(float64)) advice.DrugId = drug_id } } if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" { advice_id := int64(json["advice_id"].(float64)) advice.ID = advice_id } if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" { drugSpecUnit, _ := json["min_unit"].(string) advice.DrugSpecUnit = drugSpecUnit } if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" { singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64) advice.SingleDose = singleDose } if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" { singleDoseUnit, _ := json["min_unit"].(string) advice.SingleDoseUnit = singleDoseUnit } if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" { prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64) advice.PrescribingNumber = prescribingNumber } if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" { prescribingNumberUnit, _ := json["min_unit"].(string) advice.PrescribingNumberUnit = prescribingNumberUnit } if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" { deliveryWay, _ := json["delivery_way"].(string) advice.DeliveryWay = deliveryWay } if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" { executionFrequency, _ := json["execution_frequency"].(string) advice.ExecutionFrequency = executionFrequency } if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" { remark, _ := json["remark"].(string) advice.Remark = remark } //if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" { // advice.Price = json["retail_price"].(float64) //} if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" { price, _ := strconv.ParseFloat(json["retail_price"].(string), 64) advice.Price = price } if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" { med_list_codg, _ := json["medical_insurance_number"].(string) advice.MedListCodg = med_list_codg } return 0 } func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int { if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" { id := int64(json["id"].(float64)) project.ID = id } if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" { project_id := int64(json["project_id"].(float64)) project.ProjectId = project_id fmt.Println(project_id) fmt.Println(project.ProjectId) } if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" { price := int64(json["price"].(float64)) formatInt_price := strconv.FormatInt(price, 10) float_price, _ := strconv.ParseFloat(formatInt_price, 64) project.Price = float_price } if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" { total, _ := json["total"].(string) totals, _ := strconv.ParseInt(total, 10, 64) project.Count = totals } if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" { medical_code, _ := json["medical_code"].(string) project.MedListCodg = medical_code } return 0 } type ResultFour struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { Result []struct { BasMednFlag string `json:"bas_medn_flag"` ChldMedcFlag string `json:"chld_medc_flag"` ChrgitmLv string `json:"chrgitm_lv"` Cnt float64 `json:"cnt"` DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"` DrtReimFlag string `json:"drt_reim_flag"` FeedetlSn string `json:"feedetl_sn"` FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"` HiNegoDrugFlag string `json:"hi_nego_drug_flag"` InscpScpAmt float64 `json:"inscp_scp_amt"` ListSpItemFlag string `json:"list_sp_item_flag"` LmtUsedFlag string `json:"lmt_used_flag"` MedChrgitmType string `json:"med_chrgitm_type"` Memo string `json:"memo"` OverlmtAmt float64 `json:"overlmt_amt"` PreselfpayAmt float64 `json:"preselfpay_amt"` Pric float64 `json:"pric"` PricUplmtAmt float64 `json:"pric_uplmt_amt"` SelfpayProp float64 `json:"selfpay_prop"` } `json:"result"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype string `json:"signtype"` WarnMsg string `json:"warn_msg"` } type ResultFive struct { Insutype string `json:"insutype"` } func (c *HisApiController) GetUploadInfo() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() adminUser := c.GetAdminUserInfo() prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime) his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime) timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") chrgBchno := rand.Intn(100000) + 10000 chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10) client := &http.Client{} data := make(map[string]interface{}) data["psn_no"] = his.PsnNo data["mdtrt_id"] = his.Number data["pre"] = prescriptions data["chrg_bchno"] = chrg_bchno bytesData, _ := json.Marshal(data) req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData)) resp, _ := client.Do(req) defer resp.Body.Close() body, ioErr := ioutil.ReadAll(resp.Body) if ioErr != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON map[string]interface{} if err := json.Unmarshal([]byte(body), &respJSON); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{}) userJSONBytes, _ := json.Marshal(respJSON) var res ResultFour if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == 0 { order := &models.HisOrder{ UserOrgId: adminUser.CurrentOrgId, HisPatientId: his.ID, PatientId: his.PatientId, SettleAccountsDate: recordDateTime, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, Number: chrg_bchno, Infcode: res.Infcode, WarnMsg: res.WarnMsg, Cainfo: res.Cainfo, ErrMsg: res.ErrMsg, RespondTime: res.RefmsgTime, InfRefmsgid: res.InfRefmsgid, OrderStatus: 1, } err = service.CreateOrder(order) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException) return } for _, item := range res.Output.Result { temp := strings.Split(item.FeedetlSn, "-") var advice_id int64 = 0 var project_id int64 = 0 var types int64 = 0 id, _ := strconv.ParseInt(temp[2], 10, 64) types, _ = strconv.ParseInt(temp[1], 10, 64) if temp[1] == "1" { advice_id = id project_id = 0 } else if temp[1] == "2" { advice_id = 0 project_id = id } info := &models.HisOrderInfo{ OrderNumber: order.Number, FeedetlSn: item.FeedetlSn, UploadDate: time.Now().Unix(), AdviceId: advice_id, DetItemFeeSumamt: item.DetItemFeeSumamt, Cnt: item.Cnt, Pric: float64(item.Pric), PatientId: his.PatientId, PricUplmtAmt: item.PricUplmtAmt, SelfpayProp: item.SelfpayProp, FulamtOwnpayAmt: item.FulamtOwnpayAmt, OverlmtAmt: item.OverlmtAmt, PreselfpayAmt: item.PreselfpayAmt, BasMednFlag: item.BasMednFlag, MedChrgitmType: item.MedChrgitmType, HiNegoDrugFlag: item.HiNegoDrugFlag, Status: 1, Memo: item.Memo, Mtime: time.Now().Unix(), InscpScpAmt: item.InscpScpAmt, DrtReimFlag: item.DrtReimFlag, Ctime: time.Now().Unix(), ListSpItemFlag: item.ListSpItemFlag, ChldMedcFlag: item.ChldMedcFlag, LmtUsedFlag: item.LmtUsedFlag, ChrgitmLv: item.ChrgitmLv, UserOrgId: adminUser.CurrentOrgId, HisPatientId: his.ID, OrderId: order.ID, ProjectId: project_id, Type: types, } service.CreateOrderInfo(info) } var total float64 for _, item := range prescriptions { if item.Type == 1 { //药品 for _, subItem := range item.HisDoctorAdviceInfo { total = total + (subItem.Price * subItem.PrescribingNumber) } } if item.Type == 2 { //项目 for _, subItem := range item.HisPrescriptionProject { total = total + (subItem.Price * float64(subItem.Count)) } } } allTotal := fmt.Sprintf("%.2f", total) if res.Infcode == 0 { var rf []*ResultFive json.Unmarshal([]byte(his.Iinfo), &rf) psn_no := his.PsnNo mdtrt_id := his.Number chrg_bchno := chrg_bchno cert_no := his.Certno insutype := rf[0].Insutype api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" + insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id + "&total=" + allTotal resp, requestErr := http.Get(api) if requestErr != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } defer resp.Body.Close() body, ioErr := ioutil.ReadAll(resp.Body) if ioErr != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON map[string]interface{} if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } fmt.Println(respJSON) respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{}) userJSONBytes, _ := json.Marshal(respJSON) var res ResultFour if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else { } } else { c.ServeSuccessJSON(map[string]interface{}{ "msg": res.ErrMsg, }) } }