his_api_controller.go 95KB

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