his_api_controller.go 94KB

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