his_api_controller.go 110KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114
  1. package sg
  2. import (
  3. "C"
  4. "archive/zip"
  5. "bytes"
  6. "encoding/json"
  7. "fmt"
  8. "gdyb/controllers"
  9. "gdyb/enums"
  10. "gdyb/models"
  11. "gdyb/service"
  12. "gdyb/utils"
  13. "github.com/astaxie/beego"
  14. "github.com/jinzhu/gorm"
  15. "github.com/shopspring/decimal"
  16. "io"
  17. "io/ioutil"
  18. "math/rand"
  19. "net/http"
  20. "os"
  21. "path/filepath"
  22. //"runtime/cgo"
  23. "strconv"
  24. "strings"
  25. "syscall"
  26. "time"
  27. "unsafe"
  28. )
  29. type HisApiController struct {
  30. controllers.BaseAuthAPIController
  31. }
  32. func HisManagerApiRegistRouters() {
  33. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  34. beego.Router("/api/diag/upload", &HisApiController{}, "get:GetUploadDiag")
  35. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  36. beego.Router("/api/settle/get", &HisApiController{}, "get:GetSettleInfo")
  37. beego.Router("/api/settle/query", &HisApiController{}, "get:GetSettleAccounts")
  38. beego.Router("/api/checkaccount/get", &HisApiController{}, "get:GetCheckAccount")
  39. beego.Router("/api/checkdetailaccount/get", &HisApiController{}, "get:GetCheckDetailAccount")
  40. beego.Router("/api/refund/post", &HisApiController{}, "get:Refund")
  41. //beego.Router("/api/sscard", &HisApiController{}, "get:Sscard")
  42. beego.Router("/api/refundnumber/post", &HisApiController{}, "get:RefundNumber")
  43. beego.Router("/api/refunddetail/post", &HisApiController{}, "get:RefundDetail")
  44. beego.Router("/api/treatment/check", &HisApiController{}, "get:CheckTreatment")
  45. beego.Router("/api/record/put", &HisApiController{}, "get:PutRecord")
  46. beego.Router("/api/patient/info", &HisApiController{}, "get:GetHisPatientInfo")
  47. beego.Router("/api/org/info", &HisApiController{}, "get:GetOrgInfo")
  48. beego.Router("/api/testcard", &HisApiController{}, "get:TestGetBasBaseInfo")
  49. beego.Router("/api/testpay", &HisApiController{}, "get:TestPay")
  50. }
  51. var (
  52. str = make([]*byte, 1024)
  53. str1 = make([]*byte, 1024)
  54. )
  55. func (c *HisApiController) TestPay() {
  56. DllDef := syscall.MustLoadDLL("SSSE32.dll")
  57. readCard := DllDef.MustFindProc("ReadCardBas")
  58. str := make([]byte, 256)
  59. str1 := make([]byte, 256)
  60. ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  61. if err2 != nil {
  62. fmt.Println("SSCard的运算结果为:", ret2)
  63. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  64. return
  65. }
  66. }
  67. func (c *HisApiController) TestGetBasBaseInfo() {
  68. result := C.Init(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  69. fmt.Println(result)
  70. cs1 := C.CString("")
  71. cs2 := C.CString("")
  72. C.ReadCardBas(cs1, IntPtr(1024), cs2, IntPtr(1024))
  73. fmt.Println(cs1)
  74. fmt.Println(cs2)
  75. C.free(unsafe.Pointer(cs1))
  76. C.free(unsafe.Pointer(cs2))
  77. //
  78. //DllDef := syscall.MustLoadDLL("SSCard.dll")
  79. //Iinit := DllDef.MustFindProc("Init")
  80. //readCard := DllDef.MustFindProc("ReadCardBas")
  81. //ret, _, err := Iinit.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  82. //if ret != 0 {
  83. // fmt.Println("SSCard的报错原因:", err)
  84. // fmt.Println("SSCard的运算结果为:", ret)
  85. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  86. // return
  87. //}
  88. //
  89. //result := int(ret)
  90. //fmt.Println("SSCard的运算结果为1:", result)
  91. //if readCard == nil {
  92. // fmt.Println("readcard is nil")
  93. // readCard = DllDef.MustFindProc("ReadCardBas")
  94. //}
  95. //if readCard == nil {
  96. // fmt.Println("readcard reload is nil")
  97. // return
  98. //}
  99. //ret2, _, err2 := readCard.Call((uintptr)(unsafe.Pointer(str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(str1[0])), IntPtr(1024))
  100. //fmt.Println(" Add(4,5)的结果为:", ret2)
  101. //fmt.Println(" str:", str)
  102. //fmt.Println(" str1:", str1)
  103. //if err2 != nil {
  104. // fmt.Println("SSCard的运算结果为:", ret2)
  105. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  106. // return
  107. //}
  108. }
  109. func (c *HisApiController) GetOrgInfo() {
  110. miConfig, _ := service.FindMedicalInsuranceInfo(9919)
  111. service.Gdyb1201("", miConfig.OrgName, "1122", miConfig.Code, miConfig.InsuplcAdmdvs, miConfig.MdtrtareaAdmvs, miConfig.SecretKey, 1, "")
  112. }
  113. func (c *HisApiController) GetHisPatientInfo() {
  114. medical_insurance_card := c.GetString("medical_insurance_card")
  115. id_card_type, _ := c.GetInt64("id_card_type")
  116. id_card := c.GetString("id_card")
  117. adminInfo := c.GetAdminUserInfo()
  118. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  119. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  120. appRole, _ := service.GetAppRole(adminInfo.CurrentOrgId)
  121. IdCardNo := ""
  122. if id_card_type == 1 {
  123. IdCardNo = medical_insurance_card
  124. } else if id_card_type == 2 {
  125. IdCardNo = id_card
  126. }
  127. if config.IsOpen == 1 {
  128. 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
  129. resp, requestErr := http.Get(api)
  130. if requestErr != nil {
  131. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  132. return
  133. }
  134. defer resp.Body.Close()
  135. body, ioErr := ioutil.ReadAll(resp.Body)
  136. if ioErr != nil {
  137. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  138. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  139. return
  140. }
  141. var respJSON map[string]interface{}
  142. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  143. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  145. return
  146. }
  147. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  148. userJSONBytes, _ := json.Marshal(userJSON)
  149. var res ResultTwo
  150. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  151. utils.ErrorLog("解析失败:%v", err)
  152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  153. return
  154. }
  155. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  156. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  157. infoStr := string(Iinfos)
  158. idetinfoStr := string(Idetinfos)
  159. if res.Infcode == 0 {
  160. his := models.VMHisPatient{
  161. Status: 1,
  162. Ctime: time.Now().Unix(),
  163. Mtime: time.Now().Unix(),
  164. PsnNo: res.Output.Baseinfo.PsnNo,
  165. PsnCertType: res.Output.Baseinfo.PsnCertType,
  166. Certno: res.Output.Baseinfo.Certno,
  167. PsnName: res.Output.Baseinfo.PsnName,
  168. Gend: res.Output.Baseinfo.Gend,
  169. Naty: res.Output.Baseinfo.Naty,
  170. Brdy: res.Output.Baseinfo.Brdy,
  171. Age: res.Output.Baseinfo.Age,
  172. Iinfo: infoStr,
  173. Idetinfo: idetinfoStr,
  174. UserOrgId: adminInfo.CurrentOrgId,
  175. IsReturn: 1,
  176. IdCardType: id_card_type,
  177. }
  178. c.ServeSuccessJSON(map[string]interface{}{
  179. "info": his,
  180. })
  181. } else {
  182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  183. return
  184. }
  185. }
  186. }
  187. //func (c *HisApiController) Sscard() {
  188. // id_card_type, _ := c.GetInt64("id_card_type")
  189. // adminUser := c.GetAdminUserInfo()
  190. // miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  191. //
  192. // r := CardInit()
  193. // fmt.Println(r)
  194. // //if r == 0 {
  195. // switch id_card_type {
  196. // case 1:
  197. // basStr, err := GetBasBaseInfo()
  198. //
  199. // if err != nil {
  200. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  201. // return
  202. //
  203. // } else {
  204. // fmt.Println(basStr)
  205. //
  206. // bas := strings.Split(basStr, "|")
  207. //
  208. // basNumber := bas[1]
  209. //
  210. // //basNumber := bas[2]
  211. // card_sn := bas[3]
  212. //
  213. // appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  214. //
  215. // 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
  216. // resp, requestErr := http.Get(api)
  217. // if requestErr != nil {
  218. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  219. // return
  220. // }
  221. // defer resp.Body.Close()
  222. // body, ioErr := ioutil.ReadAll(resp.Body)
  223. // if ioErr != nil {
  224. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  225. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  226. // return
  227. // }
  228. // var respJSON map[string]interface{}
  229. //
  230. // if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  231. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  232. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  233. // return
  234. // }
  235. //
  236. // userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  237. // userJSONBytes, _ := json.Marshal(userJSON)
  238. // var res ResultTwo
  239. // if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  240. // utils.ErrorLog("解析失败:%v", err)
  241. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  242. // return
  243. // }
  244. // Iinfos, _ := json.Marshal(res.Output.Iinfo)
  245. // Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  246. // infoStr := string(Iinfos)
  247. // idetinfoStr := string(Idetinfos)
  248. //
  249. // if res.Infcode == 0 {
  250. // his := models.VMHisPatient{
  251. // Status: 1,
  252. // Ctime: time.Now().Unix(),
  253. // Mtime: time.Now().Unix(),
  254. // PsnNo: res.Output.Baseinfo.PsnNo,
  255. // PsnCertType: res.Output.Baseinfo.PsnCertType,
  256. // Certno: res.Output.Baseinfo.Certno,
  257. // PsnName: res.Output.Baseinfo.PsnName,
  258. // Gend: res.Output.Baseinfo.Gend,
  259. // Naty: res.Output.Baseinfo.Naty,
  260. // Brdy: res.Output.Baseinfo.Brdy,
  261. // Age: res.Output.Baseinfo.Age,
  262. // Iinfo: infoStr,
  263. // Idetinfo: idetinfoStr,
  264. // UserOrgId: adminUser.CurrentOrgId,
  265. // IsReturn: 1,
  266. // IdCardType: id_card_type,
  267. // }
  268. //
  269. // patient, err := service.GetPatientByNumber(basNumber, adminUser.CurrentOrgId)
  270. // if err == gorm.ErrRecordNotFound {
  271. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  272. // return
  273. //
  274. // } else if err != nil {
  275. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  276. // return
  277. //
  278. // } else {
  279. // c.ServeSuccessJSON(map[string]interface{}{
  280. // "patient": patient,
  281. // "his": his,
  282. // "number": basNumber,
  283. // })
  284. // }
  285. // } else {
  286. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisFailedException)
  287. // return
  288. // }
  289. //
  290. // }
  291. //
  292. // break
  293. // case 2:
  294. // ////SFZStr, err := GetSFZBaseInfo()
  295. // //if err != nil {
  296. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeReadCardException)
  297. // // return
  298. // //
  299. // //} else {
  300. // //
  301. // // id_card_str := strings.Split(SFZStr, "^")
  302. // // id_card_number := id_card_str[0]
  303. // //appRole, _ := service.GetAppRole(adminUser.CurrentOrgId)
  304. // //
  305. // //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)
  306. // //resp, requestErr := http.Get(api)
  307. // //if requestErr != nil {
  308. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  309. // // return
  310. // //}
  311. // //defer resp.Body.Close()
  312. // //body, ioErr := ioutil.ReadAll(resp.Body)
  313. // //if ioErr != nil {
  314. // // utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  315. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  316. // // return
  317. // //}
  318. // //var respJSON map[string]interface{}
  319. // //
  320. // //if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  321. // // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  322. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  323. // // return
  324. // //}
  325. // //
  326. // //userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  327. // //userJSONBytes, _ := json.Marshal(userJSON)
  328. // //var res ResultTwo
  329. // //if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  330. // // utils.ErrorLog("解析失败:%v", err)
  331. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  332. // // return
  333. // //}
  334. // //Iinfos, _ := json.Marshal(res.Output.Iinfo)
  335. // //Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  336. // //infoStr := string(Iinfos)
  337. // //idetinfoStr := string(Idetinfos)
  338. // //
  339. // //if res.Infcode == 0 {
  340. // // his := models.VMHisPatient{
  341. // // Status: 1,
  342. // // Ctime: time.Now().Unix(),
  343. // // Mtime: time.Now().Unix(),
  344. // // PsnNo: res.Output.Baseinfo.PsnNo,
  345. // // PsnCertType: res.Output.Baseinfo.PsnCertType,
  346. // // Certno: res.Output.Baseinfo.Certno,
  347. // // PsnName: res.Output.Baseinfo.PsnName,
  348. // // Gend: res.Output.Baseinfo.Gend,
  349. // // Naty: res.Output.Baseinfo.Naty,
  350. // // Brdy: res.Output.Baseinfo.Brdy,
  351. // // Age: res.Output.Baseinfo.Age,
  352. // // Iinfo: infoStr,
  353. // // Idetinfo: idetinfoStr,
  354. // // UserOrgId: adminUser.CurrentOrgId,
  355. // // IsReturn: 1,
  356. // // IdCardType: id_card_type,
  357. // // }
  358. //
  359. // // patient, err := service.GetPatientByNumber(id_card_number, adminUser.CurrentOrgId)
  360. // // if err == gorm.ErrRecordNotFound {
  361. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoPateintException)
  362. // // return
  363. // //
  364. // // } else if err != nil {
  365. // // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  366. // // return
  367. // //
  368. // // } else {
  369. // // c.ServeSuccessJSON(map[string]interface{}{
  370. // // "patient": patient,
  371. // // "number": id_card_number,
  372. // // })
  373. // // }
  374. // //}
  375. // break
  376. // case 3:
  377. //
  378. // break
  379. //
  380. // }
  381. //}
  382. //func GetBasBaseInfo() (jsonStr string, err error) {
  383. //
  384. // handle, err := syscall.LoadLibrary("SSCard.dll")
  385. // if err != nil {
  386. // fmt.Printf("Error: %s\n", err)
  387. // return "", err
  388. // }
  389. // defer syscall.FreeLibrary(handle)
  390. // str := make([]byte, 256)
  391. // str1 := make([]byte, 256)
  392. // add, err := syscall.GetProcAddress(handle, "ReadCardBas")
  393. // if err != nil {
  394. // fmt.Printf("Error: %s\n", err)
  395. // return "", err
  396. // }
  397. // ret, _, _ := syscall.Syscall(add, (uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  398. // if err != nil {
  399. // fmt.Printf("Error: %s\n", err)
  400. // }
  401. // fmt.Println("> Add(4,5)的结果为:", ret)
  402. // //return nil
  403. //
  404. // //
  405. // //handle := syscall.NewLazyDLL("SSCard.dll")
  406. // //ReadCardBas := handle.NewProc("ReadCardBas")
  407. // //
  408. // //var str2 [1024]C.char
  409. // //var str3 [1024]C.char
  410. // //
  411. // //
  412. // //
  413. // ////sssssswwwww
  414. // ////a := 256
  415. // //
  416. // //r, _, _ := ReadCardBas.Call(&str2, 1024, &str3, 1024)
  417. // //fmt.Println(r)
  418. // ////p := (*byte)(unsafe.Pointer(r))
  419. // // define a slice to fill with the p string
  420. // //data := make([]byte, 0)
  421. //
  422. // // loop until find '\0'
  423. // //if *p != 0 {
  424. // //
  425. // // //data = append(data, *p) // append 1 byte
  426. // // //r += unsafe.Sizeof(byte(0)) // move r to next byte
  427. // // //p = (*byte)(unsafe.Pointer(r)) // get the byte value
  428. // //} else {
  429. // // return "", nil
  430. // //
  431. // //}
  432. //
  433. // return "", nil
  434. //
  435. //}
  436. //func GetSFZBaseInfo() (jsonStr string, err error) {
  437. // //handle := syscall.MustLoadDLL("SSCard.dll")
  438. //
  439. // str := make([]byte, 256)
  440. // str1 := make([]byte, 256)
  441. // r, _, _ := ReadIDCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  442. //
  443. // fmt.Println(r)
  444. // return string(str), nil
  445. //}
  446. //func GetQRBaseInfo() (jsonStr string, err error) {
  447. // handle := syscall.LoadDLL("SSCard.dll")
  448. // ReadCardBas := handle.FindProc("GetQRBase")
  449. //
  450. // str := make([]byte, 256)
  451. // str1 := make([]byte, 256)
  452. // r, _, _ := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  453. //
  454. // fmt.Println(string(str))
  455. // fmt.Println(r)
  456. // return string(str), nil
  457. //}
  458. func CardInit() int {
  459. DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  460. add := DllTestDef.MustFindProc("Init")
  461. ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  462. if err != nil {
  463. fmt.Println("SSCard的运算结果为:", ret)
  464. }
  465. result := int(ret)
  466. return result
  467. }
  468. //func CardInit() int {
  469. // ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  470. // if err != nil {
  471. // fmt.Println("SSCard的运算结果为:", ret)
  472. // }
  473. // fmt.Println(err)
  474. // result := int(ret)
  475. // return result
  476. //}
  477. func IntPtr(n int) uintptr {
  478. return uintptr(n)
  479. }
  480. func StrPtr(s string) uintptr {
  481. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  482. }
  483. type ResultTwo struct {
  484. ErrMsg string `json:"err_msg"`
  485. InfRefmsgid string `json:"inf_refmsgid"`
  486. Infcode int64 `json:"infcode"`
  487. Output struct {
  488. Baseinfo struct {
  489. Age float64 `json:"age"`
  490. Brdy string `json:"brdy"`
  491. Certno string `json:"certno"`
  492. Gend string `json:"gend"`
  493. Naty string `json:"naty"`
  494. PsnCertType string `json:"psn_cert_type"`
  495. PsnName string `json:"psn_name"`
  496. PsnNo string `json:"psn_no"`
  497. } `json:"baseinfo"`
  498. Idetinfo []interface{} `json:"idetinfo"`
  499. Iinfo []struct {
  500. Balc int64 `json:"balc"`
  501. CvlservFlag string `json:"cvlserv_flag"`
  502. EmpName string `json:"emp_name"`
  503. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  504. Insutype string `json:"insutype"`
  505. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  506. PausInsuDate interface{} `json:"paus_insu_date"`
  507. PsnInsuDate string `json:"psn_insu_date"`
  508. PsnInsuStas string `json:"psn_insu_stas"`
  509. PsnType string `json:"psn_type"`
  510. } `json:"insuinfo"`
  511. } `json:"output"`
  512. RefmsgTime string `json:"refmsg_time"`
  513. RespondTime string `json:"respond_time"`
  514. Signtype interface{} `json:"signtype"`
  515. WarnInfo interface{} `json:"warn_info"`
  516. }
  517. type ResultThree struct {
  518. Cainfo interface{} `json:"cainfo"`
  519. ErrMsg string `json:"err_msg"`
  520. InfRefmsgid string `json:"inf_refmsgid"`
  521. Infcode int64 `json:"infcode"`
  522. Output struct {
  523. Data struct {
  524. IptOtpNo string `json:"ipt_otp_no"`
  525. MdtrtID string `json:"mdtrt_id"`
  526. PsnNo string `json:"psn_no"`
  527. } `json:"data"`
  528. } `json:"output"`
  529. RefmsgTime string `json:"refmsg_time"`
  530. RespondTime string `json:"respond_time"`
  531. Signtype interface{} `json:"signtype"`
  532. WarnMsg interface{} `json:"warn_msg"`
  533. }
  534. type ResultFour struct {
  535. Cainfo string `json:"cainfo"`
  536. ErrMsg string `json:"err_msg"`
  537. InfRefmsgid string `json:"inf_refmsgid"`
  538. Infcode int64 `json:"infcode"`
  539. Output struct {
  540. Result []struct {
  541. BasMednFlag string `json:"bas_medn_flag"`
  542. ChldMedcFlag string `json:"chld_medc_flag"`
  543. ChrgitmLv string `json:"chrgitm_lv"`
  544. Cnt float64 `json:"cnt"`
  545. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  546. DrtReimFlag string `json:"drt_reim_flag"`
  547. FeedetlSn string `json:"feedetl_sn"`
  548. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  549. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  550. InscpScpAmt float64 `json:"inscp_scp_amt"`
  551. ListSpItemFlag string `json:"list_sp_item_flag"`
  552. LmtUsedFlag string `json:"lmt_used_flag"`
  553. MedChrgitmType string `json:"med_chrgitm_type"`
  554. Memo string `json:"memo"`
  555. OverlmtAmt float64 `json:"overlmt_amt"`
  556. PreselfpayAmt float64 `json:"preselfpay_amt"`
  557. Pric float64 `json:"pric"`
  558. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  559. SelfpayProp float64 `json:"selfpay_prop"`
  560. } `json:"result"`
  561. } `json:"output"`
  562. RefmsgTime string `json:"refmsg_time"`
  563. RespondTime string `json:"respond_time"`
  564. Signtype string `json:"signtype"`
  565. WarnMsg string `json:"warn_msg"`
  566. }
  567. type ResultFive struct {
  568. Insutype string `json:"insutype"`
  569. }
  570. type ResultSix struct {
  571. Cainfo interface{} `json:"cainfo"`
  572. ErrMsg string `json:"err_msg"`
  573. InfRefmsgid string `json:"inf_refmsgid"`
  574. Infcode int64 `json:"infcode"`
  575. Output struct {
  576. } `json:"output"`
  577. RefmsgTime string `json:"refmsg_time"`
  578. RespondTime string `json:"respond_time"`
  579. Signtype interface{} `json:"signtype"`
  580. WarnMsg interface{} `json:"warn_msg"`
  581. }
  582. type ResultSeven struct {
  583. Cainfo string `json:"cainfo"`
  584. ErrMsg string `json:"err_msg"`
  585. InfRefmsgid string `json:"inf_refmsgid"`
  586. Infcode int64 `json:"infcode"`
  587. Output struct {
  588. Setldetail []interface{} `json:"setldetail"`
  589. Setlinfo struct {
  590. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  591. AcctPay float64 `json:"acct_pay"`
  592. ActPayDedc float64 `json:"act_pay_dedc"`
  593. Age float64 `json:"age"`
  594. Balc float64 `json:"balc"`
  595. Brdy string `json:"brdy"`
  596. Certno string `json:"certno"`
  597. ClrOptins string `json:"clr_optins"`
  598. ClrType string `json:"clr_type"`
  599. ClrWay string `json:"clr_way"`
  600. CvlservFlag string `json:"cvlserv_flag"`
  601. CvlservPay float64 `json:"cvlserv_pay"`
  602. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  603. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  604. Gend string `json:"gend"`
  605. HifesPay float64 `json:"hifes_pay"`
  606. HifmiPay float64 `json:"hifmi_pay"`
  607. HifpPay float64 `json:"hifp_pay"`
  608. HospPartAmt float64 `json:"hosp_part_amt"`
  609. InscpScpAmt float64 `json:"inscp_scp_amt"`
  610. Insutype string `json:"insutype"`
  611. MafPay float64 `json:"maf_pay"`
  612. MdtrtCertType string `json:"mdtrt_cert_type"`
  613. HifobPay float64 `json:"hifob_pay"`
  614. MdtrtID string `json:"mdtrt_id"`
  615. MedType string `json:"med_type"`
  616. MedfeeSumamt float64 `json:"medfee_sumamt"`
  617. MedinsSetlID string `json:"medins_setl_id"`
  618. Naty string `json:"naty"`
  619. OthPay float64 `json:"oth_pay"`
  620. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  621. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  622. PreselfpayAmt float64 `json:"preselfpay_amt"`
  623. PsnCashPay float64 `json:"psn_cash_pay"`
  624. PsnCertType string `json:"psn_cert_type"`
  625. PsnName string `json:"psn_name"`
  626. PsnNo string `json:"psn_no"`
  627. PsnPartAmt float64 `json:"psn_part_amt"`
  628. PsnType string `json:"psn_type"`
  629. SetlID string `json:"setl_id"`
  630. SetlTime string `json:"setl_time"`
  631. } `json:"setlinfo"`
  632. } `json:"output"`
  633. RefmsgTime string `json:"refmsg_time"`
  634. RespondTime string `json:"respond_time"`
  635. Signtype interface{} `json:"signtype"`
  636. WarnMsg interface{} `json:"warn_msg"`
  637. }
  638. type ResultEight struct {
  639. Cainfo string `json:"cainfo"`
  640. ErrMsg string `json:"err_msg"`
  641. InfRefmsgid string `json:"inf_refmsgid"`
  642. Infcode int64 `json:"infcode"`
  643. Output struct {
  644. Stmtinfo struct {
  645. SetlOptins string `json:"setl_optins"`
  646. StmtRslt string `json:"stmt_rslt"`
  647. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  648. } `json:"stmtinfo"`
  649. } `json:"output"`
  650. RefmsgTime string `json:"refmsg_time"`
  651. RespondTime string `json:"respond_time"`
  652. Signtype interface{} `json:"signtype"`
  653. WarnMsg interface{} `json:"warn_msg"`
  654. }
  655. type ResultNine struct {
  656. Cainfo string `json:"cainfo"`
  657. ErrMsg string `json:"err_msg"`
  658. InfRefmsgid string `json:"inf_refmsgid"`
  659. Infcode int64 `json:"infcode"`
  660. Output struct {
  661. FileQuryNo string `json:"file_qury_no"`
  662. } `json:"output"`
  663. RefmsgTime string `json:"refmsg_time"`
  664. RespondTime string `json:"respond_time"`
  665. Signtype interface{} `json:"signtype"`
  666. WarnMsg interface{} `json:"warn_msg"`
  667. }
  668. type ResultTen struct {
  669. Cainfo string `json:"cainfo"`
  670. ErrMsg string `json:"err_msg"`
  671. InfRefmsgid string `json:"inf_refmsgid"`
  672. Infcode int64 `json:"infcode"`
  673. Output struct {
  674. DldEndtime string `json:"dld_endtime"`
  675. FileQuryNo string `json:"file_qury_no"`
  676. Filename string `json:"filename"`
  677. } `json:"output"`
  678. RefmsgTime string `json:"refmsg_time"`
  679. RespondTime string `json:"respond_time"`
  680. Signtype interface{} `json:"signtype"`
  681. WarnMsg interface{} `json:"warn_msg"`
  682. }
  683. type ResultEleven struct {
  684. Cainfo string `json:"cainfo"`
  685. ErrMsg string `json:"err_msg"`
  686. InfRefmsgid string `json:"inf_refmsgid"`
  687. Infcode int64 `json:"infcode"`
  688. Output struct {
  689. Setlinfo struct {
  690. FixmedinsName string `json:"fixmedins_name"`
  691. FixmedinsCode string `json:"fixmedins_code"`
  692. PsnNo string `json:"psn_no"`
  693. PsnName string `json:"psn_name"`
  694. HifobPay float64 `json:"hifob_pay"`
  695. Gend string `json:"gend"`
  696. Brdy string `json:"brdy"`
  697. PsnCertType string `json:"psn_cert_type"`
  698. PsnType string `json:"psn_type"`
  699. EmpName string `json:"emp_name"`
  700. Certno string `json:"certno"`
  701. Insutype string `json:"insutype"`
  702. MedfeeSumamt float64 `json:"medfee_sumamt"`
  703. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  704. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  705. PreselfpayAmt float64 `json:"preselfpay_amt"`
  706. InscpScpAmt float64 `json:"inscp_scp_amt"`
  707. ActPayDedc float64 `json:"act_pay_dedc"`
  708. HifpPay float64 `json:"hifp_pay"`
  709. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  710. CvlservPay float64 `json:"cvlserv_pay"`
  711. HifesPay float64 `json:"hifes_pay"`
  712. HifmiPay float64 `json:"hifmi_pay"`
  713. MafPay float64 `json:"maf_pay"`
  714. OthPay float64 `json:"oth_pay"`
  715. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  716. PsnPay float64 `json:"psn_pay"`
  717. AcctPay float64 `json:"acct_pay"`
  718. CashPayamt float64 `json:"cash_payamt"`
  719. Balc float64 `json:"balc"`
  720. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  721. MedinsSetlId string `json:"medins_setl_id"`
  722. RefdSetlFlag string `json:"refd_setl_flag"`
  723. SetlTime string `json:"setl_time"`
  724. MedType string `json:"med_type"`
  725. HospLv string `json:"hosp_lv"`
  726. } `json:"setlinfo"`
  727. } `json:"output"`
  728. RefmsgTime string `json:"refmsg_time"`
  729. RespondTime string `json:"respond_time"`
  730. Signtype interface{} `json:"signtype"`
  731. WarnMsg interface{} `json:"warn_msg"`
  732. }
  733. type ResultTwelve struct {
  734. Cainfo string `json:"cainfo"`
  735. ErrMsg string `json:"err_msg"`
  736. InfRefmsgid string `json:"inf_refmsgid"`
  737. Infcode int64 `json:"infcode"`
  738. Output struct {
  739. MdtrtId string `json:"mdtrt_id"`
  740. ChrgBchno string `json:"chrg_bchno"`
  741. PsnNo string `json:"psn_no"`
  742. } `json:"output"`
  743. RefmsgTime string `json:"refmsg_time"`
  744. RespondTime string `json:"respond_time"`
  745. Signtype interface{} `json:"signtype"`
  746. WarnMsg interface{} `json:"warn_msg"`
  747. }
  748. type Custom struct {
  749. DetItemFeeSumamt string
  750. Cut string
  751. FeedetlSn string
  752. Price string
  753. MedListCodg string
  754. Type int64
  755. AdviceId int64
  756. ProjectId int64
  757. ItemId int64
  758. }
  759. //获取个人信息----挂号-----上传就诊信息
  760. func (c *HisApiController) GetRegisterInfo() {
  761. id, _ := c.GetInt64("id")
  762. record_time := c.GetString("record_time")
  763. settlementValue, _ := c.GetInt64("settlement_value")
  764. medical_insurance_card := c.GetString("medical_insurance_card")
  765. name := c.GetString("name")
  766. id_card_type, _ := c.GetInt64("id_card_type")
  767. certificates, _ := c.GetInt64("certificates")
  768. medical_care, _ := c.GetInt64("medical_care")
  769. birthday := c.GetString("birthday")
  770. age, _ := c.GetInt64("age")
  771. id_card := c.GetString("id_card")
  772. register_type, _ := c.GetInt64("register")
  773. doctor, _ := c.GetInt64("doctor")
  774. department, _ := c.GetInt64("department")
  775. gender, _ := c.GetInt64("sex")
  776. phone := c.GetString("phone")
  777. registration_fee, _ := c.GetFloat("registration_fee")
  778. medical_expenses, _ := c.GetFloat("medical_expenses")
  779. social_type, _ := c.GetInt64("social_type")
  780. admin_user_id, _ := c.GetInt64("admin_user_id")
  781. diagnosis_id, _ := c.GetInt64("diagnosis")
  782. sick_type, _ := c.GetInt64("sick_type")
  783. reg_type := c.GetString("p_type")
  784. timeLayout := "2006-01-02"
  785. loc, _ := time.LoadLocation("Local")
  786. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  787. birthUnix := birthdays.Unix()
  788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  789. if err != nil {
  790. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  791. return
  792. }
  793. recordDateTime := theTime.Unix()
  794. adminInfo := c.GetAdminUserInfo()
  795. var patient service.Patients
  796. if id == 0 {
  797. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  798. } else {
  799. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  800. }
  801. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  802. if patientPrescription.ID == 0 {
  803. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  804. }
  805. //adminRole, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  806. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  807. sickConfig, _ := service.FindSickById(sick_type)
  808. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  809. if patient.ID == 0 {
  810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  811. return
  812. }
  813. if len(patient.IdCardNo) == 0 {
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  815. return
  816. }
  817. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  818. if config.IsOpen == 1 {
  819. 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
  820. resp, requestErr := http.Get(api)
  821. if requestErr != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  823. return
  824. }
  825. defer resp.Body.Close()
  826. body, ioErr := ioutil.ReadAll(resp.Body)
  827. if ioErr != nil {
  828. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  829. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  830. return
  831. }
  832. var respJSON map[string]interface{}
  833. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  834. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  836. return
  837. }
  838. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  839. userJSONBytes, _ := json.Marshal(userJSON)
  840. var res ResultTwo
  841. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  842. utils.ErrorLog("解析失败:%v", err)
  843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  844. return
  845. }
  846. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  847. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  848. infoStr := string(Iinfos)
  849. idetinfoStr := string(Idetinfos)
  850. if res.Infcode == 0 {
  851. his := models.VMHisPatient{
  852. Name: name,
  853. Gender: gender,
  854. Birthday: birthUnix,
  855. MedicalTreatmentType: medical_care,
  856. IdType: certificates,
  857. IdCardNo: id_card,
  858. BalanceAccountsType: settlementValue,
  859. SocialType: social_type,
  860. MedicalInsuranceNumber: medical_insurance_card,
  861. RegisterType: register_type,
  862. RegisterCost: registration_fee,
  863. TreatmentCost: medical_expenses,
  864. Status: 1,
  865. Ctime: time.Now().Unix(),
  866. Mtime: time.Now().Unix(),
  867. PsnNo: res.Output.Baseinfo.PsnNo,
  868. PsnCertType: res.Output.Baseinfo.PsnCertType,
  869. Certno: res.Output.Baseinfo.Certno,
  870. PsnName: res.Output.Baseinfo.PsnName,
  871. Gend: res.Output.Baseinfo.Gend,
  872. Naty: res.Output.Baseinfo.Naty,
  873. Brdy: res.Output.Baseinfo.Brdy,
  874. Age: res.Output.Baseinfo.Age,
  875. Iinfo: infoStr,
  876. Idetinfo: idetinfoStr,
  877. PatientId: patient.ID,
  878. RecordDate: theTime.Unix(),
  879. UserOrgId: adminInfo.CurrentOrgId,
  880. AdminUserId: admin_user_id,
  881. IsReturn: 1,
  882. IdCardType: id_card_type,
  883. Doctor: doctor,
  884. Departments: department,
  885. }
  886. timestamp := time.Now().Unix()
  887. tempTime := time.Unix(timestamp, 0)
  888. timeFormat := tempTime.Format("20060102150405")
  889. chrgBchno := rand.Intn(100000) + 10000
  890. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  891. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  892. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  893. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  894. IdCardNo := ""
  895. if id_card_type == 1 {
  896. IdCardNo = medical_insurance_card
  897. } else {
  898. IdCardNo = patient.IdCardNo
  899. }
  900. if count <= 0 {
  901. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + IdCardNo + "&insutype=" +
  902. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  903. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  904. "&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)
  905. resp, requestErr := http.Get(api)
  906. if requestErr != nil {
  907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  908. return
  909. }
  910. defer resp.Body.Close()
  911. body, ioErr := ioutil.ReadAll(resp.Body)
  912. if ioErr != nil {
  913. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  915. return
  916. }
  917. var respJSON map[string]interface{}
  918. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  919. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  920. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  921. return
  922. }
  923. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  924. userJSONBytes, _ := json.Marshal(respJSON)
  925. var res ResultThree
  926. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  927. utils.ErrorLog("解析失败:%v", err)
  928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  929. return
  930. }
  931. if res.Infcode == -1 {
  932. adminUser := c.GetAdminUserInfo()
  933. errlog := &models.HisOrderError{
  934. UserOrgId: adminUser.CurrentOrgId,
  935. Ctime: time.Now().Unix(),
  936. Mtime: time.Now().Unix(),
  937. ErrMsg: res.ErrMsg,
  938. Status: 1,
  939. PatientId: id,
  940. RecordTime: recordDateTime,
  941. Stage: 2,
  942. }
  943. service.CreateErrMsgLog(errlog)
  944. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  945. return
  946. }
  947. his.Number = res.Output.Data.MdtrtID
  948. his.PsnNo = res.Output.Data.PsnNo
  949. his.IptOtpNo = res.Output.Data.IptOtpNo
  950. his.IdCardNo = patient.IdCardNo
  951. his.PhoneNumber = patient.Phone
  952. his.UserOrgId = adminInfo.CurrentOrgId
  953. his.Ctime = time.Now().Unix()
  954. his.Mtime = time.Now().Unix()
  955. his.Status = 1
  956. err := service.CreateHisPatientTwo(&his)
  957. if err == nil {
  958. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  959. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  960. "&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 +
  961. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  962. resp2, requestErr2 := http.Get(api2)
  963. if requestErr2 != nil {
  964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  965. return
  966. }
  967. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  968. if ioErr2 != nil {
  969. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  970. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  971. return
  972. }
  973. var respJSON2 map[string]interface{}
  974. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  975. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  976. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  977. return
  978. }
  979. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  980. userJSONBytes2, _ := json.Marshal(respJSON2)
  981. var res2 ResultSix
  982. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  983. utils.ErrorLog("解析失败:%v", err)
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  985. return
  986. }
  987. if res2.Infcode == -1 {
  988. adminUser := c.GetAdminUserInfo()
  989. errlog := &models.HisOrderError{
  990. UserOrgId: adminUser.CurrentOrgId,
  991. Ctime: time.Now().Unix(),
  992. Mtime: time.Now().Unix(),
  993. ErrMsg: res2.ErrMsg,
  994. Status: 1,
  995. PatientId: id,
  996. RecordTime: recordDateTime,
  997. Stage: 3,
  998. }
  999. service.CreateErrMsgLog(errlog)
  1000. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  1001. return
  1002. }
  1003. c.ServeSuccessJSON(map[string]interface{}{
  1004. "his_info": his,
  1005. })
  1006. } else {
  1007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1008. return
  1009. }
  1010. } else {
  1011. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1012. return
  1013. }
  1014. } else {
  1015. adminUser := c.GetAdminUserInfo()
  1016. errlog := &models.HisOrderError{
  1017. UserOrgId: adminUser.CurrentOrgId,
  1018. Ctime: time.Now().Unix(),
  1019. Mtime: time.Now().Unix(),
  1020. ErrMsg: res.ErrMsg,
  1021. Status: 1,
  1022. PatientId: id,
  1023. RecordTime: recordDateTime,
  1024. Stage: 1,
  1025. }
  1026. service.CreateErrMsgLog(errlog)
  1027. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  1028. return
  1029. }
  1030. } else {
  1031. timeStr := time.Now().Format("2006-01-02")
  1032. timeArr := strings.Split(timeStr, "-")
  1033. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1034. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1035. var hisPatient models.XtHisPatient
  1036. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1037. hisPatient = models.XtHisPatient{
  1038. Name: name,
  1039. Age: age,
  1040. Gender: gender,
  1041. Birthday: birthUnix,
  1042. Phone: phone,
  1043. MedicalTreatmentType: medical_care,
  1044. IdType: certificates,
  1045. IdCardNo: id_card,
  1046. BalanceAccountsType: settlementValue,
  1047. SocialType: social_type,
  1048. MedicalInsuranceNumber: medical_insurance_card,
  1049. RegisterType: register_type,
  1050. RegisterCost: registration_fee,
  1051. TreatmentCost: medical_expenses,
  1052. AdminUserId: admin_user_id,
  1053. UserOrgId: adminInfo.CurrentOrgId,
  1054. Status: 1,
  1055. RecordDate: recordDateTime,
  1056. IsReturn: 1,
  1057. PatientId: patient.ID,
  1058. Ctime: time.Now().Unix(),
  1059. Mtime: time.Now().Unix(),
  1060. Number: str,
  1061. }
  1062. service.CreateHisPatient(&hisPatient)
  1063. }
  1064. c.ServeSuccessJSON(map[string]interface{}{
  1065. "his_info": hisPatient,
  1066. })
  1067. }
  1068. }
  1069. //上传明细----预结算----确认订单
  1070. func (c *HisApiController) GetUploadInfo() {
  1071. id, _ := c.GetInt64("id")
  1072. record_time := c.GetString("record_time")
  1073. pay_way, _ := c.GetInt64("pay_way")
  1074. pay_price, _ := c.GetFloat("pay_price")
  1075. pay_card_no := c.GetString("pay_card_no")
  1076. discount_price, _ := c.GetFloat("discount_price")
  1077. preferential_price, _ := c.GetFloat("preferential_price")
  1078. reality_price, _ := c.GetFloat("reality_price")
  1079. found_price, _ := c.GetFloat("found_price")
  1080. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1081. private_price, _ := c.GetFloat("private_price")
  1082. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1083. admin_user_id, _ := c.GetInt64("admin_user_id")
  1084. timeLayout := "2006-01-02"
  1085. loc, _ := time.LoadLocation("Local")
  1086. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1087. if err != nil {
  1088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1089. return
  1090. }
  1091. recordDateTime := theTime.Unix()
  1092. adminUser := c.GetAdminUserInfo()
  1093. var prescriptions []*models.HisPrescription
  1094. var start_time int64
  1095. var end_time int64
  1096. data := make(map[string]interface{})
  1097. if settle_accounts_type == 1 { //日结
  1098. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1099. data["pre"] = prescriptions
  1100. } else { //月结
  1101. start_time_str := c.GetString("start_time")
  1102. end_time_str := c.GetString("end_time")
  1103. timeLayout := "2006-01-02"
  1104. loc, _ := time.LoadLocation("Local")
  1105. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1106. if err != nil {
  1107. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1108. return
  1109. }
  1110. recordStartTime := theStartTime.Unix()
  1111. start_time = recordStartTime
  1112. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1113. if err != nil {
  1114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1115. return
  1116. }
  1117. recordEndTime := theEndTime.Unix()
  1118. end_time = recordEndTime
  1119. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1120. data["pre"] = prescriptions
  1121. }
  1122. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1123. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1124. timestamp := time.Now().Unix()
  1125. tempTime := time.Unix(timestamp, 0)
  1126. timeFormat := tempTime.Format("20060102150405")
  1127. chrgBchno := rand.Intn(100000) + 10000
  1128. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1129. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1130. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1131. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1132. strconv.FormatInt(his.PatientId, 10)
  1133. client := &http.Client{}
  1134. data["psn_no"] = his.PsnNo
  1135. data["mdtrt_id"] = his.Number
  1136. data["chrg_bchno"] = chrg_bchno
  1137. data["org_name"] = miConfig.OrgName
  1138. data["doctor"] = roles.UserName
  1139. data["doctor_id"] = strconv.FormatInt(roles.AdminUserId, 10)
  1140. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1141. data["fixmedins_code"] = miConfig.Code
  1142. data["dept_code"] = department.Number
  1143. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1144. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1145. data["secret_key"] = miConfig.SecretKey
  1146. var ids []int64
  1147. for _, item := range prescriptions {
  1148. ids = append(ids, item.ID)
  1149. }
  1150. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1151. if config.IsOpen == 1 { //对接了医保,走医保流程
  1152. bytesData, _ := json.Marshal(data)
  1153. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1154. resp, _ := client.Do(req)
  1155. defer resp.Body.Close()
  1156. body, ioErr := ioutil.ReadAll(resp.Body)
  1157. if ioErr != nil {
  1158. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1160. return
  1161. }
  1162. var respJSON map[string]interface{}
  1163. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1164. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1165. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1166. return
  1167. }
  1168. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1169. userJSONBytes, _ := json.Marshal(respJSON)
  1170. var res ResultFour
  1171. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1172. utils.ErrorLog("解析失败:%v", err)
  1173. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1174. return
  1175. }
  1176. if res.Infcode == 0 {
  1177. order := &models.HisOrder{
  1178. UserOrgId: adminUser.CurrentOrgId,
  1179. HisPatientId: his.ID,
  1180. PatientId: his.PatientId,
  1181. SettleAccountsDate: recordDateTime,
  1182. Ctime: time.Now().Unix(),
  1183. Mtime: time.Now().Unix(),
  1184. Status: 1,
  1185. Number: chrg_bchno,
  1186. Infcode: res.Infcode,
  1187. WarnMsg: res.WarnMsg,
  1188. Cainfo: res.Cainfo,
  1189. ErrMsg: res.ErrMsg,
  1190. RespondTime: res.RefmsgTime,
  1191. InfRefmsgid: res.InfRefmsgid,
  1192. OrderStatus: 1,
  1193. PayWay: pay_way,
  1194. PayPrice: pay_price,
  1195. PayCardNo: pay_card_no,
  1196. DiscountPrice: discount_price,
  1197. PreferentialPrice: preferential_price,
  1198. RealityPrice: reality_price,
  1199. FoundPrice: found_price,
  1200. MedicalInsurancePrice: medical_insurance_price,
  1201. PrivatePrice: private_price,
  1202. IsMedicineInsurance: 1,
  1203. SettleType: settle_accounts_type,
  1204. SettleStartTime: start_time,
  1205. SettleEndTime: end_time,
  1206. Creator: roles.ID,
  1207. Modify: roles.ID,
  1208. }
  1209. err = service.CreateOrder(order)
  1210. if err != nil {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1212. return
  1213. }
  1214. for _, item := range res.Output.Result {
  1215. temp := strings.Split(item.FeedetlSn, "-")
  1216. var advice_id int64 = 0
  1217. var project_id int64 = 0
  1218. var types int64 = 0
  1219. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1220. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1221. if temp[1] == "1" {
  1222. advice_id = id
  1223. project_id = 0
  1224. } else if temp[1] == "2" {
  1225. advice_id = 0
  1226. project_id = id
  1227. }
  1228. info := &models.HisOrderInfo{
  1229. OrderNumber: order.Number,
  1230. FeedetlSn: item.FeedetlSn,
  1231. UploadDate: time.Now().Unix(),
  1232. AdviceId: advice_id,
  1233. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1234. Cnt: item.Cnt,
  1235. Pric: float64(item.Pric),
  1236. PatientId: his.PatientId,
  1237. PricUplmtAmt: item.PricUplmtAmt,
  1238. SelfpayProp: item.SelfpayProp,
  1239. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1240. OverlmtAmt: item.OverlmtAmt,
  1241. PreselfpayAmt: item.PreselfpayAmt,
  1242. BasMednFlag: item.BasMednFlag,
  1243. MedChrgitmType: item.MedChrgitmType,
  1244. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1245. Status: 1,
  1246. Memo: item.Memo,
  1247. Mtime: time.Now().Unix(),
  1248. InscpScpAmt: item.InscpScpAmt,
  1249. DrtReimFlag: item.DrtReimFlag,
  1250. Ctime: time.Now().Unix(),
  1251. ListSpItemFlag: item.ListSpItemFlag,
  1252. ChldMedcFlag: item.ChldMedcFlag,
  1253. LmtUsedFlag: item.LmtUsedFlag,
  1254. ChrgitmLv: item.ChrgitmLv,
  1255. UserOrgId: adminUser.CurrentOrgId,
  1256. HisPatientId: his.ID,
  1257. OrderId: order.ID,
  1258. ProjectId: project_id,
  1259. Type: types,
  1260. }
  1261. service.CreateOrderInfo(info)
  1262. }
  1263. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1264. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1265. var total float64
  1266. for _, item := range prescriptions {
  1267. if item.Type == 1 { //药品
  1268. for _, subItem := range item.HisDoctorAdviceInfo {
  1269. total = total + (subItem.Price * subItem.PrescribingNumber)
  1270. }
  1271. }
  1272. if item.Type == 2 { //项目
  1273. for _, subItem := range item.HisPrescriptionProject {
  1274. total = total + (subItem.Price * float64(subItem.Count))
  1275. }
  1276. }
  1277. }
  1278. for _, item := range prescriptions {
  1279. for _, subItem := range item.HisAdditionalCharge {
  1280. total = total + (subItem.Price * float64(subItem.Count))
  1281. }
  1282. }
  1283. allTotal := fmt.Sprintf("%.2f", total)
  1284. if res.Infcode == 0 {
  1285. var rf []*ResultFive
  1286. json.Unmarshal([]byte(his.Iinfo), &rf)
  1287. psn_no := his.PsnNo
  1288. mdtrt_id := his.Number
  1289. chrg_bchno := chrg_bchno
  1290. cert_no := his.Certno
  1291. insutype := rf[0].Insutype
  1292. if his.IdCardType == 1 {
  1293. cert_no = his.MedicalInsuranceNumber
  1294. } else {
  1295. cert_no = his.Certno
  1296. }
  1297. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1298. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1299. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1300. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1301. resp, requestErr := http.Get(api)
  1302. if requestErr != nil {
  1303. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1304. return
  1305. }
  1306. defer resp.Body.Close()
  1307. body, ioErr := ioutil.ReadAll(resp.Body)
  1308. if ioErr != nil {
  1309. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1311. return
  1312. }
  1313. var respJSON map[string]interface{}
  1314. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1315. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1317. return
  1318. }
  1319. fmt.Println(respJSON)
  1320. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1321. userJSONBytes, _ := json.Marshal(respJSON)
  1322. var res ResultSeven
  1323. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1324. utils.ErrorLog("解析失败:%v", err)
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1326. return
  1327. }
  1328. if res.Infcode == -1 {
  1329. errlog := &models.HisOrderError{
  1330. UserOrgId: adminUser.CurrentOrgId,
  1331. Ctime: time.Now().Unix(),
  1332. Mtime: time.Now().Unix(),
  1333. Number: chrg_bchno,
  1334. ErrMsg: res.ErrMsg,
  1335. Status: 1,
  1336. PatientId: id,
  1337. RecordTime: recordDateTime,
  1338. Stage: 6,
  1339. }
  1340. service.CreateErrMsgLog(errlog)
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1342. return
  1343. } else {
  1344. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1345. order.OrderStatus = 2
  1346. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1347. order.SetlId = res.Output.Setlinfo.SetlID
  1348. order.PsnNo = res.Output.Setlinfo.PsnNo
  1349. order.PsnName = res.Output.Setlinfo.PsnName
  1350. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1351. order.Certno = res.Output.Setlinfo.Certno
  1352. order.Gend = res.Output.Setlinfo.Gend
  1353. order.Naty = res.Output.Setlinfo.Naty
  1354. order.Age = res.Output.Setlinfo.Age
  1355. order.Insutype = res.Output.Setlinfo.Insutype
  1356. order.PsnType = res.Output.Setlinfo.PsnType
  1357. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1358. order.SetlTime = res.Output.Setlinfo.SetlTime
  1359. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1360. order.MedType = res.Output.Setlinfo.MedType
  1361. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1362. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1363. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1364. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1365. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1366. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1367. order.HifpPay = res.Output.Setlinfo.HifpPay
  1368. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1369. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1370. order.HifesPay = res.Output.Setlinfo.HifesPay
  1371. order.HifobPay = res.Output.Setlinfo.HifobPay
  1372. order.MafPay = res.Output.Setlinfo.MafPay
  1373. order.OthPay = res.Output.Setlinfo.OthPay
  1374. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1375. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1376. order.AcctPay = res.Output.Setlinfo.AcctPay
  1377. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1378. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1379. order.Balc = res.Output.Setlinfo.Balc
  1380. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1381. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1382. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1383. order.ClrWay = res.Output.Setlinfo.ClrWay
  1384. order.Creator = order.Creator
  1385. order.Modify = roles.ID
  1386. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1387. detailStr := string(setlDetail)
  1388. order.SetlDetail = detailStr
  1389. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1390. err = service.UpDateOrder(order)
  1391. if err == nil {
  1392. c.ServeSuccessJSON(map[string]interface{}{
  1393. "msg": "结算成功",
  1394. })
  1395. } else {
  1396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1397. return
  1398. }
  1399. }
  1400. } else {
  1401. adminUser := c.GetAdminUserInfo()
  1402. errlog := &models.HisOrderError{
  1403. UserOrgId: adminUser.CurrentOrgId,
  1404. Ctime: time.Now().Unix(),
  1405. Mtime: time.Now().Unix(),
  1406. ErrMsg: res.ErrMsg,
  1407. Status: 1,
  1408. PatientId: id,
  1409. RecordTime: recordDateTime,
  1410. Stage: 4,
  1411. }
  1412. service.CreateErrMsgLog(errlog)
  1413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1414. return
  1415. }
  1416. } else {
  1417. adminUser := c.GetAdminUserInfo()
  1418. errlog := &models.HisOrderError{
  1419. UserOrgId: adminUser.CurrentOrgId,
  1420. Ctime: time.Now().Unix(),
  1421. Mtime: time.Now().Unix(),
  1422. ErrMsg: res.ErrMsg,
  1423. Status: 1,
  1424. PatientId: id,
  1425. RecordTime: recordDateTime,
  1426. Stage: 4,
  1427. }
  1428. service.CreateErrMsgLog(errlog)
  1429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1430. return
  1431. }
  1432. } else {
  1433. var total float64
  1434. for _, item := range prescriptions {
  1435. if item.Type == 1 { //药品
  1436. for _, subItem := range item.HisDoctorAdviceInfo {
  1437. total = total + (subItem.Price * subItem.PrescribingNumber)
  1438. }
  1439. }
  1440. if item.Type == 2 { //项目
  1441. for _, subItem := range item.HisPrescriptionProject {
  1442. total = total + (subItem.Price * float64(subItem.Count))
  1443. }
  1444. }
  1445. for _, subItem := range item.HisAdditionalCharge {
  1446. total = total + (subItem.Price * float64(subItem.Count))
  1447. }
  1448. }
  1449. allTotal := fmt.Sprintf("%.2f", total)
  1450. totals, _ := strconv.ParseFloat(allTotal, 64)
  1451. order := &models.HisOrder{
  1452. UserOrgId: adminUser.CurrentOrgId,
  1453. HisPatientId: his.ID,
  1454. PatientId: id,
  1455. SettleAccountsDate: recordDateTime,
  1456. Ctime: time.Now().Unix(),
  1457. Mtime: time.Now().Unix(),
  1458. Status: 1,
  1459. OrderStatus: 2,
  1460. Number: chrg_bchno,
  1461. MedfeeSumamt: totals,
  1462. PayWay: pay_way,
  1463. PayPrice: pay_price,
  1464. PayCardNo: pay_card_no,
  1465. DiscountPrice: discount_price,
  1466. PreferentialPrice: preferential_price,
  1467. RealityPrice: reality_price,
  1468. FoundPrice: found_price,
  1469. MedicalInsurancePrice: medical_insurance_price,
  1470. PrivatePrice: private_price,
  1471. }
  1472. err = service.CreateOrder(order)
  1473. if err != nil {
  1474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1475. return
  1476. }
  1477. var customs []*Custom
  1478. for _, item := range prescriptions {
  1479. if item.Type == 1 { //药品
  1480. for _, subItem := range item.HisDoctorAdviceInfo {
  1481. cus := &Custom{
  1482. AdviceId: subItem.ID,
  1483. ProjectId: 0,
  1484. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1485. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1486. FeedetlSn: subItem.FeedetlSn,
  1487. Price: fmt.Sprintf("%.2f", subItem.Price),
  1488. MedListCodg: subItem.MedListCodg,
  1489. Type: 1,
  1490. }
  1491. customs = append(customs, cus)
  1492. }
  1493. }
  1494. if item.Type == 2 { //项目
  1495. for _, subItem := range item.HisPrescriptionProject {
  1496. cus := &Custom{
  1497. AdviceId: 0,
  1498. ProjectId: subItem.ID,
  1499. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1500. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1501. FeedetlSn: subItem.FeedetlSn,
  1502. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1503. MedListCodg: subItem.MedListCodg,
  1504. Type: 2,
  1505. }
  1506. customs = append(customs, cus)
  1507. }
  1508. }
  1509. for _, item := range item.HisAdditionalCharge {
  1510. cus := &Custom{
  1511. ItemId: item.ID,
  1512. AdviceId: 0,
  1513. ProjectId: 0,
  1514. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1515. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1516. FeedetlSn: item.FeedetlSn,
  1517. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1518. MedListCodg: item.XtHisAddtionConfig.Code,
  1519. Type: 3,
  1520. }
  1521. customs = append(customs, cus)
  1522. }
  1523. }
  1524. for _, item := range customs {
  1525. var advice_id int64 = 0
  1526. var project_id int64 = 0
  1527. var item_id int64 = 0
  1528. var types int64 = 0
  1529. if item.Type == 1 {
  1530. advice_id = item.AdviceId
  1531. project_id = 0
  1532. item_id = 0
  1533. } else if item.Type == 2 {
  1534. advice_id = 0
  1535. item_id = 0
  1536. project_id = item.ProjectId
  1537. } else if item.Type == 3 {
  1538. advice_id = 0
  1539. item_id = item.ItemId
  1540. project_id = 0
  1541. }
  1542. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1543. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1544. pric, _ := strconv.ParseFloat(item.Price, 32)
  1545. info := &models.HisOrderInfo{
  1546. OrderNumber: order.Number,
  1547. UploadDate: time.Now().Unix(),
  1548. AdviceId: advice_id,
  1549. DetItemFeeSumamt: detItemFeeSumamt,
  1550. Cnt: cut,
  1551. Pric: pric,
  1552. PatientId: id,
  1553. Status: 1,
  1554. Mtime: time.Now().Unix(),
  1555. Ctime: time.Now().Unix(),
  1556. UserOrgId: adminUser.CurrentOrgId,
  1557. HisPatientId: his.ID,
  1558. OrderId: order.ID,
  1559. ProjectId: project_id,
  1560. Type: types,
  1561. ItemId: item_id,
  1562. }
  1563. service.CreateOrderInfo(info)
  1564. }
  1565. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1566. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1567. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1568. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1569. if err == nil {
  1570. c.ServeSuccessJSON(map[string]interface{}{
  1571. "msg": "结算成功",
  1572. })
  1573. } else {
  1574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1575. return
  1576. }
  1577. }
  1578. }
  1579. func (c *HisApiController) GetSettleInfo() {
  1580. id, _ := c.GetInt64("id")
  1581. order_id, _ := c.GetInt64("order_id")
  1582. record_time := c.GetString("record_time")
  1583. pay_way, _ := c.GetInt64("pay_way")
  1584. pay_price, _ := c.GetFloat("pay_price")
  1585. pay_card_no := c.GetString("pay_card_no")
  1586. discount_price, _ := c.GetFloat("discount_price")
  1587. preferential_price, _ := c.GetFloat("preferential_price")
  1588. reality_price, _ := c.GetFloat("reality_price")
  1589. found_price, _ := c.GetFloat("found_price")
  1590. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1591. private_price, _ := c.GetFloat("private_price")
  1592. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1593. admin_user_id, _ := c.GetInt64("admin_user_id")
  1594. timeLayout := "2006-01-02"
  1595. loc, _ := time.LoadLocation("Local")
  1596. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1597. if err != nil {
  1598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1599. return
  1600. }
  1601. recordDateTime := theTime.Unix()
  1602. adminUser := c.GetAdminUserInfo()
  1603. var prescriptions []*models.HisPrescription
  1604. data := make(map[string]interface{})
  1605. if settle_accounts_type == 1 { //日结
  1606. prescriptions, _ = service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1607. data["pre"] = prescriptions
  1608. } else { //月结
  1609. start_time_str := c.GetString("start_time")
  1610. end_time_str := c.GetString("end_time")
  1611. timeLayout := "2006-01-02"
  1612. loc, _ := time.LoadLocation("Local")
  1613. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1614. if err != nil {
  1615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1616. return
  1617. }
  1618. recordStartTime := theStartTime.Unix()
  1619. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1620. if err != nil {
  1621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1622. return
  1623. }
  1624. recordEndTime := theEndTime.Unix()
  1625. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  1626. data["pre"] = prescriptions
  1627. }
  1628. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1629. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1630. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1631. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1632. strconv.FormatInt(his.PatientId, 10)
  1633. order_src, _ := service.GetHisOrderByID(order_id)
  1634. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1635. if config.IsOpen == 1 { //对接了医保,走医保流程
  1636. var total float64
  1637. for _, item := range prescriptions {
  1638. if item.Type == 1 { //药品
  1639. for _, subItem := range item.HisDoctorAdviceInfo {
  1640. total = total + (subItem.Price * subItem.PrescribingNumber)
  1641. }
  1642. }
  1643. if item.Type == 2 { //项目
  1644. for _, subItem := range item.HisPrescriptionProject {
  1645. total = total + (subItem.Price * float64(subItem.Count))
  1646. }
  1647. }
  1648. }
  1649. for _, item := range prescriptions {
  1650. for _, subItem := range item.HisAdditionalCharge {
  1651. total = total + (subItem.Price * float64(subItem.Count))
  1652. }
  1653. }
  1654. allTotal := fmt.Sprintf("%.2f", total)
  1655. var rf []*ResultFive
  1656. json.Unmarshal([]byte(his.Iinfo), &rf)
  1657. psn_no := order_src.PsnNo
  1658. mdtrt_id := order_src.MdtrtId
  1659. chrg_bchno := order_src.Number
  1660. cert_no := order_src.Certno
  1661. insutype := rf[0].Insutype
  1662. if his.IdCardType == 1 {
  1663. cert_no = his.MedicalInsuranceNumber
  1664. } else {
  1665. cert_no = his.Certno
  1666. }
  1667. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1668. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1669. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + roles.UserName + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1670. 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)
  1671. resp, requestErr := http.Get(api)
  1672. if requestErr != nil {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1674. return
  1675. }
  1676. defer resp.Body.Close()
  1677. body, ioErr := ioutil.ReadAll(resp.Body)
  1678. if ioErr != nil {
  1679. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1681. return
  1682. }
  1683. var respJSON map[string]interface{}
  1684. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1685. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1686. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1687. return
  1688. }
  1689. fmt.Println(respJSON)
  1690. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1691. userJSONBytes, _ := json.Marshal(respJSON)
  1692. var res ResultSeven
  1693. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1694. utils.ErrorLog("解析失败:%v", err)
  1695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1696. return
  1697. }
  1698. if res.Infcode == -1 {
  1699. errlog := &models.HisOrderError{
  1700. UserOrgId: adminUser.CurrentOrgId,
  1701. Ctime: time.Now().Unix(),
  1702. Mtime: time.Now().Unix(),
  1703. Number: chrg_bchno,
  1704. ErrMsg: res.ErrMsg,
  1705. Status: 1,
  1706. PatientId: id,
  1707. RecordTime: recordDateTime,
  1708. Stage: 6,
  1709. }
  1710. service.CreateErrMsgLog(errlog)
  1711. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1712. return
  1713. } else {
  1714. order_src.OrderStatus = 2
  1715. order_src.PayWay = pay_way
  1716. order_src.PayPrice = pay_price
  1717. order_src.PayCardNo = pay_card_no
  1718. order_src.DiscountPrice = discount_price
  1719. order_src.PreferentialPrice = preferential_price
  1720. order_src.RealityPrice = reality_price
  1721. order_src.FoundPrice = found_price
  1722. order_src.MedicalInsurancePrice = medical_insurance_price
  1723. order_src.PrivatePrice = private_price
  1724. order_src.MdtrtId = res.Output.Setlinfo.MdtrtID
  1725. order_src.SetlId = res.Output.Setlinfo.SetlID
  1726. order_src.PsnNo = res.Output.Setlinfo.PsnNo
  1727. order_src.PsnName = res.Output.Setlinfo.PsnName
  1728. order_src.PsnCertType = res.Output.Setlinfo.PsnCertType
  1729. order_src.Certno = res.Output.Setlinfo.Certno
  1730. order_src.Gend = res.Output.Setlinfo.Gend
  1731. order_src.Naty = res.Output.Setlinfo.Naty
  1732. order_src.Age = res.Output.Setlinfo.Age
  1733. order_src.Insutype = res.Output.Setlinfo.Insutype
  1734. order_src.PsnType = res.Output.Setlinfo.PsnType
  1735. order_src.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1736. order_src.SetlTime = res.Output.Setlinfo.SetlTime
  1737. order_src.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1738. order_src.MedType = res.Output.Setlinfo.MedType
  1739. order_src.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1740. order_src.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1741. order_src.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1742. order_src.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1743. order_src.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1744. order_src.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1745. order_src.HifpPay = res.Output.Setlinfo.HifpPay
  1746. order_src.CvlservPay = res.Output.Setlinfo.CvlservPay
  1747. order_src.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1748. order_src.HifesPay = res.Output.Setlinfo.HifesPay
  1749. order_src.HifobPay = res.Output.Setlinfo.HifobPay
  1750. order_src.MafPay = res.Output.Setlinfo.MafPay
  1751. order_src.OthPay = res.Output.Setlinfo.OthPay
  1752. order_src.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1753. order_src.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1754. order_src.AcctPay = res.Output.Setlinfo.AcctPay
  1755. order_src.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1756. order_src.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1757. order_src.Balc = res.Output.Setlinfo.Balc
  1758. order_src.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1759. order_src.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1760. order_src.ClrOptins = res.Output.Setlinfo.ClrOptins
  1761. order_src.ClrWay = res.Output.Setlinfo.ClrWay
  1762. order_src.Creator = order_src.Creator
  1763. order_src.Modify = roles.ID
  1764. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1765. detailStr := string(setlDetail)
  1766. order_src.SetlDetail = detailStr
  1767. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1768. err = service.UpDateOrder(order_src)
  1769. if err == nil {
  1770. c.ServeSuccessJSON(map[string]interface{}{
  1771. "msg": "结算成功",
  1772. })
  1773. } else {
  1774. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1775. return
  1776. }
  1777. }
  1778. }
  1779. }
  1780. //退款
  1781. func (c *HisApiController) Refund() {
  1782. order_id, _ := c.GetInt64("order_id")
  1783. number := c.GetString("number")
  1784. record_time := c.GetString("record_time")
  1785. patient_id, _ := c.GetInt64("patient_id")
  1786. timeLayout := "2006-01-02"
  1787. loc, _ := time.LoadLocation("Local")
  1788. adminUser := c.GetAdminUserInfo()
  1789. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1790. fmt.Println(err)
  1791. if err != nil {
  1792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1793. return
  1794. }
  1795. recordDateTime := theTime.Unix()
  1796. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1797. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1798. var order models.HisOrder
  1799. order, _ = service.GetHisOrderByID(order_id)
  1800. if order.ID == 0 {
  1801. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1802. }
  1803. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1804. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1805. if config.IsOpen == 1 { //对接了医保,走医保流程
  1806. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1807. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1808. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1809. resp, requestErr := http.Get(api)
  1810. if requestErr != nil {
  1811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1812. return
  1813. }
  1814. body, ioErr := ioutil.ReadAll(resp.Body)
  1815. if ioErr != nil {
  1816. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1817. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1818. return
  1819. }
  1820. var respJSON map[string]interface{}
  1821. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1822. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1824. return
  1825. }
  1826. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1827. userJSONBytes, _ := json.Marshal(respJSON)
  1828. fmt.Println(respJSON)
  1829. fmt.Println(userJSONBytes)
  1830. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1831. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1832. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1833. resp2, requestErr2 := http.Get(api2)
  1834. if requestErr2 != nil {
  1835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1836. return
  1837. }
  1838. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1839. if ioErr2 != nil {
  1840. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1842. return
  1843. }
  1844. var respJSON2 map[string]interface{}
  1845. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1846. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1847. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1848. return
  1849. }
  1850. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1851. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1852. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1853. //resp3, requestErr3 := http.Get(api3)
  1854. //if requestErr3 != nil {
  1855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1856. // return
  1857. //}
  1858. //
  1859. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1860. //if ioErr3 != nil {
  1861. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1862. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1863. // return
  1864. //}
  1865. //var respJSON3 map[string]interface{}
  1866. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1867. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1868. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1869. // return
  1870. //}
  1871. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1872. //service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1873. if err == nil {
  1874. c.ServeSuccessJSON(map[string]interface{}{
  1875. "msg": "退费成功",
  1876. })
  1877. } else {
  1878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1879. return
  1880. }
  1881. } else {
  1882. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1883. if err == nil {
  1884. c.ServeSuccessJSON(map[string]interface{}{
  1885. "msg": "退费成功",
  1886. })
  1887. } else {
  1888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1889. return
  1890. }
  1891. }
  1892. }
  1893. func (c *HisApiController) RefundNumber() {
  1894. record_time := c.GetString("record_time")
  1895. patient_id, _ := c.GetInt64("patient_id")
  1896. timeLayout := "2006-01-02"
  1897. loc, _ := time.LoadLocation("Local")
  1898. adminUser := c.GetAdminUserInfo()
  1899. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1900. fmt.Println(err)
  1901. if err != nil {
  1902. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1903. return
  1904. }
  1905. recordDateTime := theTime.Unix()
  1906. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1907. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1908. //order, _ := service.GetHisOrderByID(order_id)
  1909. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1910. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1911. if config.IsOpen == 1 { //对接了医保,走医保流程
  1912. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1913. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1914. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1915. resp3, requestErr3 := http.Get(api3)
  1916. if requestErr3 != nil {
  1917. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1918. return
  1919. }
  1920. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1921. if ioErr3 != nil {
  1922. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1923. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1924. return
  1925. }
  1926. var respJSON3 map[string]interface{}
  1927. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1928. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1929. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1930. return
  1931. }
  1932. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1933. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1934. if err == nil {
  1935. c.ServeSuccessJSON(map[string]interface{}{
  1936. "msg": "退费成功",
  1937. })
  1938. } else {
  1939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1940. return
  1941. }
  1942. } else {
  1943. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1944. //if err == nil {
  1945. // c.ServeSuccessJSON(map[string]interface{}{
  1946. // "msg": "退费成功",
  1947. // })
  1948. //} else {
  1949. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1950. // return
  1951. //}
  1952. }
  1953. }
  1954. func (c *HisApiController) RefundDetail() {
  1955. order_id, _ := c.GetInt64("order_id")
  1956. number := c.GetString("number")
  1957. record_time := c.GetString("record_time")
  1958. patient_id, _ := c.GetInt64("patient_id")
  1959. timeLayout := "2006-01-02"
  1960. loc, _ := time.LoadLocation("Local")
  1961. adminUser := c.GetAdminUserInfo()
  1962. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1963. fmt.Println(err)
  1964. if err != nil {
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. recordDateTime := theTime.Unix()
  1969. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1970. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1971. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1972. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1973. var order models.HisOrder
  1974. order, _ = service.GetHisOrderByID(order_id)
  1975. if order.ID == 0 {
  1976. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1977. }
  1978. if config.IsOpen == 1 { //对接了医保,走医保流程
  1979. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1980. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1981. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1982. resp2, requestErr2 := http.Get(api2)
  1983. if requestErr2 != nil {
  1984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1985. return
  1986. }
  1987. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1988. if ioErr2 != nil {
  1989. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1990. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1991. return
  1992. }
  1993. var respJSON2 map[string]interface{}
  1994. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1995. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1996. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1997. return
  1998. }
  1999. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2000. if err == nil {
  2001. c.ServeSuccessJSON(map[string]interface{}{
  2002. "msg": "退费成功",
  2003. })
  2004. } else {
  2005. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2006. return
  2007. }
  2008. } else {
  2009. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2010. if err == nil {
  2011. c.ServeSuccessJSON(map[string]interface{}{
  2012. "msg": "退费成功",
  2013. })
  2014. } else {
  2015. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2016. return
  2017. }
  2018. }
  2019. }
  2020. //对账
  2021. func (c *HisApiController) GetCheckAccount() {
  2022. start_time := c.GetString("start_time")
  2023. end_time := c.GetString("end_time")
  2024. insutype := c.GetString("insutype")
  2025. clr_type := c.GetString("clr_type")
  2026. admin_user_id, _ := c.GetInt64("admin_user_id")
  2027. adminUser := c.GetAdminUserInfo()
  2028. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2029. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2030. timeLayout := "2006-01-02"
  2031. loc, _ := time.LoadLocation("Local")
  2032. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2033. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2034. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2035. decimal.DivisionPrecision = 2
  2036. var medfee_sumamt float64
  2037. var acct_pay float64
  2038. var fund_pay_sumamt float64
  2039. fixmedins_setl_cnt := int64(len(orders))
  2040. for _, item := range orders {
  2041. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2042. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  2043. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2044. }
  2045. var user_name string
  2046. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2047. if role.ID == 0 {
  2048. user_name = "xxx"
  2049. } else {
  2050. user_name = role.UserName
  2051. }
  2052. if config.IsOpen == 1 {
  2053. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2054. "insutype=" + insutype +
  2055. "&clr_type=" + clr_type +
  2056. "&setl_optins=" + miConfig.OrgName +
  2057. "&stmt_begndate=" + start_time +
  2058. "&stm_enddate=" + end_time +
  2059. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2060. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2061. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2062. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2063. "&fixmedins_code=" + miConfig.Code +
  2064. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2065. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2066. "&secret_key=" + miConfig.SecretKey +
  2067. "&org_name=" + miConfig.OrgName +
  2068. "&doctor=" + user_name
  2069. fmt.Println(api)
  2070. resp, requestErr := http.Get(api)
  2071. if requestErr != nil {
  2072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2073. return
  2074. }
  2075. body, ioErr := ioutil.ReadAll(resp.Body)
  2076. fmt.Println(body)
  2077. if ioErr != nil {
  2078. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2079. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2080. return
  2081. }
  2082. var respJSON map[string]interface{}
  2083. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2084. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2086. return
  2087. }
  2088. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2089. userJSONBytes, _ := json.Marshal(respJSON)
  2090. var res ResultEight
  2091. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2092. utils.ErrorLog("解析失败:%v", err)
  2093. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2094. return
  2095. }
  2096. if res.Infcode == 0 {
  2097. micc := &models.MedicalInsuranceCostCompare{
  2098. StartTime: startime.Unix(),
  2099. EndTime: endtime.Unix(),
  2100. Insutype: insutype,
  2101. CheckType: 1,
  2102. Num: fixmedins_setl_cnt,
  2103. Mtime: time.Now().Unix(),
  2104. Status: 1,
  2105. UserOrgId: adminUser.CurrentOrgId,
  2106. CostTotal: medfee_sumamt,
  2107. FuncTotal: fund_pay_sumamt,
  2108. PsnPay: acct_pay,
  2109. Creator: admin_user_id,
  2110. Ctime: time.Now().Unix(),
  2111. }
  2112. err := service.CreateMedicalInsuranceCostCompareRecord(micc)
  2113. if err == nil {
  2114. c.ServeSuccessJSON(map[string]interface{}{
  2115. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2116. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2117. })
  2118. } else {
  2119. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2120. }
  2121. } else {
  2122. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2123. }
  2124. }
  2125. }
  2126. //对账明细
  2127. func (c *HisApiController) GetCheckDetailAccount() {
  2128. start_time := c.GetString("start_time")
  2129. end_time := c.GetString("end_time")
  2130. admin_user_id, _ := c.GetInt64("admin_user_id")
  2131. adminUser := c.GetAdminUserInfo()
  2132. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2133. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2134. timeLayout := "2006-01-02"
  2135. loc, _ := time.LoadLocation("Local")
  2136. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2137. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2138. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2139. Mkdir(miConfig.OrgName)
  2140. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2141. file_name := file + ".txt"
  2142. zip_name := file + ".zip"
  2143. zip_path := miConfig.OrgName + "/" + zip_name
  2144. file_path := miConfig.OrgName + "/" + file_name
  2145. decimal.DivisionPrecision = 2
  2146. var medfee_sumamt float64
  2147. var psn_cash_pay float64
  2148. var fund_pay_sumamt float64
  2149. fixmedins_setl_cnt := int64(len(orders))
  2150. for _, item := range orders {
  2151. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2152. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  2153. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2154. }
  2155. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2156. defer f.Close()
  2157. if err != nil {
  2158. fmt.Println(err.Error())
  2159. } else {
  2160. for _, item := range orders {
  2161. var refd_setl_flag string
  2162. if item.OrderStatus == 2 {
  2163. refd_setl_flag = "0"
  2164. }
  2165. if item.OrderStatus == 3 {
  2166. refd_setl_flag = "1"
  2167. }
  2168. var str string
  2169. str = item.SetlId + " " +
  2170. item.MdtrtId + " " +
  2171. item.PsnNo + " " +
  2172. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2173. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2174. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2175. _, err = f.Write([]byte(str))
  2176. }
  2177. }
  2178. Zip(file_path, zip_path)
  2179. fmt.Println(ReadFile(zip_path))
  2180. fmt.Println(string(ReadFile(zip_path)))
  2181. if config.IsOpen == 1 {
  2182. var user_name string
  2183. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2184. if role.ID == 0 {
  2185. user_name = "管理员"
  2186. } else {
  2187. user_name = role.UserName
  2188. }
  2189. baseParams := models.BaseParams{
  2190. SecretKey: miConfig.SecretKey,
  2191. FixmedinsCode: miConfig.Code,
  2192. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2193. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2194. OrgName: miConfig.OrgName,
  2195. Doctor: user_name,
  2196. }
  2197. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2198. var dat map[string]interface{}
  2199. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2200. fmt.Println(dat)
  2201. } else {
  2202. fmt.Println(err)
  2203. }
  2204. userJSONBytes, _ := json.Marshal(dat)
  2205. var res ResultNine
  2206. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2207. utils.ErrorLog("解析失败:%v", err)
  2208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2209. return
  2210. }
  2211. if res.Infcode == 0 {
  2212. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2213. "file_qury_no=" + res.Output.FileQuryNo +
  2214. "&setl_optins=" + miConfig.OrgName +
  2215. "&stmt_begndate=" + start_time +
  2216. "&stm_enddate=" + end_time +
  2217. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2218. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2219. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2220. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2221. "&fixmedins_code=" + miConfig.Code +
  2222. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2223. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2224. "&secret_key=" + miConfig.SecretKey +
  2225. "&org_name=" + miConfig.OrgName +
  2226. "&doctor=" + user_name
  2227. resp, requestErr := http.Get(api)
  2228. if requestErr != nil {
  2229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2230. return
  2231. }
  2232. body, ioErr := ioutil.ReadAll(resp.Body)
  2233. if ioErr != nil {
  2234. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2236. return
  2237. }
  2238. var respJSON map[string]interface{}
  2239. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2240. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2241. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2242. return
  2243. }
  2244. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2245. userJSONBytes, _ := json.Marshal(respJSON)
  2246. var res ResultTen
  2247. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2248. utils.ErrorLog("解析失败:%v", err)
  2249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2250. return
  2251. }
  2252. if res.Infcode == 0 {
  2253. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2254. micc := &models.MedicalInsuranceCostCompare{
  2255. StartTime: startime.Unix(),
  2256. EndTime: endtime.Unix(),
  2257. Insutype: "0",
  2258. CheckType: 2,
  2259. Num: fixmedins_setl_cnt,
  2260. Mtime: time.Now().Unix(),
  2261. Status: 1,
  2262. UserOrgId: adminUser.CurrentOrgId,
  2263. CostTotal: medfee_sumamt,
  2264. FuncTotal: fund_pay_sumamt,
  2265. PsnPay: psn_cash_pay,
  2266. Creator: admin_user_id,
  2267. Ctime: time.Now().Unix(),
  2268. }
  2269. service.CreateMedicalInsuranceCostCompareRecord(micc)
  2270. c.ServeSuccessJSON(map[string]interface{}{
  2271. "msg": "明细对账成功",
  2272. })
  2273. }
  2274. } else {
  2275. }
  2276. }
  2277. }
  2278. func (c *HisApiController) GetSettleAccounts() {
  2279. //id, _ := c.GetInt64("id")
  2280. //record_time := c.GetString("record_time")
  2281. order_id, _ := c.GetInt64("order_id")
  2282. admin_user_id, _ := c.GetInt64("admin_user_id")
  2283. //timeLayout := "2006-01-02"
  2284. //loc, _ := time.LoadLocation("Local")
  2285. //
  2286. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2287. //if err != nil {
  2288. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2289. // return
  2290. //}
  2291. //recordDateTime := theTime.Unix()
  2292. adminUser := c.GetAdminUserInfo()
  2293. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2294. order, _ := service.GetHisOrderByID(order_id)
  2295. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2296. var bedCostTotal float64 = 0 //床位总费
  2297. var bedCostSelfTotal float64 = 0 //床位自费
  2298. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2299. var operationCostTotal float64 = 0 //手术费
  2300. var operationCostSelfTotal float64 = 0 //手术费
  2301. var operationCostPartSelfTotal float64 = 0 //手术费
  2302. var otherCostTotal float64 = 0 //其他费用
  2303. var otherCostSelfTotal float64 = 0 //其他费用
  2304. var otherCostPartSelfTotal float64 = 0 //其他费用
  2305. var materialCostTotal float64 = 0 //材料费
  2306. var materialCostSelfTotal float64 = 0 //材料费
  2307. var materialCostPartSelfTotal float64 = 0 //材料费
  2308. var westernMedicineCostTotal float64 = 0 //西药费
  2309. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2310. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2311. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2312. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2313. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2314. var checkCostTotal float64 = 0 //检查费
  2315. var checkCostSelfTotal float64 = 0 //检查费
  2316. var checkCostPartSelfTotal float64 = 0 //检查费
  2317. var laboratoryCostTotal float64 = 0 //化验费
  2318. var laboratoryCostSelfTotal float64 = 0 //化验费
  2319. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2320. var treatCostTotal float64 = 0 //治疗费用
  2321. var treatCostSelfTotal float64 = 0 //治疗费用
  2322. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2323. decimal.DivisionPrecision = 2
  2324. for _, item := range orderInfos {
  2325. if item.MedChrgitmType == "01" { //床位费
  2326. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2327. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2328. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2329. }
  2330. if item.MedChrgitmType == "03" { //检查费
  2331. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2332. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2333. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2334. }
  2335. if item.MedChrgitmType == "04" { //化验费
  2336. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2337. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2338. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2339. }
  2340. if item.MedChrgitmType == "05" { //治疗费
  2341. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2342. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2343. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2344. }
  2345. if item.MedChrgitmType == "06" { //手术费
  2346. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2347. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2348. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2349. }
  2350. if item.MedChrgitmType == "08" { //材料费
  2351. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2352. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2353. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2354. }
  2355. if item.MedChrgitmType == "09" { //西药费
  2356. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2357. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2358. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2359. }
  2360. if item.MedChrgitmType == "11" { //中成费
  2361. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2362. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2363. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2364. }
  2365. if item.MedChrgitmType == "14" { //其他费
  2366. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2367. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2368. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2369. }
  2370. }
  2371. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2372. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2373. var user_name string
  2374. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2375. if role.ID == 0 {
  2376. user_name = "管理员"
  2377. } else {
  2378. user_name = role.UserName
  2379. }
  2380. baseParams := models.BaseParams{
  2381. SecretKey: miConfig.SecretKey,
  2382. FixmedinsCode: miConfig.Code,
  2383. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2384. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2385. OrgName: miConfig.OrgName,
  2386. Doctor: user_name,
  2387. }
  2388. businessParams := models.BusinessParams{
  2389. PsnNo: order.PsnNo,
  2390. MdtrtId: order.MdtrtId,
  2391. SetlId: order.SetlId,
  2392. }
  2393. if config.IsOpen == 1 {
  2394. result := service.Gdyb5203(baseParams, businessParams)
  2395. var dat map[string]interface{}
  2396. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2397. fmt.Println(dat)
  2398. } else {
  2399. fmt.Println(err)
  2400. }
  2401. userJSONBytes, _ := json.Marshal(dat)
  2402. var res ResultEleven
  2403. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2404. utils.ErrorLog("解析失败:%v", err)
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2406. return
  2407. }
  2408. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2409. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  2410. if res.Infcode == 0 {
  2411. c.ServeSuccessJSON(map[string]interface{}{
  2412. "charge_admin": charge_admin,
  2413. "printor_admin": printor_admin,
  2414. "info": res.Output.Setlinfo,
  2415. "bedCostTotal": bedCostTotal,
  2416. "bedCostSelfTotal": bedCostSelfTotal,
  2417. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2418. "operationCostTotal": operationCostTotal,
  2419. "operationCostSelfTotal": operationCostSelfTotal,
  2420. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2421. "otherCostTotal": otherCostTotal,
  2422. "otherCostSelfTotal": otherCostSelfTotal,
  2423. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2424. "materialCostTotal": materialCostTotal,
  2425. "materialCostSelfTotal": materialCostSelfTotal,
  2426. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2427. "westernMedicineCostTotal": westernMedicineCostTotal,
  2428. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2429. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2430. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2431. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2432. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2433. "checkCostTotal": checkCostTotal,
  2434. "checkCostSelfTotal": checkCostSelfTotal,
  2435. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2436. "laboratoryCostTotal": laboratoryCostTotal,
  2437. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2438. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2439. "treatCostTotal": treatCostTotal,
  2440. "treatCostSelfTotal": treatCostSelfTotal,
  2441. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2442. })
  2443. }
  2444. }
  2445. }
  2446. func (c *HisApiController) GetCode() {
  2447. name := c.GetString("name")
  2448. codg := c.GetString("codg")
  2449. adminUser := c.GetAdminUserInfo()
  2450. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2451. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2452. var user_name string
  2453. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2454. if role.ID == 0 {
  2455. user_name = "xxx"
  2456. } else {
  2457. user_name = role.UserName
  2458. }
  2459. baseParams := &models.BaseParams{
  2460. SecretKey: miConfig.SecretKey,
  2461. FixmedinsCode: miConfig.Code,
  2462. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2463. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2464. OrgName: miConfig.OrgName,
  2465. Doctor: user_name,
  2466. }
  2467. if config.IsOpen == 1 {
  2468. result := service.Gdyb3301(baseParams, name, codg)
  2469. var dat map[string]interface{}
  2470. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2471. fmt.Println(dat)
  2472. } else {
  2473. fmt.Println(err)
  2474. }
  2475. }
  2476. }
  2477. func (c *HisApiController) CheckTreatment() {
  2478. patient_id, _ := c.GetInt64("patient_id", 0)
  2479. record_time := c.GetString("record_time")
  2480. insutype := c.GetString("insutype")
  2481. timeLayout := "2006-01-02"
  2482. loc, _ := time.LoadLocation("Local")
  2483. adminUser := c.GetAdminUserInfo()
  2484. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2485. fmt.Println(err)
  2486. if err != nil {
  2487. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2488. return
  2489. }
  2490. recordDateTime := theTime.Unix()
  2491. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2492. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2493. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2494. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2495. var user_name string
  2496. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2497. if role.ID == 0 {
  2498. user_name = "xxx"
  2499. } else {
  2500. user_name = role.UserName
  2501. }
  2502. baseParams := models.BaseParams{
  2503. SecretKey: miConfig.SecretKey,
  2504. FixmedinsCode: miConfig.Code,
  2505. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2506. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2507. OrgName: miConfig.OrgName,
  2508. Doctor: user_name,
  2509. }
  2510. if config.IsOpen == 1 {
  2511. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  2512. var dat map[string]interface{}
  2513. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2514. fmt.Println(dat)
  2515. } else {
  2516. fmt.Println(err)
  2517. }
  2518. }
  2519. }
  2520. func (c *HisApiController) PutRecord() {
  2521. id, _ := c.GetInt64("id")
  2522. record_time := c.GetString("record_time")
  2523. timeLayout := "2006-01-02"
  2524. loc, _ := time.LoadLocation("Local")
  2525. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2526. if err != nil {
  2527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2528. return
  2529. }
  2530. recordDateTime := theTime.Unix()
  2531. adminInfo := c.GetAdminUserInfo()
  2532. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  2533. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2534. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2535. fmt.Println(miConfig.SecretKey)
  2536. if patient == nil {
  2537. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2538. return
  2539. }
  2540. if len(patient.IdCardNo) == 0 {
  2541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2542. return
  2543. }
  2544. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  2545. if config.IsOpen == 1 {
  2546. 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
  2547. resp, requestErr := http.Get(api)
  2548. if requestErr != nil {
  2549. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2550. return
  2551. }
  2552. defer resp.Body.Close()
  2553. body, ioErr := ioutil.ReadAll(resp.Body)
  2554. if ioErr != nil {
  2555. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2557. return
  2558. }
  2559. var respJSON map[string]interface{}
  2560. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2561. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2563. return
  2564. }
  2565. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2566. userJSONBytes, _ := json.Marshal(userJSON)
  2567. var res ResultTwo
  2568. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2569. utils.ErrorLog("解析失败:%v", err)
  2570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2571. return
  2572. }
  2573. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2574. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2575. infoStr := string(Iinfos)
  2576. idetinfoStr := string(Idetinfos)
  2577. if res.Infcode == 0 {
  2578. his := models.VMHisPatient{
  2579. Status: 1,
  2580. Ctime: time.Now().Unix(),
  2581. Mtime: time.Now().Unix(),
  2582. PsnNo: res.Output.Baseinfo.PsnNo,
  2583. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2584. Certno: res.Output.Baseinfo.Certno,
  2585. PsnName: res.Output.Baseinfo.PsnName,
  2586. Gend: res.Output.Baseinfo.Gend,
  2587. Naty: res.Output.Baseinfo.Naty,
  2588. Brdy: res.Output.Baseinfo.Brdy,
  2589. Age: res.Output.Baseinfo.Age,
  2590. Iinfo: infoStr,
  2591. Idetinfo: idetinfoStr,
  2592. PatientId: patient.ID,
  2593. RecordDate: theTime.Unix(),
  2594. UserOrgId: adminInfo.CurrentOrgId,
  2595. AdminUserId: adminInfo.AdminUser.Id,
  2596. IsReturn: 1,
  2597. }
  2598. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  2599. 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")
  2600. 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")
  2601. var dat map[string]interface{}
  2602. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2603. fmt.Println(dat)
  2604. } else {
  2605. fmt.Println(err)
  2606. }
  2607. var dat2 map[string]interface{}
  2608. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  2609. fmt.Println(dat2)
  2610. } else {
  2611. fmt.Println(err)
  2612. }
  2613. } else {
  2614. adminUser := c.GetAdminUserInfo()
  2615. errlog := &models.HisOrderError{
  2616. UserOrgId: adminUser.CurrentOrgId,
  2617. Ctime: time.Now().Unix(),
  2618. Mtime: time.Now().Unix(),
  2619. ErrMsg: res.ErrMsg,
  2620. Status: 1,
  2621. PatientId: id,
  2622. RecordTime: recordDateTime,
  2623. Stage: 1,
  2624. }
  2625. service.CreateErrMsgLog(errlog)
  2626. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  2627. return
  2628. }
  2629. }
  2630. }
  2631. func (c *HisApiController) GetUploadDiag() {
  2632. id, _ := c.GetInt64("id")
  2633. record_time := c.GetString("record_time")
  2634. diagnosis_id, _ := c.GetInt64("diagnosis")
  2635. sick_type, _ := c.GetInt64("sick_type")
  2636. reg_type, _ := c.GetInt64("reg_type")
  2637. timeLayout := "2006-01-02"
  2638. loc, _ := time.LoadLocation("Local")
  2639. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2640. if err != nil {
  2641. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2642. return
  2643. }
  2644. var patientPrescription models.HisPrescriptionInfo
  2645. recordDateTime := theTime.Unix()
  2646. adminInfo := c.GetAdminUserInfo()
  2647. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2648. if patientPrescription.ID == 0 {
  2649. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2650. }
  2651. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2652. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2653. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2654. sickConfig, _ := service.FindSickById(sick_type)
  2655. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2656. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  2657. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  2658. "&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 +
  2659. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  2660. resp2, requestErr2 := http.Get(api2)
  2661. if requestErr2 != nil {
  2662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2663. return
  2664. }
  2665. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2666. if ioErr2 != nil {
  2667. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2669. return
  2670. }
  2671. var respJSON2 map[string]interface{}
  2672. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2673. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2674. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2675. return
  2676. }
  2677. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2678. userJSONBytes2, _ := json.Marshal(respJSON2)
  2679. var res2 ResultSix
  2680. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2681. utils.ErrorLog("解析失败:%v", err)
  2682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2683. return
  2684. }
  2685. if res2.Infcode == -1 {
  2686. adminUser := c.GetAdminUserInfo()
  2687. errlog := &models.HisOrderError{
  2688. UserOrgId: adminUser.CurrentOrgId,
  2689. Ctime: time.Now().Unix(),
  2690. Mtime: time.Now().Unix(),
  2691. ErrMsg: res2.ErrMsg,
  2692. Status: 1,
  2693. PatientId: id,
  2694. RecordTime: recordDateTime,
  2695. Stage: 3,
  2696. }
  2697. service.CreateErrMsgLog(errlog)
  2698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  2699. return
  2700. }
  2701. c.ServeSuccessJSON(map[string]interface{}{
  2702. "msg": "上传成功",
  2703. })
  2704. }
  2705. func PathExists(path string) (bool, error) {
  2706. _, err := os.Stat(path)
  2707. if err == nil {
  2708. return true, nil
  2709. }
  2710. if os.IsNotExist(err) {
  2711. return false, nil
  2712. }
  2713. return false, err
  2714. }
  2715. //创建文件夹
  2716. func Mkdir(dir string) {
  2717. // 创建文件夹
  2718. exist, err := PathExists(dir)
  2719. if err != nil {
  2720. fmt.Println(err.Error())
  2721. } else {
  2722. if exist {
  2723. fmt.Println(dir + "文件夹已存在!")
  2724. } else {
  2725. // 文件夹名称,权限
  2726. err := os.Mkdir(dir, os.ModePerm)
  2727. if err != nil {
  2728. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2729. } else {
  2730. fmt.Println(dir + "文件夹创建成功!")
  2731. }
  2732. }
  2733. }
  2734. }
  2735. //压缩文件
  2736. func Zip(srcFile string, destZip string) error {
  2737. zipfile, err := os.Create(destZip)
  2738. if err != nil {
  2739. return err
  2740. }
  2741. defer zipfile.Close()
  2742. archive := zip.NewWriter(zipfile)
  2743. defer archive.Close()
  2744. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2745. if err != nil {
  2746. return err
  2747. }
  2748. header, err := zip.FileInfoHeader(info)
  2749. if err != nil {
  2750. return err
  2751. }
  2752. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2753. // header.Name = path
  2754. if info.IsDir() {
  2755. header.Name += "/"
  2756. } else {
  2757. header.Method = zip.Deflate
  2758. }
  2759. writer, err := archive.CreateHeader(header)
  2760. if err != nil {
  2761. return err
  2762. }
  2763. if !info.IsDir() {
  2764. file, err := os.Open(path)
  2765. if err != nil {
  2766. return err
  2767. }
  2768. defer file.Close()
  2769. _, err = io.Copy(writer, file)
  2770. }
  2771. return err
  2772. })
  2773. return err
  2774. }
  2775. func ReadFile(filePath string) []byte {
  2776. f, err := os.Open(filePath)
  2777. if err != nil {
  2778. fmt.Println("read file fail", err)
  2779. return nil
  2780. }
  2781. defer f.Close()
  2782. fd, err := ioutil.ReadAll(f)
  2783. if err != nil {
  2784. fmt.Println("read to fd fail", err)
  2785. return nil
  2786. }
  2787. return fd
  2788. }
  2789. func RemoveRepeatedCode(arr []string) (newArr []string) {
  2790. newArr = make([]string, 0)
  2791. for i := 0; i < len(arr); i++ {
  2792. repeat := false
  2793. for j := i + 1; j < len(arr); j++ {
  2794. if arr[i] == arr[j] {
  2795. repeat = true
  2796. break
  2797. }
  2798. }
  2799. if !repeat {
  2800. newArr = append(newArr, arr[i])
  2801. }
  2802. }
  2803. return
  2804. }
  2805. //func ShowMessage1(caption, text string, style uintptr) (result int) {
  2806. // user32, _ := syscall.LoadLibrary("SSCard.dll")
  2807. // messageBox, _ := syscall.GetProcAddress(user32, "MessageBoxW")
  2808. // defer syscall.FreeLibrary(user32)
  2809. //
  2810. // ret, _, _ := syscall.Syscall9(messageBox,
  2811. // 4,
  2812. // 0,
  2813. // StrPtr(text),
  2814. // StrPtr(caption),
  2815. // style,
  2816. // 0, 0, 0, 0, 0)
  2817. // result = int(ret)
  2818. // return
  2819. //}
  2820. //func StrPtr3(s string) uintptr {
  2821. // return uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(s)))
  2822. //}