package sg import ( "archive/zip" "bytes" "encoding/json" "fmt" "gdyb/controllers" "gdyb/enums" "gdyb/models" "gdyb/service" "gdyb/utils" "github.com/astaxie/beego" "github.com/jinzhu/gorm" "github.com/shopspring/decimal" "io" "io/ioutil" "math/rand" "net/http" "os" "path/filepath" "strconv" "strings" "syscall" "time" "unsafe" ) type HisApiController struct { controllers.BaseAuthAPIController } func HisManagerApiRegistRouters() { beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo") beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag") beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo") beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts") beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount") beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount") beego.Router("/api/refund/post", &HisApiController{}, "get:Refund") //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard") beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber") beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail") beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment") beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord") beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo") beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo") beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo") beego.Router("/api/testpay", &HisApiController{}, "get:TestPay") beego.Router("/api/pre_upload/get", &HisApiController{}, "get:GetPreUploadInfo") beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo") } //func (c *HisApiController) TestPay() { // DllDef2 := syscall.MustLoadDLL("SSSE32.dll") // readCards := DllDef2.MustFindProc("BankTrans") // inputData := make(map[string]interface{}) // inputData["transId"] = "05" // inputData["amount"] = "0.01" // inputData["traceNo"] = "20210227093601325405377" // inputData["cardNo"] = "F36084348" // inputData["id"] = "44022919620927046X" // //jsonStr := ` // // { // // "transId": "05", // // "amount":"1.00", // // "traceNo":"20210227093601325405377", // // "cardNo":"F36084348", // // "id":"44022919620927046X" // // // // } // //` // // bytes_arr, _ := json.Marshal(inputData) // str3 := make([]byte, 256) // ret4, _, err4 := readCards.Call(StrPtr(string(bytes_arr)), (uintptr)(unsafe.Pointer(&str3[0]))) // fmt.Println(":", string(str3)) // // if err4 != nil { // fmt.Println("SSCard的运算结果为:", ret4) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException) // return // } // //} func (c *HisApiController) TestGetBasBaseInfo() { //result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200")) //fmt.Println(result) //cs1 := C.CString("") //cs2 := C.CString("") //C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024)) //fmt.Println(cs1) //fmt.Println(cs2) //C.free(unsafe.Pointer(cs1)) //C.free(unsafe.Pointer(cs2)) // DllDef := syscall.MustLoadDLL("SSCard.dll") Iinit := DllDef.MustFindProc("Init") readCard := DllDef.MustFindProc("ReadCardBas") ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200")) if ret != 0 { fmt.Println("SSCard的报错原因:", err) fmt.Println("SSCard的运算结果为:", ret) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException) return } result := int(ret) fmt.Println("SSCard的运算结果为1:", result) //path := "" //bytePath := []byte( "\x00") //bytePath2 := []byte( "\x00") //ssss str := make([]byte, 256) str1 := make([]byte, 256) s2 := []byte(string(str)) s3 := []byte(string(str1)) ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&s2[0])), IntPtr(256), (uintptr)(unsafe.Pointer(&s3[0])), IntPtr(256)) fmt.Println(" Add(4,5)的结果为:", ret2) fmt.Println(" str:", s2) fmt.Println(" str1:", s3) if err2 != nil { fmt.Println("SSCard的运算结果为:", ret2) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException) return } //DllDef := syscall.MustLoadDLL("SSCard.dll") } func (c *HisApiController) GetOrgInfo() { miConfig, _ := service.FindMedicalInsuranceInfo(9919) service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "") } func (c *HisApiController) GetHisPatientInfo() { medical_insurance_card := c.GetString("medical_insurance_card") id_card_type, _ := c.GetInt64("id_card_type") id_card := c.GetString("id_card") adminInfo := c.GetAdminUserInfo() config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId) miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId) appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId) IdCardNo := "" if id_card_type == 1 { IdCardNo = medical_insurance_card } else if id_card_type == 2 { IdCardNo = id_card } if config.IsOpen == 1 { api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey 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) if res.Infcode == 0 { his := models.VMHisPatient{ Status: 1, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), 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, UserOrgId: adminInfo.CurrentOrgId, IsReturn: 1, IdCardType: id_card_type, } c.ServeSuccessJSON(map[string]interface{}{ "info": his, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException) return } } } //func (c *HisApiController) Sscard() { // id_card_type, _ := c.GetInt64("id_card_type") // adminUser := c.GetAdminUserInfo() // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) // // r := CardInit() // fmt.Println(r) // //if r == 0 { // switch id_card_type { // case 1: // basStr, err := GetBasBaseInfo() // // if err != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException) // return // // } else { // fmt.Println(basStr) // // bas := strings.Split(basStr, "|") // // basNumber := bas[1] // // //basNumber := bas[2] // card_sn := bas[3] // // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId) // // api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + basNumber + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) + "&card_sn=" + card_sn // 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) // // if res.Infcode == 0 { // his := models.VMHisPatient{ // Status: 1, // Ctime: time.Now().Unix(), // Mtime: time.Now().Unix(), // 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, // UserOrgId: adminUser.CurrentOrgId, // IsReturn: 1, // IdCardType: id_card_type, // } // // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId) // if err == gorm.ErrRecordNotFound { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException) // return // // } else if err != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) // return // // } else { // c.ServeSuccessJSON(map[string]interface{}{ // "patient": patient, // "his": his, // "number": basNumber, // }) // } // } else { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException) // return // } // // } // // break // case 2: // ////SFZStr, err := GetSFZBaseInfo() // //if err != nil { // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException) // // return // // // //} else { // // // // id_card_str := strings.Split(SFZStr, "^") // // id_card_number := id_card_str[0] // //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId) // // // //api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + id_card_number + "&org_name=" + miConfig.OrgName + "&doctor=" + appRole.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) // //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) // // // //if res.Infcode == 0 { // // his := models.VMHisPatient{ // // Status: 1, // // Ctime: time.Now().Unix(), // // Mtime: time.Now().Unix(), // // 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, // // UserOrgId: adminUser.CurrentOrgId, // // IsReturn: 1, // // IdCardType: id_card_type, // // } // // // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId) // // if err == gorm.ErrRecordNotFound { // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException) // // return // // // // } else if err != nil { // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) // // return // // // // } else { // // c.ServeSuccessJSON(map[string]interface{}{ // // "patient": patient, // // "number": id_card_number, // // }) // // } // //} // break // case 3: // // break // // } //} //func GetBasBaseInfo() (jsonStr string, err error) { // // handle, err := syscall.LoadLibrary("SSCard.dll") // if err != nil { // fmt.Printf("Error: %s\n", err) // return "", err // } // defer syscall.FreeLibrary(handle) // str := make([]byte, 256) // str1 := make([]byte, 256) // add, err := syscall.GetProcAddress(handle, "ReadCardBas") // if err != nil { // fmt.Printf("Error: %s\n", err) // return "", err // } // ret, _, _ := syscall.Syscall(add, (uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024)) // if err != nil { // fmt.Printf("Error: %s\n", err) // } // fmt.Println("> Add(4,5)的结果为:", ret) // //return nil // // // // //handle := syscall.NewLazyDLL("SSCard.dll") // //ReadCardBas := handle.NewProc("ReadCardBas") // // // //var str2 [1024]C.char // //var str3 [1024]C.char // // // // // // // ////sssssswwwww // ////a := 256 // // // //r, _, _ := ReadCardBas.Call(&str2, 1024, &str3, 1024) // //fmt.Println(r) // ////p := (*byte)(unsafe.Pointer(r)) // // define a slice to fill with the p string // //data := make([]byte, 0) // // // loop until find '\0' // //if *p != 0 { // // // // //data = append(data, *p) // append 1 byte // // //r += unsafe.Sizeof(byte(0)) // move r to next byte // // //p = (*byte)(unsafe.Pointer(r)) // get the byte value // //} else { // // return "", nil // // // //} // // return "", nil // //} //func GetSFZBaseInfo() (jsonStr string, err error) { // //handle := syscall.MustLoadDLL("SSCard.dll") // // str := make([]byte, 256) // str1 := make([]byte, 256) // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024)) // // fmt.Println(r) // return string(str), nil //} //func GetQRBaseInfo() (jsonStr string, err error) { // handle := syscall.LoadDLL("SSCard.dll") // ReadCardBas := handle.FindProc("GetQRBase") // // str := make([]byte, 256) // str1 := make([]byte, 256) // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024)) // // fmt.Println(string(str)) // fmt.Println(r) // return string(str), nil //} func CardInit() int { DllTestDef := syscall.MustLoadDLL("SSCard.dll") add := DllTestDef.MustFindProc("Init") ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200")) if err != nil { fmt.Println("SSCard的运算结果为:", ret) } result := int(ret) return result } //func CardInit() int { // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200")) // if err != nil { // fmt.Println("SSCard的运算结果为:", ret) // } // fmt.Println(err) // result := int(ret) // return result //} func IntPtr(n int) uintptr { return uintptr(n) } func StrPtr(s string) uintptr { return uintptr(unsafe.Pointer(syscall.StringBytePtr(s))) } type ResultTwo struct { ErrMsg string `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 string `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"` } 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"` } type ResultSix struct { Cainfo interface{} `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type ResultSeven struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { Setldetail []interface{} `json:"setldetail"` Setlinfo struct { AcctMulaidPay float64 `json:"acct_mulaid_pay"` AcctPay float64 `json:"acct_pay"` ActPayDedc float64 `json:"act_pay_dedc"` Age float64 `json:"age"` Balc float64 `json:"balc"` Brdy string `json:"brdy"` Certno string `json:"certno"` ClrOptins string `json:"clr_optins"` ClrType string `json:"clr_type"` ClrWay string `json:"clr_way"` CvlservFlag string `json:"cvlserv_flag"` CvlservPay float64 `json:"cvlserv_pay"` FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"` FundPaySumamt float64 `json:"fund_pay_sumamt"` Gend string `json:"gend"` HifesPay float64 `json:"hifes_pay"` HifmiPay float64 `json:"hifmi_pay"` HifpPay float64 `json:"hifp_pay"` HospPartAmt float64 `json:"hosp_part_amt"` InscpScpAmt float64 `json:"inscp_scp_amt"` Insutype string `json:"insutype"` MafPay float64 `json:"maf_pay"` MdtrtCertType string `json:"mdtrt_cert_type"` HifobPay float64 `json:"hifob_pay"` MdtrtID string `json:"mdtrt_id"` MedType string `json:"med_type"` MedfeeSumamt float64 `json:"medfee_sumamt"` MedinsSetlID string `json:"medins_setl_id"` Naty string `json:"naty"` OthPay float64 `json:"oth_pay"` OverlmtSelfpay float64 `json:"overlmt_selfpay"` PoolPropSelfpay float64 `json:"pool_prop_selfpay"` PreselfpayAmt float64 `json:"preselfpay_amt"` PsnCashPay float64 `json:"psn_cash_pay"` PsnCertType string `json:"psn_cert_type"` PsnName string `json:"psn_name"` PsnNo string `json:"psn_no"` PsnPartAmt float64 `json:"psn_part_amt"` PsnType string `json:"psn_type"` SetlID string `json:"setl_id"` SetlTime string `json:"setl_time"` } `json:"setlinfo"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type ResultEight struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { Stmtinfo struct { SetlOptins string `json:"setl_optins"` StmtRslt string `json:"stmt_rslt"` StmtRsltDscr string `json:"stmt_rslt_dscr"` } `json:"stmtinfo"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type ResultNine struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { FileQuryNo string `json:"file_qury_no"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type ResultTen struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { DldEndtime string `json:"dld_endtime"` FileQuryNo string `json:"file_qury_no"` Filename string `json:"filename"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type ResultEleven struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { Setlinfo struct { FixmedinsName string `json:"fixmedins_name"` FixmedinsCode string `json:"fixmedins_code"` PsnNo string `json:"psn_no"` PsnName string `json:"psn_name"` HifobPay float64 `json:"hifob_pay"` Gend string `json:"gend"` Brdy string `json:"brdy"` PsnCertType string `json:"psn_cert_type"` PsnType string `json:"psn_type"` EmpName string `json:"emp_name"` Certno string `json:"certno"` Insutype string `json:"insutype"` MedfeeSumamt float64 `json:"medfee_sumamt"` FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"` OverlmtSelfpay float64 `json:"overlmt_selfpay"` PreselfpayAmt float64 `json:"preselfpay_amt"` InscpScpAmt float64 `json:"inscp_scp_amt"` ActPayDedc float64 `json:"act_pay_dedc"` HifpPay float64 `json:"hifp_pay"` PoolPropSelfpay float64 `json:"pool_prop_selfpay"` CvlservPay float64 `json:"cvlserv_pay"` HifesPay float64 `json:"hifes_pay"` HifmiPay float64 `json:"hifmi_pay"` MafPay float64 `json:"maf_pay"` OthPay float64 `json:"oth_pay"` FundPaySumamt float64 `json:"fund_pay_sumamt"` PsnPay float64 `json:"psn_pay"` AcctPay float64 `json:"acct_pay"` CashPayamt float64 `json:"cash_payamt"` Balc float64 `json:"balc"` AcctMulaidPay float64 `json:"acct_mulaid_pay"` MedinsSetlId string `json:"medins_setl_id"` RefdSetlFlag string `json:"refd_setl_flag"` SetlTime string `json:"setl_time"` MedType string `json:"med_type"` HospLv string `json:"hosp_lv"` } `json:"setlinfo"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type ResultTwelve struct { Cainfo string `json:"cainfo"` ErrMsg string `json:"err_msg"` InfRefmsgid string `json:"inf_refmsgid"` Infcode int64 `json:"infcode"` Output struct { MdtrtId string `json:"mdtrt_id"` ChrgBchno string `json:"chrg_bchno"` PsnNo string `json:"psn_no"` } `json:"output"` RefmsgTime string `json:"refmsg_time"` RespondTime string `json:"respond_time"` Signtype interface{} `json:"signtype"` WarnMsg interface{} `json:"warn_msg"` } type Custom struct { DetItemFeeSumamt string Cut string FeedetlSn string Price string MedListCodg string Type int64 AdviceId int64 ProjectId int64 ItemId int64 } //获取个人信息----挂号-----上传就诊信息 func (c *HisApiController) GetRegisterInfo() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") settlementValue, _ := c.GetInt64("settlement_value") medical_insurance_card := c.GetString("medical_insurance_card") name := c.GetString("name") id_card_type, _ := c.GetInt64("id_card_type") certificates, _ := c.GetInt64("certificates") medical_care, _ := c.GetInt64("medical_care") birthday := c.GetString("birthday") age, _ := c.GetInt64("age") id_card := c.GetString("id_card") register_type, _ := c.GetInt64("register") doctor, _ := c.GetInt64("doctor") department, _ := c.GetInt64("department") gender, _ := c.GetInt64("sex") phone := c.GetString("phone") registration_fee, _ := c.GetFloat("registration_fee") medical_expenses, _ := c.GetFloat("medical_expenses") social_type, _ := c.GetInt64("social_type") admin_user_id, _ := c.GetInt64("admin_user_id") diagnosis_id, _ := c.GetInt64("diagnosis") sick_type, _ := c.GetInt64("sick_type") reg_type := c.GetString("p_type") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc) birthUnix := birthdays.Unix() 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() adminInfo := c.GetAdminUserInfo() var patient service.Patients if id == 0 { patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId) } else { patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id) } patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime) if patientPrescription.ID == 0 { patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime) } //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id) diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id) sickConfig, _ := service.FindSickById(sick_type) miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId) if patient.ID == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(patient.IdCardNo) == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo) return } config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId) if config.IsOpen == 1 { api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey 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) if res.Infcode == 0 { his := models.VMHisPatient{ Name: name, Gender: gender, Birthday: birthUnix, MedicalTreatmentType: medical_care, IdType: certificates, IdCardNo: id_card, BalanceAccountsType: settlementValue, SocialType: social_type, MedicalInsuranceNumber: medical_insurance_card, RegisterType: register_type, RegisterCost: registration_fee, TreatmentCost: medical_expenses, Status: 1, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), 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(), UserOrgId: adminInfo.CurrentOrgId, AdminUserId: admin_user_id, IsReturn: 1, IdCardType: id_card_type, Doctor: doctor, Departments: department, } timestamp := time.Now().Unix() tempTime := time.Unix(timestamp, 0) timeFormat := tempTime.Format("20060102150405") chrgBchno := rand.Intn(100000) + 10000 ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10) count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId) department, _ := service.GetDepartMentDetail(patientPrescription.Departments) doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10) IdCardNo := "" if id_card_type == 1 { IdCardNo = medical_insurance_card } else { IdCardNo = patient.IdCardNo } if count <= 0 { api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" + res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no + "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code + "&dept_code=" + department.Number + "&doctor_id=" + doctor_id + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&id_card_type=" + strconv.FormatInt(int64(id_card_type), 10) 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 { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 2, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException) return } 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.Ctime = time.Now().Unix() his.Mtime = time.Now().Unix() his.Status = 1 err := service.CreateHisPatientTwo(&his) if err == nil { api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo + "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name + "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + reg_type + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName resp2, requestErr2 := http.Get(api2) if requestErr2 != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } body2, ioErr2 := ioutil.ReadAll(resp2.Body) if ioErr2 != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr2) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON2 map[string]interface{} if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{}) userJSONBytes2, _ := json.Marshal(respJSON2) var res2 ResultSix if err := json.Unmarshal(userJSONBytes2, &res2); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res2.Infcode == -1 { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res2.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 3, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException) return } c.ServeSuccessJSON(map[string]interface{}{ "his_info": his, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError) return } } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException) return } } else { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 1, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException) return } } else { timeStr := time.Now().Format("2006-01-02") timeArr := strings.Split(timeStr, "-") var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10) his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime) var hisPatient models.XtHisPatient if err == gorm.ErrRecordNotFound || his.ID == 0 { hisPatient = models.XtHisPatient{ Name: name, Age: age, Gender: gender, Birthday: birthUnix, Phone: phone, MedicalTreatmentType: medical_care, IdType: certificates, IdCardNo: id_card, BalanceAccountsType: settlementValue, SocialType: social_type, MedicalInsuranceNumber: medical_insurance_card, RegisterType: register_type, RegisterCost: registration_fee, TreatmentCost: medical_expenses, AdminUserId: admin_user_id, UserOrgId: adminInfo.CurrentOrgId, Status: 1, RecordDate: recordDateTime, IsReturn: 1, PatientId: patient.ID, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Number: str, } service.CreateHisPatient(&hisPatient) } c.ServeSuccessJSON(map[string]interface{}{ "his_info": hisPatient, }) } } //上传明细----预结算----确认订单 func (c *HisApiController) GetUploadInfo() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") pay_way, _ := c.GetInt64("pay_way") pay_price, _ := c.GetFloat("pay_price") pay_card_no := c.GetString("pay_card_no") discount_price, _ := c.GetFloat("discount_price") preferential_price, _ := c.GetFloat("preferential_price") reality_price, _ := c.GetFloat("reality_price") found_price, _ := c.GetFloat("found_price") medical_insurance_price, _ := c.GetFloat("medical_insurance_price") private_price, _ := c.GetFloat("private_price") settle_accounts_type, _ := c.GetInt64("settle_accounts_type") admin_user_id, _ := c.GetInt64("admin_user_id") 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() var prescriptions []*models.HisPrescription var start_time int64 var end_time int64 data := make(map[string]interface{}) if settle_accounts_type == 1 { //日结 prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime) data["pre"] = prescriptions } else { //月结 start_time_str := c.GetString("start_time") end_time_str := c.GetString("end_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordStartTime := theStartTime.Unix() start_time = recordStartTime theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordEndTime := theEndTime.Unix() end_time = recordEndTime prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime) data["pre"] = prescriptions } roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) 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) miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime) department, _ := service.GetDepartMentDetail(patientPrescription.Departments) strconv.FormatInt(his.PatientId, 10) client := &http.Client{} data["psn_no"] = his.PsnNo data["mdtrt_id"] = his.Number data["chrg_bchno"] = chrg_bchno data["org_name"] = miConfig.OrgName data["doctor"] = roles.UserName data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10) data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10) data["fixmedins_code"] = miConfig.Code if department.ID == 0 && adminUser.CurrentOrgId == 9919 { data["dept_code"] = "15" } else { data["dept_code"] = department.Number } data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs data["secret_key"] = miConfig.SecretKey var ids []int64 for _, item := range prescriptions { ids = append(ids, item.ID) } config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) if config.IsOpen == 1 { //对接了医保,走医保流程 bytesData, _ := json.Marshal(data) req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"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, PayWay: pay_way, PayPrice: pay_price, PayCardNo: pay_card_no, DiscountPrice: discount_price, PreferentialPrice: preferential_price, RealityPrice: reality_price, FoundPrice: found_price, MedicalInsurancePrice: medical_insurance_price, PrivatePrice: private_price, IsMedicineInsurance: 1, SettleType: settle_accounts_type, SettleStartTime: start_time, SettleEndTime: end_time, Creator: roles.ID, Modify: roles.ID, } err = service.CreateOrder(order) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException) 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) } service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime) 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)) } } } for _, item := range prescriptions { for _, subItem := range item.HisAdditionalCharge { 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 if his.IdCardType == 1 { cert_no = his.MedicalInsuranceNumber } else { cert_no = his.Certno } api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" + insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id + "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10) 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 ResultSeven if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == -1 { errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Number: chrg_bchno, ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 6, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException) return } else { order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id) order.OrderStatus = 2 order.MdtrtId = res.Output.Setlinfo.MdtrtID order.SetlId = res.Output.Setlinfo.SetlID order.PsnNo = res.Output.Setlinfo.PsnNo order.PsnName = res.Output.Setlinfo.PsnName order.PsnCertType = res.Output.Setlinfo.PsnCertType order.Certno = res.Output.Setlinfo.Certno order.Gend = res.Output.Setlinfo.Gend order.Naty = res.Output.Setlinfo.Naty order.Age = res.Output.Setlinfo.Age order.Insutype = res.Output.Setlinfo.Insutype order.PsnType = res.Output.Setlinfo.PsnType order.CvlservFlag = res.Output.Setlinfo.CvlservFlag order.SetlTime = res.Output.Setlinfo.SetlTime order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType order.MedType = res.Output.Setlinfo.MedType order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt order.ActPayDedc = res.Output.Setlinfo.ActPayDedc order.HifpPay = res.Output.Setlinfo.HifpPay order.CvlservPay = res.Output.Setlinfo.CvlservPay order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay order.HifesPay = res.Output.Setlinfo.HifesPay order.HifobPay = res.Output.Setlinfo.HifobPay order.MafPay = res.Output.Setlinfo.MafPay order.OthPay = res.Output.Setlinfo.OthPay order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt order.AcctPay = res.Output.Setlinfo.AcctPay order.PsnCashPay = res.Output.Setlinfo.PsnCashPay order.HospPartAmt = res.Output.Setlinfo.HospPartAmt order.Balc = res.Output.Setlinfo.Balc order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID order.ClrOptins = res.Output.Setlinfo.ClrOptins order.ClrWay = res.Output.Setlinfo.ClrWay order.Creator = order.Creator order.Modify = roles.ID setlDetail, _ := json.Marshal(res.Output.Setldetail) detailStr := string(setlDetail) order.SetlDetail = detailStr err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId) err = service.UpDateOrder(order) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "结算成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException) return } } } else { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 4, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException) return } } else { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 4, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException) return } } else { 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)) } } for _, subItem := range item.HisAdditionalCharge { total = total + (subItem.Price * float64(subItem.Count)) } } allTotal := fmt.Sprintf("%.2f", total) totals, _ := strconv.ParseFloat(allTotal, 64) order := &models.HisOrder{ UserOrgId: adminUser.CurrentOrgId, HisPatientId: his.ID, PatientId: id, SettleAccountsDate: recordDateTime, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, OrderStatus: 2, Number: chrg_bchno, MedfeeSumamt: totals, PayWay: pay_way, PayPrice: pay_price, PayCardNo: pay_card_no, DiscountPrice: discount_price, PreferentialPrice: preferential_price, RealityPrice: reality_price, FoundPrice: found_price, MedicalInsurancePrice: medical_insurance_price, PrivatePrice: private_price, } err = service.CreateOrder(order) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException) return } var customs []*Custom for _, item := range prescriptions { if item.Type == 1 { //药品 for _, subItem := range item.HisDoctorAdviceInfo { cus := &Custom{ AdviceId: subItem.ID, ProjectId: 0, DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", subItem.Price), MedListCodg: subItem.MedListCodg, Type: 1, } customs = append(customs, cus) } } if item.Type == 2 { //项目 for _, subItem := range item.HisPrescriptionProject { cus := &Custom{ AdviceId: 0, ProjectId: subItem.ID, DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), Cut: fmt.Sprintf("%.2f", float64(subItem.Count)), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(subItem.Price)), MedListCodg: subItem.MedListCodg, Type: 2, } customs = append(customs, cus) } } for _, item := range item.HisAdditionalCharge { cus := &Custom{ ItemId: item.ID, AdviceId: 0, ProjectId: 0, DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price), Cut: fmt.Sprintf("%.2f", float64(item.Count)), FeedetlSn: item.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(item.Price)), MedListCodg: item.XtHisAddtionConfig.Code, Type: 3, } customs = append(customs, cus) } } for _, item := range customs { var advice_id int64 = 0 var project_id int64 = 0 var item_id int64 = 0 var types int64 = 0 if item.Type == 1 { advice_id = item.AdviceId project_id = 0 item_id = 0 } else if item.Type == 2 { advice_id = 0 item_id = 0 project_id = item.ProjectId } else if item.Type == 3 { advice_id = 0 item_id = item.ItemId project_id = 0 } detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32) cut, _ := strconv.ParseFloat(item.Cut, 32) pric, _ := strconv.ParseFloat(item.Price, 32) info := &models.HisOrderInfo{ OrderNumber: order.Number, UploadDate: time.Now().Unix(), AdviceId: advice_id, DetItemFeeSumamt: detItemFeeSumamt, Cnt: cut, Pric: pric, PatientId: id, Status: 1, Mtime: time.Now().Unix(), Ctime: time.Now().Unix(), UserOrgId: adminUser.CurrentOrgId, HisPatientId: his.ID, OrderId: order.ID, ProjectId: project_id, Type: types, ItemId: item_id, } service.CreateOrderInfo(info) } //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime) err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "结算成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException) return } } } func (c *HisApiController) GetPreUploadInfo() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") settle_accounts_type, _ := c.GetInt64("settle_accounts_type") admin_user_id, _ := c.GetInt64("admin_user_id") 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() var prescriptions []*models.HisPrescription var start_time int64 var end_time int64 data := make(map[string]interface{}) if settle_accounts_type == 1 { //日结 prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime) data["pre"] = prescriptions } else { //月结 start_time_str := c.GetString("start_time") end_time_str := c.GetString("end_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordStartTime := theStartTime.Unix() start_time = recordStartTime theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordEndTime := theEndTime.Unix() end_time = recordEndTime prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime) data["pre"] = prescriptions } roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) 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) miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime) department, _ := service.GetDepartMentDetail(patientPrescription.Departments) strconv.FormatInt(his.PatientId, 10) client := &http.Client{} data["psn_no"] = his.PsnNo data["mdtrt_id"] = his.Number data["chrg_bchno"] = chrg_bchno data["org_name"] = miConfig.OrgName data["doctor"] = roles.UserName data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10) data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10) data["fixmedins_code"] = miConfig.Code data["dept_code"] = department.Number data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs data["secret_key"] = miConfig.SecretKey var ids []int64 for _, item := range prescriptions { ids = append(ids, item.ID) } config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) if config.IsOpen == 1 { //对接了医保,走医保流程 bytesData, _ := json.Marshal(data) req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"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, IsMedicineInsurance: 1, SettleType: settle_accounts_type, SettleStartTime: start_time, SettleEndTime: end_time, Creator: roles.ID, Modify: roles.ID, } err = service.CreateOrder(order) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException) 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) } service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime) 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)) } } } for _, item := range prescriptions { for _, subItem := range item.HisAdditionalCharge { 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 if his.IdCardType == 1 { cert_no = his.MedicalInsuranceNumber } else { cert_no = his.Certno } api := "http://127.0.0.1:9532/" + "gdyb/seven?cert_no=" + cert_no + "&insutype=" + insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id + "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10) 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 ResultSeven if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == -1 { errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Number: chrg_bchno, ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 7, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException) return } else { order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id) order.OrderStatus = 1 order.MdtrtId = res.Output.Setlinfo.MdtrtID order.SetlId = res.Output.Setlinfo.SetlID order.PsnNo = res.Output.Setlinfo.PsnNo order.PsnName = res.Output.Setlinfo.PsnName order.PsnCertType = res.Output.Setlinfo.PsnCertType order.Certno = res.Output.Setlinfo.Certno order.Gend = res.Output.Setlinfo.Gend order.Naty = res.Output.Setlinfo.Naty order.Age = res.Output.Setlinfo.Age order.Insutype = res.Output.Setlinfo.Insutype order.PsnType = res.Output.Setlinfo.PsnType order.CvlservFlag = res.Output.Setlinfo.CvlservFlag order.SetlTime = res.Output.Setlinfo.SetlTime order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType order.MedType = res.Output.Setlinfo.MedType order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt order.ActPayDedc = res.Output.Setlinfo.ActPayDedc order.HifpPay = res.Output.Setlinfo.HifpPay order.CvlservPay = res.Output.Setlinfo.CvlservPay order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay order.HifesPay = res.Output.Setlinfo.HifesPay order.HifobPay = res.Output.Setlinfo.HifobPay order.MafPay = res.Output.Setlinfo.MafPay order.OthPay = res.Output.Setlinfo.OthPay order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt order.AcctPay = res.Output.Setlinfo.AcctPay order.PsnCashPay = res.Output.Setlinfo.PsnCashPay order.HospPartAmt = res.Output.Setlinfo.HospPartAmt order.Balc = res.Output.Setlinfo.Balc order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID order.ClrOptins = res.Output.Setlinfo.ClrOptins order.ClrWay = res.Output.Setlinfo.ClrWay order.Creator = order.Creator order.Modify = roles.ID setlDetail, _ := json.Marshal(res.Output.Setldetail) detailStr := string(setlDetail) order.SetlDetail = detailStr //err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId) err = service.UpDateOrder(order) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "预结算成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException) return } } } else { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 4, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException) return } } else { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 4, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException) return } } else { 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)) } } for _, subItem := range item.HisAdditionalCharge { total = total + (subItem.Price * float64(subItem.Count)) } } allTotal := fmt.Sprintf("%.2f", total) totals, _ := strconv.ParseFloat(allTotal, 64) order := &models.HisOrder{ UserOrgId: adminUser.CurrentOrgId, HisPatientId: his.ID, PatientId: id, SettleAccountsDate: recordDateTime, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Status: 1, OrderStatus: 2, Number: chrg_bchno, MedfeeSumamt: totals, } err = service.CreateOrder(order) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException) return } var customs []*Custom for _, item := range prescriptions { if item.Type == 1 { //药品 for _, subItem := range item.HisDoctorAdviceInfo { cus := &Custom{ AdviceId: subItem.ID, ProjectId: 0, DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber), Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", subItem.Price), MedListCodg: subItem.MedListCodg, Type: 1, } customs = append(customs, cus) } } if item.Type == 2 { //项目 for _, subItem := range item.HisPrescriptionProject { cus := &Custom{ AdviceId: 0, ProjectId: subItem.ID, DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)), Cut: fmt.Sprintf("%.2f", float64(subItem.Count)), FeedetlSn: subItem.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(subItem.Price)), MedListCodg: subItem.MedListCodg, Type: 2, } customs = append(customs, cus) } } for _, item := range item.HisAdditionalCharge { cus := &Custom{ ItemId: item.ID, AdviceId: 0, ProjectId: 0, DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price), Cut: fmt.Sprintf("%.2f", float64(item.Count)), FeedetlSn: item.FeedetlSn, Price: fmt.Sprintf("%.2f", float64(item.Price)), MedListCodg: item.XtHisAddtionConfig.Code, Type: 3, } customs = append(customs, cus) } } for _, item := range customs { var advice_id int64 = 0 var project_id int64 = 0 var item_id int64 = 0 var types int64 = 0 if item.Type == 1 { advice_id = item.AdviceId project_id = 0 item_id = 0 } else if item.Type == 2 { advice_id = 0 item_id = 0 project_id = item.ProjectId } else if item.Type == 3 { advice_id = 0 item_id = item.ItemId project_id = 0 } detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32) cut, _ := strconv.ParseFloat(item.Cut, 32) pric, _ := strconv.ParseFloat(item.Price, 32) info := &models.HisOrderInfo{ OrderNumber: order.Number, UploadDate: time.Now().Unix(), AdviceId: advice_id, DetItemFeeSumamt: detItemFeeSumamt, Cnt: cut, Pric: pric, PatientId: id, Status: 1, Mtime: time.Now().Unix(), Ctime: time.Now().Unix(), UserOrgId: adminUser.CurrentOrgId, HisPatientId: his.ID, OrderId: order.ID, ProjectId: project_id, Type: types, ItemId: item_id, } service.CreateOrderInfo(info) } //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno) err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime) err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "结算成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException) return } } } func (c *HisApiController) GetSettleInfo() { id, _ := c.GetInt64("id") order_id, _ := c.GetInt64("order_id") record_time := c.GetString("record_time") pay_way, _ := c.GetInt64("pay_way") pay_price, _ := c.GetFloat("pay_price") pay_card_no := c.GetString("pay_card_no") discount_price, _ := c.GetFloat("discount_price") preferential_price, _ := c.GetFloat("preferential_price") reality_price, _ := c.GetFloat("reality_price") found_price, _ := c.GetFloat("found_price") medical_insurance_price, _ := c.GetFloat("medical_insurance_price") private_price, _ := c.GetFloat("private_price") settle_accounts_type, _ := c.GetInt64("settle_accounts_type") admin_user_id, _ := c.GetInt64("admin_user_id") 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() var prescriptions []*models.HisPrescription data := make(map[string]interface{}) if settle_accounts_type == 1 { //日结 prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime) data["pre"] = prescriptions } else { //月结 start_time_str := c.GetString("start_time") end_time_str := c.GetString("end_time") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordStartTime := theStartTime.Unix() theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordEndTime := theEndTime.Unix() prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime) data["pre"] = prescriptions } roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime) miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime) strconv.FormatInt(his.PatientId, 10) order_src, _ := service.GetHisOrderByID(order_id) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) if config.IsOpen == 1 { //对接了医保,走医保流程 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)) } } } for _, item := range prescriptions { for _, subItem := range item.HisAdditionalCharge { total = total + (subItem.Price * float64(subItem.Count)) } } allTotal := fmt.Sprintf("%.2f", total) var rf []*ResultFive json.Unmarshal([]byte(his.Iinfo), &rf) psn_no := order_src.PsnNo mdtrt_id := order_src.MdtrtId chrg_bchno := order_src.Number cert_no := order_src.Certno insutype := rf[0].Insutype if his.IdCardType == 1 { cert_no = his.MedicalInsuranceNumber } else { cert_no = his.Certno } api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" + insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id + "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10) + "&fulamt_ownpay_amt=" + strconv.FormatFloat(order_src.FulamtOwnpayAmt, 'E', -1, 64) + "&overlmt_selfpay=" + strconv.FormatFloat(order_src.OverlmtSelfPay, 'E', -1, 64) + "&preselfpay_amt=" + strconv.FormatFloat(order_src.PreselfpayAmt, 'E', -1, 64) + "&inscp_scp_amt=" + strconv.FormatFloat(order_src.InscpScpAmt, 'E', -1, 64) 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 ResultSeven if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == -1 { errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), Number: chrg_bchno, ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 6, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException) return } else { order_src.OrderStatus = 2 order_src.PayWay = pay_way order_src.PayPrice = pay_price order_src.PayCardNo = pay_card_no order_src.DiscountPrice = discount_price order_src.PreferentialPrice = preferential_price order_src.RealityPrice = reality_price order_src.FoundPrice = found_price order_src.MedicalInsurancePrice = medical_insurance_price order_src.PrivatePrice = private_price order_src.MdtrtId = res.Output.Setlinfo.MdtrtID order_src.SetlId = res.Output.Setlinfo.SetlID order_src.PsnNo = res.Output.Setlinfo.PsnNo order_src.PsnName = res.Output.Setlinfo.PsnName order_src.PsnCertType = res.Output.Setlinfo.PsnCertType order_src.Certno = res.Output.Setlinfo.Certno order_src.Gend = res.Output.Setlinfo.Gend order_src.Naty = res.Output.Setlinfo.Naty order_src.Age = res.Output.Setlinfo.Age order_src.Insutype = res.Output.Setlinfo.Insutype order_src.PsnType = res.Output.Setlinfo.PsnType order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag order_src.SetlTime = res.Output.Setlinfo.SetlTime order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType order_src.MedType = res.Output.Setlinfo.MedType order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc order_src.HifpPay = res.Output.Setlinfo.HifpPay order_src.CvlservPay = res.Output.Setlinfo.CvlservPay order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay order_src.HifesPay = res.Output.Setlinfo.HifesPay order_src.HifobPay = res.Output.Setlinfo.HifobPay order_src.MafPay = res.Output.Setlinfo.MafPay order_src.OthPay = res.Output.Setlinfo.OthPay order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt order_src.AcctPay = res.Output.Setlinfo.AcctPay order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt order_src.Balc = res.Output.Setlinfo.Balc order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID order_src.ClrOptins = res.Output.Setlinfo.ClrOptins order_src.ClrWay = res.Output.Setlinfo.ClrWay order_src.Creator = order_src.Creator order_src.Modify = roles.ID setlDetail, _ := json.Marshal(res.Output.Setldetail) detailStr := string(setlDetail) order_src.SetlDetail = detailStr err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId) err = service.UpDateOrder(order_src) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "结算成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException) return } } } } //退款 func (c *HisApiController) Refund() { order_id, _ := c.GetInt64("order_id") number := c.GetString("number") record_time := c.GetString("record_time") patient_id, _ := c.GetInt64("patient_id") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") adminUser := c.GetAdminUserInfo() theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) fmt.Println(err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) var order models.HisOrder order, _ = service.GetHisOrderByID(order_id) if order.ID == 0 { order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId) } miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) if config.IsOpen == 1 { //对接了医保,走医保流程 api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo + "&mdtrt_id=" + his.Number + "&doctor=" + "张俊杰" + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey resp, requestErr := http.Get(api) if requestErr != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } 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) fmt.Println(respJSON) fmt.Println(userJSONBytes) api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo + "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + "张俊杰" + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey resp2, requestErr2 := http.Get(api2) if requestErr2 != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } body2, ioErr2 := ioutil.ReadAll(resp2.Body) if ioErr2 != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr2) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON2 map[string]interface{} if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo + // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code + // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey //resp3, requestErr3 := http.Get(api3) //if requestErr3 != nil { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} // //body3, ioErr3 := ioutil.ReadAll(resp3.Body) //if ioErr3 != nil { // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} //var respJSON3 map[string]interface{} //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil { // utils.ErrorLog("接口返回数据解析JSON失败: %v", err) // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId) //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "退费成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else { err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "退费成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } func (c *HisApiController) RefundNumber() { record_time := c.GetString("record_time") patient_id, _ := c.GetInt64("patient_id") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") adminUser := c.GetAdminUserInfo() theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) fmt.Println(err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) //patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) //order, _ := service.GetHisOrderByID(order_id) miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) if config.IsOpen == 1 { //对接了医保,走医保流程 api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo + "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + "张俊杰" + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey resp3, requestErr3 := http.Get(api3) if requestErr3 != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } body3, ioErr3 := ioutil.ReadAll(resp3.Body) if ioErr3 != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr3) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON3 map[string]interface{} if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId) service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "退费成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else { //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId) //if err == nil { // c.ServeSuccessJSON(map[string]interface{}{ // "msg": "退费成功", // }) //} else { // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) // return //} } } func (c *HisApiController) RefundDetail() { order_id, _ := c.GetInt64("order_id") number := c.GetString("number") record_time := c.GetString("record_time") patient_id, _ := c.GetInt64("patient_id") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") adminUser := c.GetAdminUserInfo() theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) fmt.Println(err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) var order models.HisOrder order, _ = service.GetHisOrderByID(order_id) if order.ID == 0 { order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId) } if config.IsOpen == 1 { //对接了医保,走医保流程 api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo + "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey resp2, requestErr2 := http.Get(api2) if requestErr2 != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } body2, ioErr2 := ioutil.ReadAll(resp2.Body) if ioErr2 != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr2) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON2 map[string]interface{} if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "退费成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } else { err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "msg": "退费成功", }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } } } //对账 func (c *HisApiController) GetCheckAccount() { start_time := c.GetString("start_time") end_time := c.GetString("end_time") insutype := c.GetString("insutype") clr_type := c.GetString("clr_type") admin_user_id, _ := c.GetInt64("admin_user_id") adminUser := c.GetAdminUserInfo() miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc) endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc) orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type) orders_two, _ := service.GetOrderByTimeThree(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type) fixmedins_setl_cnt := int64(len(orders_two)) //撤销的算2条数据为一笔 for _, item := range orders_two { if item.OrderStatus == 3 { fixmedins_setl_cnt = fixmedins_setl_cnt + 1 } } var medfee_sumamt float64 var acct_pay float64 var fund_pay_sumamt float64 for _, item := range orders { medfee_sumamt = medfee_sumamt + item.MedfeeSumamt acct_pay = acct_pay + item.AcctPay fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt } var user_name string role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) if role.ID == 0 { user_name = "张俊杰" } else { user_name = role.UserName } if config.IsOpen == 1 { api := "http://127.0.0.1:9532/" + "gdyb/ten?" + "insutype=" + insutype + "&clr_type=" + clr_type + "&setl_optins=" + "定点医保中心" + "&stmt_begndate=" + start_time + "&stm_enddate=" + end_time + "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) + "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) + "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) + "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name fmt.Println(api) resp, requestErr := http.Get(api) if requestErr != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } body, ioErr := ioutil.ReadAll(resp.Body) fmt.Println(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 ResultEight if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == 0 { micc := &models.MedicalInsuranceCostCompare{ StartTime: startime.Unix(), EndTime: endtime.Unix(), Insutype: insutype, CheckType: 1, Num: fixmedins_setl_cnt, Mtime: time.Now().Unix(), Status: 1, UserOrgId: adminUser.CurrentOrgId, CostTotal: medfee_sumamt, FuncTotal: fund_pay_sumamt, PsnPay: acct_pay, Creator: admin_user_id, Ctime: time.Now().Unix(), } err := service.CreateMedicalInsuranceCostCompareRecord(micc) if err == nil { c.ServeSuccessJSON(map[string]interface{}{ "stmt_rslt": res.Output.Stmtinfo.StmtRslt, "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr, }) } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) } } else { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) } } } //对账明细 func (c *HisApiController) GetCheckDetailAccount() { start_time := c.GetString("start_time") end_time := c.GetString("end_time") admin_user_id, _ := c.GetInt64("admin_user_id") adminUser := c.GetAdminUserInfo() miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc) endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc) orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId) Mkdir(miConfig.OrgName) file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10) file_name := file + ".txt" zip_name := file + ".zip" zip_path := miConfig.OrgName + "/" + zip_name file_path := miConfig.OrgName + "/" + file_name decimal.DivisionPrecision = 2 var medfee_sumamt float64 var psn_cash_pay float64 var fund_pay_sumamt float64 fixmedins_setl_cnt := int64(len(orders)) for _, item := range orders { medfee_sumamt = medfee_sumamt + item.MedfeeSumamt psn_cash_pay = psn_cash_pay + item.PsnCashPay fund_pay_sumamt = fund_pay_sumamt + item.FundPaySumamt } f, err := os.Create(miConfig.OrgName + "/" + file_name) defer f.Close() if err != nil { fmt.Println(err.Error()) } else { for _, item := range orders { var refd_setl_flag string if item.OrderStatus == 2 { refd_setl_flag = "0" } if item.OrderStatus == 3 { refd_setl_flag = "1" } var str string str = item.SetlId + " " + item.MdtrtId + " " + item.PsnNo + " " + fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " + fmt.Sprintf("%.2f", item.FundPaySumamt) + " " + fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n" _, err = f.Write([]byte(str)) } } Zip(file_path, zip_path) fmt.Println(ReadFile(zip_path)) fmt.Println(string(ReadFile(zip_path))) if config.IsOpen == 1 { var user_name string role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) if role.ID == 0 { user_name = "管理员" } else { user_name = role.UserName } baseParams := models.BaseParams{ SecretKey: miConfig.SecretKey, FixmedinsCode: miConfig.Code, InsuplcAdmdvs: miConfig.InsuplcAdmdvs, MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs, OrgName: miConfig.OrgName, Doctor: user_name, } result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path)) var dat map[string]interface{} if err := json.Unmarshal([]byte(result), &dat); err == nil { fmt.Println(dat) } else { fmt.Println(err) } userJSONBytes, _ := json.Marshal(dat) var res ResultNine if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == 0 { api := "http://127.0.0.1:9532/" + "gdyb/twelve?" + "file_qury_no=" + res.Output.FileQuryNo + "&setl_optins=" + "定点医保中心" + "&stmt_begndate=" + start_time + "&stm_enddate=" + end_time + "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) + "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) + "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) + "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&org_name=" + miConfig.OrgName + "&doctor=" + user_name resp, requestErr := http.Get(api) if requestErr != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } 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 ResultTen if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res.Infcode == 0 { service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo) micc := &models.MedicalInsuranceCostCompare{ StartTime: startime.Unix(), EndTime: endtime.Unix(), Insutype: "0", CheckType: 2, Num: fixmedins_setl_cnt, Mtime: time.Now().Unix(), Status: 1, UserOrgId: adminUser.CurrentOrgId, CostTotal: medfee_sumamt, FuncTotal: fund_pay_sumamt, PsnPay: psn_cash_pay, Creator: admin_user_id, Ctime: time.Now().Unix(), } service.CreateMedicalInsuranceCostCompareRecord(micc) c.ServeSuccessJSON(map[string]interface{}{ "msg": "明细对账成功", }) } } else { } } } func (c *HisApiController) GetSettleAccounts() { //id, _ := c.GetInt64("id") //record_time := c.GetString("record_time") order_id, _ := c.GetInt64("order_id") admin_user_id, _ := c.GetInt64("admin_user_id") //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() //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime) order, _ := service.GetHisOrderByID(order_id) orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number) var bedCostTotal float64 = 0 //床位总费 var bedCostSelfTotal float64 = 0 //床位自费 var bedCostPartSelfTotal float64 = 0 //床位部分项目自费 var operationCostTotal float64 = 0 //手术费 var operationCostSelfTotal float64 = 0 //手术费 var operationCostPartSelfTotal float64 = 0 //手术费 var otherCostTotal float64 = 0 //其他费用 var otherCostSelfTotal float64 = 0 //其他费用 var otherCostPartSelfTotal float64 = 0 //其他费用 var materialCostTotal float64 = 0 //材料费 var materialCostSelfTotal float64 = 0 //材料费 var materialCostPartSelfTotal float64 = 0 //材料费 var westernMedicineCostTotal float64 = 0 //西药费 var westernMedicineCostSelfTotal float64 = 0 //西药费 var westernMedicineCostPartSelfTotal float64 = 0 //西药费 var chineseTraditionalMedicineCostTotal float64 = 0 //中成药 var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药 var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药 var checkCostTotal float64 = 0 //检查费 var checkCostSelfTotal float64 = 0 //检查费 var checkCostPartSelfTotal float64 = 0 //检查费 var laboratoryCostTotal float64 = 0 //化验费 var laboratoryCostSelfTotal float64 = 0 //化验费 var laboratoryCostPartSelfTotal float64 = 0 //化验费 var treatCostTotal float64 = 0 //治疗费用 var treatCostSelfTotal float64 = 0 //治疗费用 var treatCostPartSelfTotal float64 = 0 //治疗费用 decimal.DivisionPrecision = 2 for _, item := range orderInfos { if item.MedChrgitmType == "01" { //床位费 bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "03" { //检查费 checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "04" { //化验费 laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "05" { //治疗费 treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "06" { //手术费 operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "08" { //材料费 materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "09" { //西药费 westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "11" { //中成费 chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } if item.MedChrgitmType == "14" { //其他费 otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64() otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64() } } miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) var user_name string role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) if role.ID == 0 { user_name = "管理员" } else { user_name = role.UserName } baseParams := models.BaseParams{ SecretKey: miConfig.SecretKey, FixmedinsCode: miConfig.Code, InsuplcAdmdvs: miConfig.InsuplcAdmdvs, MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs, OrgName: miConfig.OrgName, Doctor: user_name, } businessParams := models.BusinessParams{ PsnNo: order.PsnNo, MdtrtId: order.MdtrtId, SetlId: order.SetlId, } if config.IsOpen == 1 { result := service.Gdyb5203(baseParams, businessParams) var dat map[string]interface{} if err := json.Unmarshal([]byte(result), &dat); err == nil { fmt.Println(dat) } else { fmt.Println(err) } userJSONBytes, _ := json.Marshal(dat) var res ResultEleven if err := json.Unmarshal(userJSONBytes, &res); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id) charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator) if res.Infcode == 0 { c.ServeSuccessJSON(map[string]interface{}{ "charge_admin": charge_admin, "printor_admin": printor_admin, "info": res.Output.Setlinfo, "bedCostTotal": bedCostTotal, "bedCostSelfTotal": bedCostSelfTotal, "bedCostPartSelfTotal": bedCostPartSelfTotal, "operationCostTotal": operationCostTotal, "operationCostSelfTotal": operationCostSelfTotal, "operationCostPartSelfTotal": operationCostPartSelfTotal, "otherCostTotal": otherCostTotal, "otherCostSelfTotal": otherCostSelfTotal, "otherCostPartSelfTotal": otherCostPartSelfTotal, "materialCostTotal": materialCostTotal, "materialCostSelfTotal": materialCostSelfTotal, "materialCostPartSelfTotal": materialCostPartSelfTotal, "westernMedicineCostTotal": westernMedicineCostTotal, "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal, "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal, "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal, "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal, "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal, "checkCostTotal": checkCostTotal, "checkCostSelfTotal": checkCostSelfTotal, "checkCostPartSelfTotal": checkCostPartSelfTotal, "laboratoryCostTotal": laboratoryCostTotal, "laboratoryCostSelfTotal": laboratoryCostSelfTotal, "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal, "treatCostTotal": treatCostTotal, "treatCostSelfTotal": treatCostSelfTotal, "treatCostPartSelfTotal": treatCostPartSelfTotal, }) } } } func (c *HisApiController) GetCode() { name := c.GetString("name") codg := c.GetString("codg") adminUser := c.GetAdminUserInfo() miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) var user_name string role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id) if role.ID == 0 { user_name = "xxx" } else { user_name = role.UserName } baseParams := &models.BaseParams{ SecretKey: miConfig.SecretKey, FixmedinsCode: miConfig.Code, InsuplcAdmdvs: miConfig.InsuplcAdmdvs, MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs, OrgName: miConfig.OrgName, Doctor: user_name, } if config.IsOpen == 1 { result := service.Gdyb3301(baseParams, name, codg) var dat map[string]interface{} if err := json.Unmarshal([]byte(result), &dat); err == nil { fmt.Println(dat) } else { fmt.Println(err) } } } func (c *HisApiController) CheckTreatment() { patient_id, _ := c.GetInt64("patient_id", 0) record_time := c.GetString("record_time") insutype := c.GetString("insutype") timeLayout := "2006-01-02" loc, _ := time.LoadLocation("Local") adminUser := c.GetAdminUserInfo() theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc) fmt.Println(err) if err != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong) return } recordDateTime := theTime.Unix() his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime) miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId) config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId) var user_name string role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id) if role.ID == 0 { user_name = "xxx" } else { user_name = role.UserName } baseParams := models.BaseParams{ SecretKey: miConfig.SecretKey, FixmedinsCode: miConfig.Code, InsuplcAdmdvs: miConfig.InsuplcAdmdvs, MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs, OrgName: miConfig.OrgName, Doctor: user_name, } if config.IsOpen == 1 { result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10)) var dat map[string]interface{} if err := json.Unmarshal([]byte(result), &dat); err == nil { fmt.Println(dat) } else { fmt.Println(err) } } } func (c *HisApiController) PutRecord() { 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() adminInfo := c.GetAdminUserInfo() patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id) patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime) miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId) fmt.Println(miConfig.SecretKey) if patient == nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist) return } if len(patient.IdCardNo) == 0 { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo) return } config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId) if config.IsOpen == 1 { api := "http://127.0.0.1:9532/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey 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) if res.Infcode == 0 { his := models.VMHisPatient{ Status: 1, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), 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(), UserOrgId: adminInfo.CurrentOrgId, AdminUserId: adminInfo.AdminUser.Id, IsReturn: 1, } doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10) result := service.Gdyb2503(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801") result2 := service.Gdyb5301(his.PsnNo, res.Output.Iinfo[0].Insutype, miConfig.OrgName, patientPrescription.Doctor, miConfig.Code, doctor_id, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, "重症尿毒症透析(血透)", "M07801") var dat map[string]interface{} if err := json.Unmarshal([]byte(result), &dat); err == nil { fmt.Println(dat) } else { fmt.Println(err) } var dat2 map[string]interface{} if err := json.Unmarshal([]byte(result2), &dat2); err == nil { fmt.Println(dat2) } else { fmt.Println(err) } } else { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 1, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException) return } } } func (c *HisApiController) GetUploadDiag() { id, _ := c.GetInt64("id") record_time := c.GetString("record_time") diagnosis_id, _ := c.GetInt64("diagnosis") sick_type, _ := c.GetInt64("sick_type") reg_type, _ := c.GetInt64("reg_type") 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 } var patientPrescription models.HisPrescriptionInfo recordDateTime := theTime.Unix() adminInfo := c.GetAdminUserInfo() patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime) if patientPrescription.ID == 0 { patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime) } miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId) diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id) his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime) sickConfig, _ := service.FindSickById(sick_type) department, _ := service.GetDepartMentDetail(patientPrescription.Departments) api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo + "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name + "&diag=" + diagnosisConfig.ClassName + "&org_name=" + miConfig.OrgName + "&med_type=" + strconv.FormatInt(reg_type, 10) + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code + "&diag_code=" + diagnosisConfig.CountryCode + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName resp2, requestErr2 := http.Get(api2) if requestErr2 != nil { c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } body2, ioErr2 := ioutil.ReadAll(resp2.Body) if ioErr2 != nil { utils.ErrorLog("接口返回数据读取失败: %v", ioErr2) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } var respJSON2 map[string]interface{} if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil { utils.ErrorLog("接口返回数据解析JSON失败: %v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{}) userJSONBytes2, _ := json.Marshal(respJSON2) var res2 ResultSix if err := json.Unmarshal(userJSONBytes2, &res2); err != nil { utils.ErrorLog("解析失败:%v", err) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException) return } if res2.Infcode == -1 { adminUser := c.GetAdminUserInfo() errlog := &models.HisOrderError{ UserOrgId: adminUser.CurrentOrgId, Ctime: time.Now().Unix(), Mtime: time.Now().Unix(), ErrMsg: res2.ErrMsg, Status: 1, PatientId: id, RecordTime: recordDateTime, Stage: 3, } service.CreateErrMsgLog(errlog) c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException) return } c.ServeSuccessJSON(map[string]interface{}{ "msg": "上传成功", }) } func PathExists(path string) (bool, error) { _, err := os.Stat(path) if err == nil { return true, nil } if os.IsNotExist(err) { return false, nil } return false, err } //创建文件夹 func Mkdir(dir string) { // 创建文件夹 exist, err := PathExists(dir) if err != nil { fmt.Println(err.Error()) } else { if exist { fmt.Println(dir + "文件夹已存在!") } else { // 文件夹名称,权限 err := os.Mkdir(dir, os.ModePerm) if err != nil { fmt.Println(dir+"文件夹创建失败:", err.Error()) } else { fmt.Println(dir + "文件夹创建成功!") } } } } //压缩文件 func Zip(srcFile string, destZip string) error { zipfile, err := os.Create(destZip) if err != nil { return err } defer zipfile.Close() archive := zip.NewWriter(zipfile) defer archive.Close() filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error { if err != nil { return err } header, err := zip.FileInfoHeader(info) if err != nil { return err } header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/") // header.Name = path if info.IsDir() { header.Name += "/" } else { header.Method = zip.Deflate } writer, err := archive.CreateHeader(header) if err != nil { return err } if !info.IsDir() { file, err := os.Open(path) if err != nil { return err } defer file.Close() _, err = io.Copy(writer, file) } return err }) return err } func ReadFile(filePath string) []byte { f, err := os.Open(filePath) if err != nil { fmt.Println("read file fail", err) return nil } defer f.Close() fd, err := ioutil.ReadAll(f) if err != nil { fmt.Println("read to fd fail", err) return nil } return fd } func RemoveRepeatedCode(arr []string) (newArr []string) { newArr = make([]string, 0) for i := 0; i < len(arr); i++ { repeat := false for j := i + 1; j < len(arr); j++ { if arr[i] == arr[j] { repeat = true break } } if !repeat { newArr = append(newArr, arr[i]) } } return } //func ShowMessage1(caption, text string, style uintptr) (result int) { // user32, _ := syscall.LoadLibrary("SSCard.dll") // messageBox, _ := syscall.GetProcAddress(user32, "MessageBoxW") // defer syscall.FreeLibrary(user32) // // ret, _, _ := syscall.Syscall9(messageBox, // 4, // 0, // StrPtr(text), // StrPtr(caption), // style, // 0, 0, 0, 0, 0) // result = int(ret) // return //} //func StrPtr3(s string) uintptr { // return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s))) //}