his_api_controller.go 99KB

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