his_api_controller.go 95KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686
  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. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  963. timestamp := time.Now().Unix()
  964. tempTime := time.Unix(timestamp, 0)
  965. timeFormat := tempTime.Format("20060102150405")
  966. chrgBchno := rand.Intn(100000) + 10000
  967. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  968. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  969. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  970. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  971. strconv.FormatInt(his.PatientId, 10)
  972. client := &http.Client{}
  973. data["psn_no"] = his.PsnNo
  974. data["mdtrt_id"] = his.Number
  975. data["chrg_bchno"] = chrg_bchno
  976. data["org_name"] = miConfig.OrgName
  977. data["doctor"] = patientPrescription.Doctor
  978. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  979. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  980. data["fixmedins_code"] = miConfig.Code
  981. data["dept_code"] = department.Number
  982. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  983. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  984. data["secret_key"] = miConfig.SecretKey
  985. var ids []int64
  986. for _, item := range prescriptions {
  987. ids = append(ids, item.ID)
  988. }
  989. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  990. if config.IsOpen == 1 { //对接了医保,走医保流程
  991. bytesData, _ := json.Marshal(data)
  992. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  993. resp, _ := client.Do(req)
  994. defer resp.Body.Close()
  995. body, ioErr := ioutil.ReadAll(resp.Body)
  996. if ioErr != nil {
  997. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  998. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  999. return
  1000. }
  1001. var respJSON map[string]interface{}
  1002. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1003. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1004. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1005. return
  1006. }
  1007. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1008. userJSONBytes, _ := json.Marshal(respJSON)
  1009. var res ResultFour
  1010. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1011. utils.ErrorLog("解析失败:%v", err)
  1012. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1013. return
  1014. }
  1015. if res.Infcode == 0 {
  1016. order := &models.HisOrder{
  1017. UserOrgId: adminUser.CurrentOrgId,
  1018. HisPatientId: his.ID,
  1019. PatientId: his.PatientId,
  1020. SettleAccountsDate: recordDateTime,
  1021. Ctime: time.Now().Unix(),
  1022. Mtime: time.Now().Unix(),
  1023. Status: 1,
  1024. Number: chrg_bchno,
  1025. Infcode: res.Infcode,
  1026. WarnMsg: res.WarnMsg,
  1027. Cainfo: res.Cainfo,
  1028. ErrMsg: res.ErrMsg,
  1029. RespondTime: res.RefmsgTime,
  1030. InfRefmsgid: res.InfRefmsgid,
  1031. OrderStatus: 1,
  1032. PayWay: pay_way,
  1033. PayPrice: pay_price,
  1034. PayCardNo: pay_card_no,
  1035. DiscountPrice: discount_price,
  1036. PreferentialPrice: preferential_price,
  1037. RealityPrice: reality_price,
  1038. FoundPrice: found_price,
  1039. MedicalInsurancePrice: medical_insurance_price,
  1040. PrivatePrice: private_price,
  1041. IsMedicineInsurance: 1,
  1042. SettleType: settle_accounts_type,
  1043. SettleStartTime: start_time,
  1044. SettleEndTime: end_time,
  1045. }
  1046. err = service.CreateOrder(order)
  1047. if err != nil {
  1048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1049. return
  1050. }
  1051. for _, item := range res.Output.Result {
  1052. temp := strings.Split(item.FeedetlSn, "-")
  1053. var advice_id int64 = 0
  1054. var project_id int64 = 0
  1055. var types int64 = 0
  1056. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1057. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1058. if temp[1] == "1" {
  1059. advice_id = id
  1060. project_id = 0
  1061. } else if temp[1] == "2" {
  1062. advice_id = 0
  1063. project_id = id
  1064. }
  1065. info := &models.HisOrderInfo{
  1066. OrderNumber: order.Number,
  1067. FeedetlSn: item.FeedetlSn,
  1068. UploadDate: time.Now().Unix(),
  1069. AdviceId: advice_id,
  1070. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1071. Cnt: item.Cnt,
  1072. Pric: float64(item.Pric),
  1073. PatientId: his.PatientId,
  1074. PricUplmtAmt: item.PricUplmtAmt,
  1075. SelfpayProp: item.SelfpayProp,
  1076. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1077. OverlmtAmt: item.OverlmtAmt,
  1078. PreselfpayAmt: item.PreselfpayAmt,
  1079. BasMednFlag: item.BasMednFlag,
  1080. MedChrgitmType: item.MedChrgitmType,
  1081. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1082. Status: 1,
  1083. Memo: item.Memo,
  1084. Mtime: time.Now().Unix(),
  1085. InscpScpAmt: item.InscpScpAmt,
  1086. DrtReimFlag: item.DrtReimFlag,
  1087. Ctime: time.Now().Unix(),
  1088. ListSpItemFlag: item.ListSpItemFlag,
  1089. ChldMedcFlag: item.ChldMedcFlag,
  1090. LmtUsedFlag: item.LmtUsedFlag,
  1091. ChrgitmLv: item.ChrgitmLv,
  1092. UserOrgId: adminUser.CurrentOrgId,
  1093. HisPatientId: his.ID,
  1094. OrderId: order.ID,
  1095. ProjectId: project_id,
  1096. Type: types,
  1097. }
  1098. service.CreateOrderInfo(info)
  1099. }
  1100. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1101. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1102. var total float64
  1103. for _, item := range prescriptions {
  1104. if item.Type == 1 { //药品
  1105. for _, subItem := range item.HisDoctorAdviceInfo {
  1106. total = total + (subItem.Price * subItem.PrescribingNumber)
  1107. }
  1108. }
  1109. if item.Type == 2 { //项目
  1110. for _, subItem := range item.HisPrescriptionProject {
  1111. total = total + (subItem.Price * float64(subItem.Count))
  1112. }
  1113. }
  1114. }
  1115. for _, item := range prescriptions {
  1116. for _, subItem := range item.HisAdditionalCharge {
  1117. total = total + (subItem.Price * float64(subItem.Count))
  1118. }
  1119. }
  1120. allTotal := fmt.Sprintf("%.2f", total)
  1121. if res.Infcode == 0 {
  1122. var rf []*ResultFive
  1123. json.Unmarshal([]byte(his.Iinfo), &rf)
  1124. psn_no := his.PsnNo
  1125. mdtrt_id := his.Number
  1126. chrg_bchno := chrg_bchno
  1127. cert_no := his.Certno
  1128. insutype := rf[0].Insutype
  1129. if his.IdCardType == 1 {
  1130. cert_no = his.MedicalInsuranceNumber
  1131. } else {
  1132. cert_no = his.Certno
  1133. }
  1134. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1135. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1136. "&total=" + allTotal + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code + "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" +
  1137. miConfig.SecretKey + "&med_type=" + strconv.FormatInt(patientPrescription.RegisterType, 10) + "&id_card_type=" + strconv.FormatInt(int64(his.IdCardType), 10)
  1138. resp, requestErr := http.Get(api)
  1139. if requestErr != nil {
  1140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1141. return
  1142. }
  1143. defer resp.Body.Close()
  1144. body, ioErr := ioutil.ReadAll(resp.Body)
  1145. if ioErr != nil {
  1146. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1148. return
  1149. }
  1150. var respJSON map[string]interface{}
  1151. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1152. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1154. return
  1155. }
  1156. fmt.Println(respJSON)
  1157. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1158. userJSONBytes, _ := json.Marshal(respJSON)
  1159. var res ResultSeven
  1160. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1161. utils.ErrorLog("解析失败:%v", err)
  1162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1163. return
  1164. }
  1165. if res.Infcode == -1 {
  1166. errlog := &models.HisOrderError{
  1167. UserOrgId: adminUser.CurrentOrgId,
  1168. Ctime: time.Now().Unix(),
  1169. Mtime: time.Now().Unix(),
  1170. Number: chrg_bchno,
  1171. ErrMsg: res.ErrMsg,
  1172. Status: 1,
  1173. PatientId: id,
  1174. RecordTime: recordDateTime,
  1175. Stage: 6,
  1176. }
  1177. service.CreateErrMsgLog(errlog)
  1178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1179. return
  1180. } else {
  1181. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1182. order.OrderStatus = 2
  1183. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1184. order.SetlId = res.Output.Setlinfo.SetlID
  1185. order.PsnNo = res.Output.Setlinfo.PsnNo
  1186. order.PsnName = res.Output.Setlinfo.PsnName
  1187. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1188. order.Certno = res.Output.Setlinfo.Certno
  1189. order.Gend = res.Output.Setlinfo.Gend
  1190. order.Naty = res.Output.Setlinfo.Naty
  1191. order.Age = res.Output.Setlinfo.Age
  1192. order.Insutype = res.Output.Setlinfo.Insutype
  1193. order.PsnType = res.Output.Setlinfo.PsnType
  1194. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1195. order.SetlTime = res.Output.Setlinfo.SetlTime
  1196. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1197. order.MedType = res.Output.Setlinfo.MedType
  1198. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1199. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1200. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1201. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1202. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1203. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1204. order.HifpPay = res.Output.Setlinfo.HifpPay
  1205. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1206. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1207. order.HifesPay = res.Output.Setlinfo.HifesPay
  1208. order.HifobPay = res.Output.Setlinfo.HifobPay
  1209. order.MafPay = res.Output.Setlinfo.MafPay
  1210. order.OthPay = res.Output.Setlinfo.OthPay
  1211. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1212. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1213. order.AcctPay = res.Output.Setlinfo.AcctPay
  1214. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1215. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1216. order.Balc = res.Output.Setlinfo.Balc
  1217. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1218. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1219. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1220. order.ClrWay = res.Output.Setlinfo.ClrWay
  1221. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1222. detailStr := string(setlDetail)
  1223. order.SetlDetail = detailStr
  1224. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1225. err = service.UpDateOrder(order)
  1226. if err == nil {
  1227. c.ServeSuccessJSON(map[string]interface{}{
  1228. "msg": "结算成功",
  1229. })
  1230. } else {
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1232. return
  1233. }
  1234. }
  1235. } else {
  1236. adminUser := c.GetAdminUserInfo()
  1237. errlog := &models.HisOrderError{
  1238. UserOrgId: adminUser.CurrentOrgId,
  1239. Ctime: time.Now().Unix(),
  1240. Mtime: time.Now().Unix(),
  1241. ErrMsg: res.ErrMsg,
  1242. Status: 1,
  1243. PatientId: id,
  1244. RecordTime: recordDateTime,
  1245. Stage: 4,
  1246. }
  1247. service.CreateErrMsgLog(errlog)
  1248. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterRepeatException)
  1249. return
  1250. }
  1251. } else {
  1252. adminUser := c.GetAdminUserInfo()
  1253. errlog := &models.HisOrderError{
  1254. UserOrgId: adminUser.CurrentOrgId,
  1255. Ctime: time.Now().Unix(),
  1256. Mtime: time.Now().Unix(),
  1257. ErrMsg: res.ErrMsg,
  1258. Status: 1,
  1259. PatientId: id,
  1260. RecordTime: recordDateTime,
  1261. Stage: 4,
  1262. }
  1263. service.CreateErrMsgLog(errlog)
  1264. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1265. return
  1266. }
  1267. } else {
  1268. var total float64
  1269. for _, item := range prescriptions {
  1270. if item.Type == 1 { //药品
  1271. for _, subItem := range item.HisDoctorAdviceInfo {
  1272. total = total + (subItem.Price * subItem.PrescribingNumber)
  1273. }
  1274. }
  1275. if item.Type == 2 { //项目
  1276. for _, subItem := range item.HisPrescriptionProject {
  1277. total = total + (subItem.Price * float64(subItem.Count))
  1278. }
  1279. }
  1280. for _, subItem := range item.HisAdditionalCharge {
  1281. total = total + (subItem.Price * float64(subItem.Count))
  1282. }
  1283. }
  1284. allTotal := fmt.Sprintf("%.2f", total)
  1285. totals, _ := strconv.ParseFloat(allTotal, 64)
  1286. order := &models.HisOrder{
  1287. UserOrgId: adminUser.CurrentOrgId,
  1288. HisPatientId: his.ID,
  1289. PatientId: id,
  1290. SettleAccountsDate: recordDateTime,
  1291. Ctime: time.Now().Unix(),
  1292. Mtime: time.Now().Unix(),
  1293. Status: 1,
  1294. OrderStatus: 2,
  1295. Number: chrg_bchno,
  1296. MedfeeSumamt: totals,
  1297. PayWay: pay_way,
  1298. PayPrice: pay_price,
  1299. PayCardNo: pay_card_no,
  1300. DiscountPrice: discount_price,
  1301. PreferentialPrice: preferential_price,
  1302. RealityPrice: reality_price,
  1303. FoundPrice: found_price,
  1304. MedicalInsurancePrice: medical_insurance_price,
  1305. PrivatePrice: private_price,
  1306. }
  1307. err = service.CreateOrder(order)
  1308. if err != nil {
  1309. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreatePreOrderException)
  1310. return
  1311. }
  1312. var customs []*Custom
  1313. for _, item := range prescriptions {
  1314. if item.Type == 1 { //药品
  1315. for _, subItem := range item.HisDoctorAdviceInfo {
  1316. cus := &Custom{
  1317. AdviceId: subItem.ID,
  1318. ProjectId: 0,
  1319. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1320. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1321. FeedetlSn: subItem.FeedetlSn,
  1322. Price: fmt.Sprintf("%.2f", subItem.Price),
  1323. MedListCodg: subItem.MedListCodg,
  1324. Type: 1,
  1325. }
  1326. customs = append(customs, cus)
  1327. }
  1328. }
  1329. if item.Type == 2 { //项目
  1330. for _, subItem := range item.HisPrescriptionProject {
  1331. cus := &Custom{
  1332. AdviceId: 0,
  1333. ProjectId: subItem.ID,
  1334. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1335. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1336. FeedetlSn: subItem.FeedetlSn,
  1337. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1338. MedListCodg: subItem.MedListCodg,
  1339. Type: 2,
  1340. }
  1341. customs = append(customs, cus)
  1342. }
  1343. }
  1344. for _, item := range item.HisAdditionalCharge {
  1345. cus := &Custom{
  1346. ItemId: item.ID,
  1347. AdviceId: 0,
  1348. ProjectId: 0,
  1349. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1350. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1351. FeedetlSn: item.FeedetlSn,
  1352. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1353. MedListCodg: item.XtHisAddtionConfig.Code,
  1354. Type: 3,
  1355. }
  1356. customs = append(customs, cus)
  1357. }
  1358. }
  1359. for _, item := range customs {
  1360. var advice_id int64 = 0
  1361. var project_id int64 = 0
  1362. var item_id int64 = 0
  1363. var types int64 = 0
  1364. if item.Type == 1 {
  1365. advice_id = item.AdviceId
  1366. project_id = 0
  1367. item_id = 0
  1368. } else if item.Type == 2 {
  1369. advice_id = 0
  1370. item_id = 0
  1371. project_id = item.ProjectId
  1372. } else if item.Type == 3 {
  1373. advice_id = 0
  1374. item_id = item.ItemId
  1375. project_id = 0
  1376. }
  1377. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1378. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1379. pric, _ := strconv.ParseFloat(item.Price, 32)
  1380. info := &models.HisOrderInfo{
  1381. OrderNumber: order.Number,
  1382. UploadDate: time.Now().Unix(),
  1383. AdviceId: advice_id,
  1384. DetItemFeeSumamt: detItemFeeSumamt,
  1385. Cnt: cut,
  1386. Pric: pric,
  1387. PatientId: id,
  1388. Status: 1,
  1389. Mtime: time.Now().Unix(),
  1390. Ctime: time.Now().Unix(),
  1391. UserOrgId: adminUser.CurrentOrgId,
  1392. HisPatientId: his.ID,
  1393. OrderId: order.ID,
  1394. ProjectId: project_id,
  1395. Type: types,
  1396. ItemId: item_id,
  1397. }
  1398. service.CreateOrderInfo(info)
  1399. }
  1400. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1401. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1402. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1403. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1404. if err == nil {
  1405. c.ServeSuccessJSON(map[string]interface{}{
  1406. "msg": "结算成功",
  1407. })
  1408. } else {
  1409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAmountAccountException)
  1410. return
  1411. }
  1412. }
  1413. }
  1414. //退款
  1415. func (c *HisApiController) Refund() {
  1416. order_id, _ := c.GetInt64("order_id")
  1417. number := c.GetString("number")
  1418. record_time := c.GetString("record_time")
  1419. patient_id, _ := c.GetInt64("patient_id")
  1420. timeLayout := "2006-01-02"
  1421. loc, _ := time.LoadLocation("Local")
  1422. adminUser := c.GetAdminUserInfo()
  1423. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1424. fmt.Println(err)
  1425. if err != nil {
  1426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1427. return
  1428. }
  1429. recordDateTime := theTime.Unix()
  1430. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1431. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1432. var order models.HisOrder
  1433. order, _ = service.GetHisOrderByID(order_id)
  1434. if order.ID == 0 {
  1435. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1436. }
  1437. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1438. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1439. if config.IsOpen == 1 { //对接了医保,走医保流程
  1440. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1441. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1442. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1443. resp, requestErr := http.Get(api)
  1444. if requestErr != nil {
  1445. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1446. return
  1447. }
  1448. body, ioErr := ioutil.ReadAll(resp.Body)
  1449. if ioErr != nil {
  1450. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1452. return
  1453. }
  1454. var respJSON map[string]interface{}
  1455. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1456. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1457. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1458. return
  1459. }
  1460. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1461. userJSONBytes, _ := json.Marshal(respJSON)
  1462. fmt.Println(respJSON)
  1463. fmt.Println(userJSONBytes)
  1464. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1465. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1466. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1467. resp2, requestErr2 := http.Get(api2)
  1468. if requestErr2 != nil {
  1469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1470. return
  1471. }
  1472. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1473. if ioErr2 != nil {
  1474. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1475. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1476. return
  1477. }
  1478. var respJSON2 map[string]interface{}
  1479. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1480. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1481. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1482. return
  1483. }
  1484. //api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1485. // "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1486. // "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1487. //resp3, requestErr3 := http.Get(api3)
  1488. //if requestErr3 != nil {
  1489. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1490. // return
  1491. //}
  1492. //
  1493. //body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1494. //if ioErr3 != nil {
  1495. // utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1496. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1497. // return
  1498. //}
  1499. //var respJSON3 map[string]interface{}
  1500. //if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1501. // utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1502. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1503. // return
  1504. //}
  1505. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1506. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1507. if err == nil {
  1508. c.ServeSuccessJSON(map[string]interface{}{
  1509. "msg": "退费成功",
  1510. })
  1511. } else {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1513. return
  1514. }
  1515. } else {
  1516. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1517. if err == nil {
  1518. c.ServeSuccessJSON(map[string]interface{}{
  1519. "msg": "退费成功",
  1520. })
  1521. } else {
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1523. return
  1524. }
  1525. }
  1526. }
  1527. func (c *HisApiController) RefundNumber() {
  1528. record_time := c.GetString("record_time")
  1529. patient_id, _ := c.GetInt64("patient_id")
  1530. timeLayout := "2006-01-02"
  1531. loc, _ := time.LoadLocation("Local")
  1532. adminUser := c.GetAdminUserInfo()
  1533. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1534. fmt.Println(err)
  1535. if err != nil {
  1536. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1537. return
  1538. }
  1539. recordDateTime := theTime.Unix()
  1540. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1541. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1542. //order, _ := service.GetHisOrderByID(order_id)
  1543. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1544. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1545. if config.IsOpen == 1 { //对接了医保,走医保流程
  1546. api3 := "http://127.0.0.1:9532/" + "gdyb/three?psn_no=" + his.PsnNo +
  1547. "&mdtrt_id=" + his.Number + "&ipt_otp_no=" + his.IptOtpNo + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1548. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1549. resp3, requestErr3 := http.Get(api3)
  1550. if requestErr3 != nil {
  1551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1552. return
  1553. }
  1554. body3, ioErr3 := ioutil.ReadAll(resp3.Body)
  1555. if ioErr3 != nil {
  1556. utils.ErrorLog("接口返回数据读取失败: %v", ioErr3)
  1557. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1558. return
  1559. }
  1560. var respJSON3 map[string]interface{}
  1561. if err := json.Unmarshal([]byte(string(body3)), &respJSON3); err != nil {
  1562. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1564. return
  1565. }
  1566. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1567. service.UpdataRegStatus(patient_id, recordDateTime, adminUser.CurrentOrgId)
  1568. if err == nil {
  1569. c.ServeSuccessJSON(map[string]interface{}{
  1570. "msg": "退费成功",
  1571. })
  1572. } else {
  1573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1574. return
  1575. }
  1576. } else {
  1577. //err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1578. //if err == nil {
  1579. // c.ServeSuccessJSON(map[string]interface{}{
  1580. // "msg": "退费成功",
  1581. // })
  1582. //} else {
  1583. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1584. // return
  1585. //}
  1586. }
  1587. }
  1588. func (c *HisApiController) RefundDetail() {
  1589. order_id, _ := c.GetInt64("order_id")
  1590. number := c.GetString("number")
  1591. record_time := c.GetString("record_time")
  1592. patient_id, _ := c.GetInt64("patient_id")
  1593. timeLayout := "2006-01-02"
  1594. loc, _ := time.LoadLocation("Local")
  1595. adminUser := c.GetAdminUserInfo()
  1596. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1597. fmt.Println(err)
  1598. if err != nil {
  1599. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1600. return
  1601. }
  1602. recordDateTime := theTime.Unix()
  1603. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1604. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1605. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1606. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1607. var order models.HisOrder
  1608. order, _ = service.GetHisOrderByID(order_id)
  1609. if order.ID == 0 {
  1610. order, _ = service.GetHisOrderThree(recordDateTime, patient_id, adminUser.CurrentOrgId)
  1611. }
  1612. if config.IsOpen == 1 { //对接了医保,走医保流程
  1613. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1614. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1615. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1616. resp2, requestErr2 := http.Get(api2)
  1617. if requestErr2 != nil {
  1618. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1619. return
  1620. }
  1621. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  1622. if ioErr2 != nil {
  1623. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  1624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1625. return
  1626. }
  1627. var respJSON2 map[string]interface{}
  1628. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  1629. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1631. return
  1632. }
  1633. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1634. if err == nil {
  1635. c.ServeSuccessJSON(map[string]interface{}{
  1636. "msg": "退费成功",
  1637. })
  1638. } else {
  1639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1640. return
  1641. }
  1642. } else {
  1643. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1644. if err == nil {
  1645. c.ServeSuccessJSON(map[string]interface{}{
  1646. "msg": "退费成功",
  1647. })
  1648. } else {
  1649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1650. return
  1651. }
  1652. }
  1653. }
  1654. //对账
  1655. func (c *HisApiController) GetCheckAccount() {
  1656. start_time := c.GetString("start_time")
  1657. end_time := c.GetString("end_time")
  1658. insutype := c.GetString("insutype")
  1659. clr_type := c.GetString("clr_type")
  1660. admin_user_id, _ := c.GetInt64("admin_user_id")
  1661. adminUser := c.GetAdminUserInfo()
  1662. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1663. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1664. timeLayout := "2006-01-02"
  1665. loc, _ := time.LoadLocation("Local")
  1666. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1667. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1668. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  1669. decimal.DivisionPrecision = 2
  1670. var medfee_sumamt float64
  1671. var acct_pay float64
  1672. var fund_pay_sumamt float64
  1673. fixmedins_setl_cnt := int64(len(orders))
  1674. for _, item := range orders {
  1675. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1676. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  1677. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1678. }
  1679. var user_name string
  1680. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1681. if role.ID == 0 {
  1682. user_name = "xxx"
  1683. } else {
  1684. user_name = role.UserName
  1685. }
  1686. if config.IsOpen == 1 {
  1687. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  1688. "insutype=" + insutype +
  1689. "&clr_type=" + clr_type +
  1690. "&setl_optins=" + miConfig.OrgName +
  1691. "&stmt_begndate=" + start_time +
  1692. "&stm_enddate=" + end_time +
  1693. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1694. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1695. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  1696. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1697. "&fixmedins_code=" + miConfig.Code +
  1698. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1699. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1700. "&secret_key=" + miConfig.SecretKey +
  1701. "&org_name=" + miConfig.OrgName +
  1702. "&doctor=" + user_name
  1703. fmt.Println(api)
  1704. resp, requestErr := http.Get(api)
  1705. if requestErr != nil {
  1706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1707. return
  1708. }
  1709. body, ioErr := ioutil.ReadAll(resp.Body)
  1710. fmt.Println(body)
  1711. if ioErr != nil {
  1712. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1714. return
  1715. }
  1716. var respJSON map[string]interface{}
  1717. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1718. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1720. return
  1721. }
  1722. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1723. userJSONBytes, _ := json.Marshal(respJSON)
  1724. var res ResultEight
  1725. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1726. utils.ErrorLog("解析失败:%v", err)
  1727. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1728. return
  1729. }
  1730. if res.Infcode == 0 {
  1731. c.ServeSuccessJSON(map[string]interface{}{
  1732. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  1733. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  1734. })
  1735. } else {
  1736. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1737. }
  1738. }
  1739. }
  1740. //对账明细
  1741. func (c *HisApiController) GetCheckDetailAccount() {
  1742. start_time := c.GetString("start_time")
  1743. end_time := c.GetString("end_time")
  1744. admin_user_id, _ := c.GetInt64("admin_user_id")
  1745. adminUser := c.GetAdminUserInfo()
  1746. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1747. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1748. timeLayout := "2006-01-02"
  1749. loc, _ := time.LoadLocation("Local")
  1750. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1751. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1752. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  1753. Mkdir(miConfig.OrgName)
  1754. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  1755. file_name := file + ".txt"
  1756. zip_name := file + ".zip"
  1757. zip_path := miConfig.OrgName + "/" + zip_name
  1758. file_path := miConfig.OrgName + "/" + file_name
  1759. decimal.DivisionPrecision = 2
  1760. var medfee_sumamt float64
  1761. var psn_cash_pay float64
  1762. var fund_pay_sumamt float64
  1763. fixmedins_setl_cnt := int64(len(orders))
  1764. for _, item := range orders {
  1765. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  1766. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  1767. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  1768. }
  1769. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  1770. defer f.Close()
  1771. if err != nil {
  1772. fmt.Println(err.Error())
  1773. } else {
  1774. for _, item := range orders {
  1775. var refd_setl_flag string
  1776. if item.OrderStatus == 2 {
  1777. refd_setl_flag = "0"
  1778. }
  1779. if item.OrderStatus == 3 {
  1780. refd_setl_flag = "1"
  1781. }
  1782. var str string
  1783. str = item.SetlId + " " +
  1784. item.MdtrtId + " " +
  1785. item.PsnNo + " " +
  1786. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  1787. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  1788. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  1789. _, err = f.Write([]byte(str))
  1790. }
  1791. }
  1792. Zip(file_path, zip_path)
  1793. fmt.Println(ReadFile(zip_path))
  1794. fmt.Println(string(ReadFile(zip_path)))
  1795. if config.IsOpen == 1 {
  1796. var user_name string
  1797. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1798. if role.ID == 0 {
  1799. user_name = "管理员"
  1800. } else {
  1801. user_name = role.UserName
  1802. }
  1803. baseParams := models.BaseParams{
  1804. SecretKey: miConfig.SecretKey,
  1805. FixmedinsCode: miConfig.Code,
  1806. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1807. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1808. OrgName: miConfig.OrgName,
  1809. Doctor: user_name,
  1810. }
  1811. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  1812. var dat map[string]interface{}
  1813. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1814. fmt.Println(dat)
  1815. } else {
  1816. fmt.Println(err)
  1817. }
  1818. userJSONBytes, _ := json.Marshal(dat)
  1819. var res ResultNine
  1820. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1821. utils.ErrorLog("解析失败:%v", err)
  1822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1823. return
  1824. }
  1825. if res.Infcode == 0 {
  1826. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  1827. "file_qury_no=" + res.Output.FileQuryNo +
  1828. "&setl_optins=" + miConfig.OrgName +
  1829. "&stmt_begndate=" + start_time +
  1830. "&stm_enddate=" + end_time +
  1831. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  1832. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  1833. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  1834. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  1835. "&fixmedins_code=" + miConfig.Code +
  1836. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  1837. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  1838. "&secret_key=" + miConfig.SecretKey +
  1839. "&org_name=" + miConfig.OrgName +
  1840. "&doctor=" + user_name
  1841. resp, requestErr := http.Get(api)
  1842. if requestErr != nil {
  1843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1844. return
  1845. }
  1846. body, ioErr := ioutil.ReadAll(resp.Body)
  1847. if ioErr != nil {
  1848. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1850. return
  1851. }
  1852. var respJSON map[string]interface{}
  1853. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1854. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1855. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1856. return
  1857. }
  1858. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1859. userJSONBytes, _ := json.Marshal(respJSON)
  1860. var res ResultTen
  1861. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1862. utils.ErrorLog("解析失败:%v", err)
  1863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1864. return
  1865. }
  1866. if res.Infcode == 0 {
  1867. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  1868. c.ServeSuccessJSON(map[string]interface{}{
  1869. "msg": "明细对账成功",
  1870. })
  1871. }
  1872. } else {
  1873. }
  1874. }
  1875. }
  1876. func (c *HisApiController) GetSettleAccounts() {
  1877. //id, _ := c.GetInt64("id")
  1878. //record_time := c.GetString("record_time")
  1879. order_id, _ := c.GetInt64("order_id")
  1880. admin_user_id, _ := c.GetInt64("admin_user_id")
  1881. //timeLayout := "2006-01-02"
  1882. //loc, _ := time.LoadLocation("Local")
  1883. //
  1884. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1885. //if err != nil {
  1886. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1887. // return
  1888. //}
  1889. //recordDateTime := theTime.Unix()
  1890. adminUser := c.GetAdminUserInfo()
  1891. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1892. order, _ := service.GetHisOrderByID(order_id)
  1893. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  1894. var bedCostTotal float64 = 0 //床位总费
  1895. var bedCostSelfTotal float64 = 0 //床位自费
  1896. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  1897. var operationCostTotal float64 = 0 //手术费
  1898. var operationCostSelfTotal float64 = 0 //手术费
  1899. var operationCostPartSelfTotal float64 = 0 //手术费
  1900. var otherCostTotal float64 = 0 //其他费用
  1901. var otherCostSelfTotal float64 = 0 //其他费用
  1902. var otherCostPartSelfTotal float64 = 0 //其他费用
  1903. var materialCostTotal float64 = 0 //材料费
  1904. var materialCostSelfTotal float64 = 0 //材料费
  1905. var materialCostPartSelfTotal float64 = 0 //材料费
  1906. var westernMedicineCostTotal float64 = 0 //西药费
  1907. var westernMedicineCostSelfTotal float64 = 0 //西药费
  1908. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  1909. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  1910. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  1911. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  1912. var checkCostTotal float64 = 0 //检查费
  1913. var checkCostSelfTotal float64 = 0 //检查费
  1914. var checkCostPartSelfTotal float64 = 0 //检查费
  1915. var laboratoryCostTotal float64 = 0 //化验费
  1916. var laboratoryCostSelfTotal float64 = 0 //化验费
  1917. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  1918. var treatCostTotal float64 = 0 //治疗费用
  1919. var treatCostSelfTotal float64 = 0 //治疗费用
  1920. var treatCostPartSelfTotal float64 = 0 //治疗费用
  1921. decimal.DivisionPrecision = 2
  1922. for _, item := range orderInfos {
  1923. if item.MedChrgitmType == "01" { //床位费
  1924. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1925. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1926. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1927. }
  1928. if item.MedChrgitmType == "03" { //检查费
  1929. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1930. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1931. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1932. }
  1933. if item.MedChrgitmType == "04" { //化验费
  1934. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1935. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1936. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1937. }
  1938. if item.MedChrgitmType == "05" { //治疗费
  1939. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1940. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1941. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1942. }
  1943. if item.MedChrgitmType == "06" { //手术费
  1944. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1945. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1946. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1947. }
  1948. if item.MedChrgitmType == "08" { //材料费
  1949. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1950. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1951. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1952. }
  1953. if item.MedChrgitmType == "09" { //西药费
  1954. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1955. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1956. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1957. }
  1958. if item.MedChrgitmType == "11" { //中成费
  1959. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1960. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1961. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1962. }
  1963. if item.MedChrgitmType == "14" { //其他费
  1964. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1965. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1966. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  1967. }
  1968. }
  1969. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1970. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1971. var user_name string
  1972. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1973. if role.ID == 0 {
  1974. user_name = "管理员"
  1975. } else {
  1976. user_name = role.UserName
  1977. }
  1978. baseParams := models.BaseParams{
  1979. SecretKey: miConfig.SecretKey,
  1980. FixmedinsCode: miConfig.Code,
  1981. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  1982. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  1983. OrgName: miConfig.OrgName,
  1984. Doctor: user_name,
  1985. }
  1986. businessParams := models.BusinessParams{
  1987. PsnNo: order.PsnNo,
  1988. MdtrtId: order.MdtrtId,
  1989. SetlId: order.SetlId,
  1990. }
  1991. if config.IsOpen == 1 {
  1992. result := service.Gdyb5203(baseParams, businessParams)
  1993. var dat map[string]interface{}
  1994. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  1995. fmt.Println(dat)
  1996. } else {
  1997. fmt.Println(err)
  1998. }
  1999. userJSONBytes, _ := json.Marshal(dat)
  2000. var res ResultEleven
  2001. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2002. utils.ErrorLog("解析失败:%v", err)
  2003. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2004. return
  2005. }
  2006. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  2007. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  2008. if res.Infcode == 0 {
  2009. c.ServeSuccessJSON(map[string]interface{}{
  2010. "charge_admin": charge_admin,
  2011. "printor_admin": printor_admin,
  2012. "info": res.Output.Setlinfo,
  2013. "bedCostTotal": bedCostTotal,
  2014. "bedCostSelfTotal": bedCostSelfTotal,
  2015. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2016. "operationCostTotal": operationCostTotal,
  2017. "operationCostSelfTotal": operationCostSelfTotal,
  2018. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2019. "otherCostTotal": otherCostTotal,
  2020. "otherCostSelfTotal": otherCostSelfTotal,
  2021. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2022. "materialCostTotal": materialCostTotal,
  2023. "materialCostSelfTotal": materialCostSelfTotal,
  2024. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2025. "westernMedicineCostTotal": westernMedicineCostTotal,
  2026. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2027. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2028. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2029. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2030. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2031. "checkCostTotal": checkCostTotal,
  2032. "checkCostSelfTotal": checkCostSelfTotal,
  2033. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2034. "laboratoryCostTotal": laboratoryCostTotal,
  2035. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2036. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2037. "treatCostTotal": treatCostTotal,
  2038. "treatCostSelfTotal": treatCostSelfTotal,
  2039. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2040. })
  2041. }
  2042. }
  2043. }
  2044. func (c *HisApiController) GetCode() {
  2045. name := c.GetString("name")
  2046. codg := c.GetString("codg")
  2047. adminUser := c.GetAdminUserInfo()
  2048. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2049. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2050. var user_name string
  2051. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2052. if role.ID == 0 {
  2053. user_name = "xxx"
  2054. } else {
  2055. user_name = role.UserName
  2056. }
  2057. baseParams := &models.BaseParams{
  2058. SecretKey: miConfig.SecretKey,
  2059. FixmedinsCode: miConfig.Code,
  2060. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2061. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2062. OrgName: miConfig.OrgName,
  2063. Doctor: user_name,
  2064. }
  2065. if config.IsOpen == 1 {
  2066. result := service.Gdyb3301(baseParams, name, codg)
  2067. var dat map[string]interface{}
  2068. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2069. fmt.Println(dat)
  2070. } else {
  2071. fmt.Println(err)
  2072. }
  2073. }
  2074. }
  2075. func (c *HisApiController) CheckTreatment() {
  2076. patient_id, _ := c.GetInt64("patient_id", 0)
  2077. record_time := c.GetString("record_time")
  2078. insutype := c.GetString("insutype")
  2079. timeLayout := "2006-01-02"
  2080. loc, _ := time.LoadLocation("Local")
  2081. adminUser := c.GetAdminUserInfo()
  2082. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2083. fmt.Println(err)
  2084. if err != nil {
  2085. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2086. return
  2087. }
  2088. recordDateTime := theTime.Unix()
  2089. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2090. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  2091. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2092. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2093. var user_name string
  2094. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2095. if role.ID == 0 {
  2096. user_name = "xxx"
  2097. } else {
  2098. user_name = role.UserName
  2099. }
  2100. baseParams := models.BaseParams{
  2101. SecretKey: miConfig.SecretKey,
  2102. FixmedinsCode: miConfig.Code,
  2103. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2104. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2105. OrgName: miConfig.OrgName,
  2106. Doctor: user_name,
  2107. }
  2108. if config.IsOpen == 1 {
  2109. result := service.Gdyb2001(baseParams, his.PsnNo, insutype, strconv.FormatInt(patientPrescription.RegisterType, 10))
  2110. var dat map[string]interface{}
  2111. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2112. fmt.Println(dat)
  2113. } else {
  2114. fmt.Println(err)
  2115. }
  2116. }
  2117. }
  2118. func (c *HisApiController) PutRecord() {
  2119. id, _ := c.GetInt64("id")
  2120. record_time := c.GetString("record_time")
  2121. timeLayout := "2006-01-02"
  2122. loc, _ := time.LoadLocation("Local")
  2123. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2124. if err != nil {
  2125. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2126. return
  2127. }
  2128. recordDateTime := theTime.Unix()
  2129. adminInfo := c.GetAdminUserInfo()
  2130. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  2131. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2132. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2133. fmt.Println(miConfig.SecretKey)
  2134. if patient == nil {
  2135. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2136. return
  2137. }
  2138. if len(patient.IdCardNo) == 0 {
  2139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2140. return
  2141. }
  2142. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  2143. if config.IsOpen == 1 {
  2144. 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
  2145. resp, requestErr := http.Get(api)
  2146. if requestErr != nil {
  2147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2148. return
  2149. }
  2150. defer resp.Body.Close()
  2151. body, ioErr := ioutil.ReadAll(resp.Body)
  2152. if ioErr != nil {
  2153. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2155. return
  2156. }
  2157. var respJSON map[string]interface{}
  2158. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2159. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2160. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2161. return
  2162. }
  2163. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2164. userJSONBytes, _ := json.Marshal(userJSON)
  2165. var res ResultTwo
  2166. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2167. utils.ErrorLog("解析失败:%v", err)
  2168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2169. return
  2170. }
  2171. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  2172. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  2173. infoStr := string(Iinfos)
  2174. idetinfoStr := string(Idetinfos)
  2175. if res.Infcode == 0 {
  2176. his := models.VMHisPatient{
  2177. Status: 1,
  2178. Ctime: time.Now().Unix(),
  2179. Mtime: time.Now().Unix(),
  2180. PsnNo: res.Output.Baseinfo.PsnNo,
  2181. PsnCertType: res.Output.Baseinfo.PsnCertType,
  2182. Certno: res.Output.Baseinfo.Certno,
  2183. PsnName: res.Output.Baseinfo.PsnName,
  2184. Gend: res.Output.Baseinfo.Gend,
  2185. Naty: res.Output.Baseinfo.Naty,
  2186. Brdy: res.Output.Baseinfo.Brdy,
  2187. Age: res.Output.Baseinfo.Age,
  2188. Iinfo: infoStr,
  2189. Idetinfo: idetinfoStr,
  2190. PatientId: patient.ID,
  2191. RecordDate: theTime.Unix(),
  2192. UserOrgId: adminInfo.CurrentOrgId,
  2193. AdminUserId: adminInfo.AdminUser.Id,
  2194. IsReturn: 1,
  2195. }
  2196. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  2197. 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")
  2198. 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")
  2199. var dat map[string]interface{}
  2200. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2201. fmt.Println(dat)
  2202. } else {
  2203. fmt.Println(err)
  2204. }
  2205. var dat2 map[string]interface{}
  2206. if err := json.Unmarshal([]byte(result2), &dat2); err == nil {
  2207. fmt.Println(dat2)
  2208. } else {
  2209. fmt.Println(err)
  2210. }
  2211. } else {
  2212. adminUser := c.GetAdminUserInfo()
  2213. errlog := &models.HisOrderError{
  2214. UserOrgId: adminUser.CurrentOrgId,
  2215. Ctime: time.Now().Unix(),
  2216. Mtime: time.Now().Unix(),
  2217. ErrMsg: res.ErrMsg,
  2218. Status: 1,
  2219. PatientId: id,
  2220. RecordTime: recordDateTime,
  2221. Stage: 1,
  2222. }
  2223. service.CreateErrMsgLog(errlog)
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeGdybOneException)
  2225. return
  2226. }
  2227. }
  2228. }
  2229. func (c *HisApiController) GetUploadDiag() {
  2230. id, _ := c.GetInt64("id")
  2231. record_time := c.GetString("record_time")
  2232. diagnosis_id, _ := c.GetInt64("diagnosis")
  2233. sick_type, _ := c.GetInt64("sick_type")
  2234. reg_type, _ := c.GetInt64("reg_type")
  2235. timeLayout := "2006-01-02"
  2236. loc, _ := time.LoadLocation("Local")
  2237. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2238. if err != nil {
  2239. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2240. return
  2241. }
  2242. var patientPrescription models.HisPrescriptionInfo
  2243. recordDateTime := theTime.Unix()
  2244. adminInfo := c.GetAdminUserInfo()
  2245. patientPrescription, _ = service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2246. if patientPrescription.ID == 0 {
  2247. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2248. }
  2249. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  2250. diagnosisConfig, _ := service.FindDiagnoseById(diagnosis_id)
  2251. his, _ := service.GetVMHisPatientInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  2252. sickConfig, _ := service.FindSickById(sick_type)
  2253. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  2254. api2 := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  2255. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  2256. "&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 +
  2257. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey + "&sick_code=" + sickConfig.CountryCode + "&sick_name=" + sickConfig.ClassName
  2258. resp2, requestErr2 := http.Get(api2)
  2259. if requestErr2 != nil {
  2260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2261. return
  2262. }
  2263. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2264. if ioErr2 != nil {
  2265. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2267. return
  2268. }
  2269. var respJSON2 map[string]interface{}
  2270. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2271. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2272. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2273. return
  2274. }
  2275. respJSON2 = respJSON2["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2276. userJSONBytes2, _ := json.Marshal(respJSON2)
  2277. var res2 ResultSix
  2278. if err := json.Unmarshal(userJSONBytes2, &res2); err != nil {
  2279. utils.ErrorLog("解析失败:%v", err)
  2280. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2281. return
  2282. }
  2283. if res2.Infcode == -1 {
  2284. adminUser := c.GetAdminUserInfo()
  2285. errlog := &models.HisOrderError{
  2286. UserOrgId: adminUser.CurrentOrgId,
  2287. Ctime: time.Now().Unix(),
  2288. Mtime: time.Now().Unix(),
  2289. ErrMsg: res2.ErrMsg,
  2290. Status: 1,
  2291. PatientId: id,
  2292. RecordTime: recordDateTime,
  2293. Stage: 3,
  2294. }
  2295. service.CreateErrMsgLog(errlog)
  2296. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterThreeException)
  2297. return
  2298. }
  2299. c.ServeSuccessJSON(map[string]interface{}{
  2300. "msg": "上传成功",
  2301. })
  2302. }
  2303. func PathExists(path string) (bool, error) {
  2304. _, err := os.Stat(path)
  2305. if err == nil {
  2306. return true, nil
  2307. }
  2308. if os.IsNotExist(err) {
  2309. return false, nil
  2310. }
  2311. return false, err
  2312. }
  2313. //创建文件夹
  2314. func Mkdir(dir string) {
  2315. // 创建文件夹
  2316. exist, err := PathExists(dir)
  2317. if err != nil {
  2318. fmt.Println(err.Error())
  2319. } else {
  2320. if exist {
  2321. fmt.Println(dir + "文件夹已存在!")
  2322. } else {
  2323. // 文件夹名称,权限
  2324. err := os.Mkdir(dir, os.ModePerm)
  2325. if err != nil {
  2326. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2327. } else {
  2328. fmt.Println(dir + "文件夹创建成功!")
  2329. }
  2330. }
  2331. }
  2332. }
  2333. //压缩文件
  2334. func Zip(srcFile string, destZip string) error {
  2335. zipfile, err := os.Create(destZip)
  2336. if err != nil {
  2337. return err
  2338. }
  2339. defer zipfile.Close()
  2340. archive := zip.NewWriter(zipfile)
  2341. defer archive.Close()
  2342. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2343. if err != nil {
  2344. return err
  2345. }
  2346. header, err := zip.FileInfoHeader(info)
  2347. if err != nil {
  2348. return err
  2349. }
  2350. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2351. // header.Name = path
  2352. if info.IsDir() {
  2353. header.Name += "/"
  2354. } else {
  2355. header.Method = zip.Deflate
  2356. }
  2357. writer, err := archive.CreateHeader(header)
  2358. if err != nil {
  2359. return err
  2360. }
  2361. if !info.IsDir() {
  2362. file, err := os.Open(path)
  2363. if err != nil {
  2364. return err
  2365. }
  2366. defer file.Close()
  2367. _, err = io.Copy(writer, file)
  2368. }
  2369. return err
  2370. })
  2371. return err
  2372. }
  2373. func ReadFile(filePath string) []byte {
  2374. f, err := os.Open(filePath)
  2375. if err != nil {
  2376. fmt.Println("read file fail", err)
  2377. return nil
  2378. }
  2379. defer f.Close()
  2380. fd, err := ioutil.ReadAll(f)
  2381. if err != nil {
  2382. fmt.Println("read to fd fail", err)
  2383. return nil
  2384. }
  2385. return fd
  2386. }
  2387. func RemoveRepeatedCode(arr []string) (newArr []string) {
  2388. newArr = make([]string, 0)
  2389. for i := 0; i < len(arr); i++ {
  2390. repeat := false
  2391. for j := i + 1; j < len(arr); j++ {
  2392. if arr[i] == arr[j] {
  2393. repeat = true
  2394. break
  2395. }
  2396. }
  2397. if !repeat {
  2398. newArr = append(newArr, arr[i])
  2399. }
  2400. }
  2401. return
  2402. }