his_api_controller.go 95KB

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