his_api_controller.go 94KB

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