his_api_controller.go 98KB

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