his_api_controller.go 94KB

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