his_api_controller.go 96KB

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