his_api_controller.go 96KB

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