his_api_controller.go 95KB

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