coordinate_controller.go 83KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591
  1. package coordinate
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "fmt"
  6. "gdyb/controllers"
  7. "gdyb/enums"
  8. "gdyb/models"
  9. "gdyb/service"
  10. "gdyb/utils"
  11. "github.com/astaxie/beego"
  12. "io/ioutil"
  13. "math/rand"
  14. "os"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. type CoordinateController struct {
  20. controllers.BaseAuthAPIController
  21. }
  22. type ResultReg struct {
  23. ResultCode string `json:"resultCode"`
  24. ResultDesc string `json:"resultDesc"`
  25. InfoSeq string `json:"infoSeq"`
  26. }
  27. type ResultSettle struct {
  28. ResultCode string `json:"resultCode"`
  29. ResultDesc string `json:"resultDesc"`
  30. }
  31. type ResultCancelSettle struct {
  32. ResultCode string `json:"resultCode"`
  33. ResultDesc string `json:"resultDesc"`
  34. }
  35. type Settle struct {
  36. PatientId string `json:"resultCode"`
  37. DocId string `json:"docId"`
  38. InfoSeq string `json:"infoSeq"`
  39. }
  40. type Refund struct {
  41. PatientId string `json:"resultCode"`
  42. DocId string `json:"docId"`
  43. InfoSeq string `json:"infoSeq"`
  44. }
  45. type RefundDetail struct {
  46. Msg string `json:"msg"`
  47. Result []struct {
  48. ResultMsg string `json:"resultMsg"`
  49. Code string `json:"code"`
  50. Records int `json:"records"`
  51. TotalPage int `json:"totalPage"`
  52. List []struct {
  53. Zae01 int64 `json:"ZAE01"`
  54. } `json:"list"`
  55. RecordsTotal int `json:"recordsTotal"`
  56. Pagenumber int `json:"pagenumber"`
  57. Result string `json:"result"`
  58. Total int `json:"total"`
  59. RecordsFtered int `json:"recordsFtered"`
  60. Page int `json:"page"`
  61. } `json:"result"`
  62. Code string `json:"code"`
  63. }
  64. type RefundDetailtwo struct {
  65. Msg string `json:"msg"`
  66. Code string `json:"code"`
  67. }
  68. type ResultQuery struct {
  69. Msg string `json:"msg"`
  70. Result []struct {
  71. Type string `json:"type"`
  72. Name string `json:"name"`
  73. Vaa01 int `json:"vaa01"`
  74. Vaa07 int `json:"vaa07"`
  75. Visittime string `json:"visittime"`
  76. } `json:"result"`
  77. Code string `json:"code"`
  78. }
  79. type Data struct {
  80. List []ListItem `json:"resultObj"`
  81. Result bool `json:"result"`
  82. Code int `json:"code"`
  83. ResultMsg string `json:"resultMsg"`
  84. Msg string `json:"msg"`
  85. Error bool `json:"error"`
  86. Success bool `json:"success"`
  87. }
  88. type Data10 struct {
  89. List []ListItem10 `json:"resultObj"`
  90. Result bool `json:"result"`
  91. Code int `json:"code"`
  92. ResultMsg string `json:"resultMsg"`
  93. Msg string `json:"msg"`
  94. Error bool `json:"error"`
  95. Success bool `json:"success"`
  96. }
  97. type ListItem10 struct {
  98. Vaf01 int64 `json:"vaf01"`
  99. }
  100. type ListItem struct {
  101. Acf01 int64 `json:"acf01"`
  102. Bcq04 string `json:"bcq04"`
  103. Abw01 string `json:"abw01"`
  104. Aau01 string `json:"aau01"`
  105. Vaa08 string `json:"vaa08"`
  106. Vae11 string `json:"vae11"`
  107. Vaa05 string `json:"vaa05"`
  108. Vaa10 int `json:"vaa10"`
  109. Vaa01 int `json:"vaa01"`
  110. Vaa07 int `json:"vaa07"`
  111. Vaa12 string `json:"vaa12"`
  112. Abbrp string `json:"abbrp"`
  113. Bck01A int `json:"bck01a"`
  114. Bck01B int `json:"bck01b"`
  115. Vaa15 string `json:"vaa15"`
  116. Vaa35 string `json:"vaa35"`
  117. }
  118. type ResultUpload struct {
  119. Code string `json:"code"`
  120. Msg string `json:"msg"`
  121. Result []struct {
  122. List []interface{} `json:"list"`
  123. Page int64 `json:"page"`
  124. Pagenumber int64 `json:"pagenumber"`
  125. Records int64 `json:"records"`
  126. RecordsFiltered int64 `json:"recordsFiltered"`
  127. RecordsTotal int64 `json:"recordsTotal"`
  128. Result string `json:"result"`
  129. ResultMsg string `json:"resultMsg"`
  130. Total int64 `json:"total"`
  131. TotalPage int64 `json:"totalPage"`
  132. Userdata string `json:"userdata"`
  133. } `json:"result"`
  134. }
  135. func CoordinateRcegistRouters() {
  136. beego.Router("/coordinate/check", &CoordinateController{}, "get:SavePatientMessageInfo")
  137. //坐标挂号
  138. beego.Router("/coordinate/register", &CoordinateController{}, "get:Register")
  139. //坐标记账
  140. //beego.Router("/coordinate/opKeepAccounts", &CoordinateController{}, "get:OpKeepAccounts")
  141. //坐标撤销记账
  142. //beego.Router("/coordinate/opCancelKeepAccounts", &CoordinateController{}, "get:OpCancelKeepAccounts")
  143. //坐标结算回调
  144. beego.Router("/coordinate/settle", &CoordinateController{}, "post:Settle")
  145. //坐标退费回调
  146. beego.Router("/coordinate/refund", &CoordinateController{}, "post:Refund")
  147. //坐标患者查询~上传医嘱~结算功能
  148. //beego.Router("/coordinate/settleAccount", &CoordinateController{}, "get:SettleAccount")
  149. beego.Router("/coordinate/other", &CoordinateController{}, "get:NMGother")
  150. ////内蒙古
  151. beego.Router("/nmg/coordinate/settleAccount", &CoordinateController{}, "get:NMGSettleAccount")
  152. beego.Router("/nmg/coordinate/settleAccount/cancel", &CoordinateController{}, "get:NMGCancelSettleAccount")
  153. beego.Router("/nmg/coordinate/querystock", &CoordinateController{}, "get:QueryStock")
  154. /* beego.Router("/nmg/coordinate/deladvice", &CoordinateController{}, "get:NMGdeladvice")
  155. beego.Router("/nmg/coordinate/createadvice", &CoordinateController{}, "get:NMGcreateadvice")
  156. beego.Router("/nmg/coordinate/querydiagnose", &CoordinateController{}, "get:NMGquerydiagnose")
  157. beego.Router("/nmg/coordinate/querycheck", &CoordinateController{}, "get:NMGquerycheck")
  158. */
  159. }
  160. ////删医嘱
  161. //func (c *CoordinateController)NMGdeladvice(){
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // id, _ := c.GetInt64("id")
  164. //
  165. //
  166. // patient, _ := service.GetPatientByID(c.GetAdminUserInfo().CurrentOrgId, patient_id)
  167. // result, _ := service.GetNMGHisPatientForCoordinate(0,0,0,patient.Name)
  168. // var res Data
  169. // if err := json.Unmarshal([]byte(result), &res); err != nil {
  170. // utils.ErrorLog("解析失败:%v", err)
  171. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  172. // return
  173. // }
  174. // service.CancleNMGPrescriptionForCoordinate(res.List[0].Acf01,)
  175. //
  176. //}
  177. type ProjectStruct struct {
  178. Data []struct {
  179. Bbx01 int64 `json:"bbx01"`
  180. Bda02 string `json:"bda02"`
  181. Bbx04 string `json:"bbx04"`
  182. Bbx05 string `json:"bbx05"`
  183. Bby06 string `json:"bby06"`
  184. Bdg02 string `json:"bdg02"`
  185. Acf01 int64 `json:"acf01"`
  186. Price float64 `json:"price"`
  187. Bck01 int64 `json:"bck01"`
  188. Lsqty float64 `json:"lsqty"`
  189. Bce03a string `json:"bce03a"`
  190. Bbx24 string `json:"bbx24"`
  191. Bbx25 string `json:"bbx25"`
  192. } `json:"data"`
  193. }
  194. type Medicine struct {
  195. Data []struct {
  196. Bby01 int `json:"bby01"`
  197. Ypmc string `json:"ypmc"`
  198. Gg string `json:"gg"`
  199. Dw string `json:"dw"`
  200. Jhj float64 `json:"jhj"`
  201. Pfj float64 `json:"pfj"`
  202. Lsj float64 `json:"lsj"`
  203. Sysl float64 `json:"sysl"`
  204. Ypjx string `json:"ypjx"`
  205. Jldw string `json:"jldw"`
  206. Sccj string `json:"sccj"`
  207. Cd string `json:"cd"`
  208. } `json:"data"`
  209. }
  210. func (c *CoordinateController)QueryStock(){
  211. result, _ := service.GetDrugs()
  212. fmt.Println(result)
  213. result2, _ := service.GetProject()
  214. saveLog(result, "", "查询", "查询", "")
  215. saveLog(result2, "", "查询", "查询", "")
  216. var project ProjectStruct
  217. err := json.Unmarshal([]byte(result2), &project)
  218. if err != nil {
  219. fmt.Println("解析JSON出错:", err)
  220. return
  221. }
  222. fmt.Println(project)
  223. var drug Medicine
  224. err2 := json.Unmarshal([]byte(result), &drug)
  225. if err2 != nil {
  226. fmt.Println("解析JSON出错:", err2)
  227. return
  228. }
  229. c.ServeSuccessJSON(map[string]interface{}{
  230. "project": project,
  231. "drug": drug,
  232. })
  233. }
  234. //查询检查
  235. func (c *CoordinateController)NMGquerycheck(){
  236. }
  237. func (c *CoordinateController)NMGother(){
  238. //service.GetDeptEmp()
  239. service.GetDrugInterval()
  240. //service.GetUsage()
  241. //service.GetDrugs()
  242. //service.GetProject()
  243. }
  244. type ResultObj struct {
  245. Cbm01 int `json:"cbm01"`
  246. Vaf01List []int `json:"vaf01List"`
  247. }
  248. type Response struct {
  249. ResultObj []ResultObj `json:"resultObj"`
  250. Result bool `json:"result"`
  251. Code int `json:"code"`
  252. ResultMsg string `json:"resultMsg"`
  253. Msg string `json:"msg"`
  254. Error bool `json:"error"`
  255. Success bool `json:"success"`
  256. }
  257. type Responsexml struct {
  258. XMLName xml.Name `xml:"root"`
  259. ErrorCode int `xml:"errorcode"`
  260. ErrorMsg string `xml:"errormsg"`
  261. Data string `xml:"data"`
  262. }
  263. //获取患者信息-判断是否存在上传过的医嘱,先删除后保存当天医嘱-记账
  264. func (c *CoordinateController) NMGSettleAccount() {
  265. patient_id, _ := c.GetInt64("patient_id")
  266. record_date := c.GetString("record_date")
  267. admin_user_id, _ := c.GetInt64("admin_user_id")
  268. diagnosis_id := c.GetString("diagnosis")
  269. sick_type, _ := c.GetInt64("sick_type")
  270. reg_type, _ := c.GetInt64("p_type")
  271. org_id, _ := c.GetInt64("org_id")
  272. org_id = 10454
  273. org, _ := service.GetOrgById(org_id)
  274. patient, _ := service.GetPatientByID(org.Id, patient_id)
  275. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  276. //住院
  277. result, request := service.GetNMGHisPatientForCoordinate(0,0,2,patient.Name)
  278. //门诊
  279. result5, request5 := service.GetNMGHisPatientForCoordinate(0,0,1,patient.Name)
  280. saveLog(result, request, "住院查询", "住院查询", "")
  281. saveLog(result5, request5, "门诊查询", "门诊查询", "")
  282. var res Data
  283. if err := json.Unmarshal([]byte(result), &res); err != nil {
  284. utils.ErrorLog("解析失败:%v", err)
  285. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  286. return
  287. }
  288. var res8 Data
  289. if err := json.Unmarshal([]byte(result5), &res8); err != nil {
  290. utils.ErrorLog("解析失败:%v", err)
  291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  292. return
  293. }
  294. //优先查询今天门诊的患者,如果今天没有门诊的患者查询出住院的患者
  295. if res8.Code == 200 {
  296. var res9 Data
  297. //res9.List = append(res9.List, res.List...)
  298. res9.List = append(res9.List, res8.List...)
  299. var li ListItem
  300. for _, item := range res9.List {
  301. cure_date := strings.Split(item.Vae11, " ")
  302. if cure_date[0] == record_date && patient.Name == item.Vaa05 {
  303. li = item
  304. }
  305. }
  306. if li.Acf01 == 0 && li.Vaa07 == 0 && li.Vaa01 == 0 { //今天没有门诊患者,则查询出最后一个日期的住院患者
  307. var res10 Data
  308. //res9.List = append(res9.List, res.List...)
  309. res10.List = append(res10.List, res.List...)
  310. layout := "2006-01-02 15:04:05"
  311. var maxDate time.Time
  312. for _, item := range res10.List {
  313. currentDate, err := time.Parse(layout, item.Vae11)
  314. if err != nil {
  315. fmt.Println("Error parsing date:", err)
  316. continue
  317. }
  318. if currentDate.After(maxDate) {
  319. maxDate = currentDate
  320. }
  321. if !maxDate.IsZero() {
  322. fmt.Println("The maximum date is:", maxDate.Format(layout))
  323. } else {
  324. fmt.Println("No valid dates found")
  325. }
  326. }
  327. fmt.Println(maxDate.Format("2006-01-02 15:04:05"))
  328. for _, item := range res10.List {
  329. if item.Vae11 == maxDate.Format("2006-01-02 15:04:05") && patient.Name == item.Vaa05{
  330. li = item
  331. }
  332. }
  333. }
  334. fmt.Println(li)
  335. timeLayout := "2006-01-02"
  336. loc, _ := time.LoadLocation("Local")
  337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  338. if err != nil {
  339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  340. return
  341. }
  342. org_id := org.Id
  343. recordDateTime := theTime.Unix()
  344. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  345. if patientPrescription.ID == 0 {
  346. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  347. }
  348. departmwnt, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  349. admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  350. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  351. var prescriptions []*models.HisPrescription
  352. settle_accounts_type = 1
  353. if settle_accounts_type == 1 { //日结
  354. prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, patient_id, recordDateTime, 2)
  355. } else { //月结
  356. start_time_str := c.GetString("start_time")
  357. end_time_str := c.GetString("end_time")
  358. timeLayout := "2006-01-02"
  359. loc, _ := time.LoadLocation("Local")
  360. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  361. if err != nil {
  362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  363. return
  364. }
  365. recordStartTime := theStartTime.Unix()
  366. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  367. if err != nil {
  368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  369. return
  370. }
  371. recordEndTime := theEndTime.Unix()
  372. prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, patient_id, recordStartTime, recordEndTime)
  373. }
  374. var ids []int64
  375. for _, item := range prescriptions {
  376. ids = append(ids, item.ID)
  377. }
  378. var customs []*models.NewCustomTwo
  379. for _, item := range prescriptions {
  380. if item.Type == 1 { //药品
  381. for _, subItem := range item.HisDoctorAdviceInfo {
  382. tempTime := time.Unix(item.PreTime, 0)
  383. //timeFormat := tempTime.Format("20060102150405")
  384. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  385. cus := &models.NewCustomTwo{
  386. AdviceId: subItem.ID,
  387. ProjectId: 0,
  388. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  389. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  390. FeedetlSn: subItem.FeedetlSn,
  391. Price: fmt.Sprintf("%.2f", subItem.Price),
  392. MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  393. Type: 1,
  394. ItemId: subItem.BaseDrugLib.ZuobiaoId,
  395. StartTime: timeFormatOne,
  396. Content: subItem.AdviceName,
  397. Bby01: subItem.BaseDrugLib.Bby01,
  398. }
  399. customs = append(customs, cus)
  400. }
  401. }
  402. if item.Type == 2 { //项目
  403. for _, subItem := range item.HisPrescriptionProject {
  404. if subItem.Type == 2 {
  405. tempTime := time.Unix(item.PreTime, 0)
  406. //timeFormat := tempTime.Format("20060102150405")
  407. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  408. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  409. cus := &models.NewCustomTwo{
  410. AdviceId: 0,
  411. ProjectId: subItem.ID,
  412. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  413. Cut: fmt.Sprintf("%.4f", cnt),
  414. FeedetlSn: subItem.FeedetlSn,
  415. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  416. MedListCodg: subItem.HisProject.MedicalCode,
  417. Type: 2,
  418. ItemId: subItem.HisProject.ZuobiaoId,
  419. StartTime: timeFormatOne,
  420. Content: subItem.HisProject.ProjectName,
  421. Bby01: subItem.HisProject.Bby01,
  422. }
  423. customs = append(customs, cus)
  424. } else {
  425. tempTime := time.Unix(item.PreTime, 0)
  426. //timeFormat := tempTime.Format("20060102150405")
  427. timeFormatOne := tempTime.Format("2006-01-02 15:04:05")
  428. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  429. cus := &models.NewCustomTwo{
  430. AdviceId: 0,
  431. ProjectId: subItem.ID,
  432. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  433. Cut: fmt.Sprintf("%.4f", cnt),
  434. FeedetlSn: subItem.FeedetlSn,
  435. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  436. MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  437. Type: 3,
  438. ItemId: subItem.GoodInfo.ZuobiaoId,
  439. StartTime: timeFormatOne,
  440. Content: subItem.GoodInfo.GoodName,
  441. Bby01: subItem.GoodInfo.Bby01,
  442. }
  443. customs = append(customs, cus)
  444. }
  445. }
  446. }
  447. }
  448. var info models.UploadInfo
  449. info.Acf01 = int64(li.Acf01)
  450. info.Bce01 = admin_user_info.DoctorNumber
  451. info.Bck01 = "48"
  452. info.Vaa07 = int64(li.Vaa07)
  453. info.Vaa01 = int64(li.Vaa01)
  454. info.Vaa05 = li.Vaa05
  455. info.Bce01a = doctor_info.DoctorNumber
  456. //for _, item := range customs {
  457. // var cha models.ChargeList
  458. // cha.Bby01 = item.Bby01
  459. // cha.Vaj25 = item.Cut
  460. // cha.Bbx01 = item.ItemId
  461. // cha.Vaf21 = item.Cut
  462. // cha.Vaf22 = item.Content
  463. // cha.Vaf42 = item.StartTime
  464. // info.ChargeList = append(info.ChargeList, cha)
  465. //}
  466. for _, item := range customs {
  467. var cha models.ChargeListtwo
  468. cha.Bby01 = item.Bby01
  469. cha.Vaj25 = item.Cut
  470. info.ChargeListtwo = append(info.ChargeListtwo, cha)
  471. }
  472. var root models.Root
  473. var tradeInfo models.TradeInfo
  474. var cBM1 models.CBM1
  475. var vAF1 models.VAF1
  476. var vAO1 models.VAO1
  477. var vBQ1 models.VBQ1
  478. if li.Acf01 == 1 {
  479. tradeInfo.PatSource = 1
  480. tradeInfo.Type = 0
  481. } else {
  482. tradeInfo.PatSource = 2
  483. tradeInfo.Type = 1
  484. }
  485. tradeInfo.Detpid = departmwnt.Number
  486. tradeInfo.Empid = doctor_info.DoctorNumber
  487. tradeInfo.Empno = doctor_info.DoctorCode
  488. tradeInfo.Empname = doctor_info.UserName
  489. root.TradeInfo = tradeInfo
  490. //
  491. //
  492. //var del_ids []string
  493. //
  494. //
  495. ////信息
  496. for _, item := range prescriptions {
  497. fmt.Println("999999999")
  498. //del_ids = append(del_ids, item.Cbm01)
  499. var ie_cbm1 models.IEone
  500. ie_cbm1.CBMID = strconv.FormatInt(item.ID, 10)
  501. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  502. ie_cbm1.VAA07 = strconv.FormatInt(int64(li.Vaa07), 10)
  503. ie_cbm1.ACF01 = strconv.FormatInt(int64(li.Acf01), 10)
  504. //ie_cbm1.CBM06 = strconv.FormatInt(int64(res.List[0].Acf01), 10)
  505. if li.Acf01 == 1 {
  506. ie_cbm1.CBM06 = item.Cbm07
  507. ie_cbm1.BCK01A = "0"
  508. } else {
  509. ie_cbm1.CBM06 = "0"
  510. ie_cbm1.BCK01A =strconv.FormatInt(int64(li.Bck01A), 10) //病区id
  511. }
  512. ie_cbm1.CBM07 = item.Cbm07
  513. ie_cbm1.BCK01B = strconv.FormatInt(int64(li.Bck01B), 10)
  514. ie_cbm1.BCK01C = departmwnt.Number
  515. ie_cbm1.CBM19 = "0"
  516. cBM1.Ie = append(cBM1.Ie, ie_cbm1)
  517. }
  518. root.CBM1 = cBM1
  519. ////医嘱
  520. for _, item := range prescriptions {
  521. fmt.Println("88888888888")
  522. if item.Type == 1 {
  523. for _, subitem := range item.HisDoctorAdviceInfo {
  524. var ie_cbm1 models.IEtwo
  525. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  526. ie_cbm1.VAF04 = strconv.FormatInt(int64(li.Acf01), 10)
  527. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  528. ie_cbm1.VAF06 = strconv.FormatInt(int64(li.Vaa07), 10)
  529. ie_cbm1.BCK01A = strconv.FormatInt(int64(li.Bck01A), 10)
  530. ie_cbm1.ROWNR = strconv.FormatInt(subitem.Groupno, 10)
  531. ie_cbm1.VAF10 = "1"
  532. ie_cbm1.VAF11 = "2"
  533. ie_cbm1.BDA01 = "1" //诊疗类型
  534. ie_cbm1.BBX01 = subitem.BaseDrugLib.ZuobiaoId
  535. ie_cbm1.VAF14 = "" //检验样本类型
  536. ie_cbm1.VAF15 = "" //检验样本类型
  537. ie_cbm1.BBY01 = "" //药品规格id或材料规格id
  538. if li.Acf01 == 1 {
  539. ie_cbm1.VAF17 = strconv.FormatInt(int64(subitem.Day), 10) //药品规格id或材料规格id
  540. } else {
  541. ie_cbm1.VAF17 = "0" //药品规格id或材料规格id
  542. }
  543. ie_cbm1.VAF18 = fmt.Sprintf("%.2f", subitem.SingleDose) //药品规格id或材料规格id
  544. ie_cbm1.VAF19 = fmt.Sprintf("%.2f", subitem.SingleDose) + " " + subitem.SingleDoseUnit //药品规格id或材料规格id
  545. ie_cbm1.VAF20 = fmt.Sprintf("%.2f", subitem.SingleDose)
  546. ie_cbm1.VAF21 = fmt.Sprintf("%.2f", subitem.PrescribingNumber)
  547. ie_cbm1.VAF22 = subitem.AdviceName
  548. ie_cbm1.Crypt = "0"
  549. ie_cbm1.VAF23 = ""
  550. ie_cbm1.BCK01B = subitem.BaseDrugLib.Bck01b
  551. ie_cbm1.VAF26 = subitem.ExecutionFrequency
  552. ie_cbm1.VAF27 = "1"
  553. ie_cbm1.VAF28 = ""
  554. ie_cbm1.VAF29 = ""
  555. ie_cbm1.VAF30 = ""
  556. ie_cbm1.VAF31 = "0"
  557. ie_cbm1.VAF32 = "0" //todo
  558. ie_cbm1.VAF33 = "0"
  559. ie_cbm1.VAF34 = "0"
  560. ie_cbm1.VAF35 = "0"
  561. tempTime1 := time.Unix(subitem.StartTime, 0)
  562. timeFormatOne := tempTime1.Format("2006-01-02 15:04:05")
  563. ie_cbm1.VAF36 = timeFormatOne
  564. ie_cbm1.VAF37 = "1899-12-30"
  565. doctor_info, _ := service.GetAdminUserInfoByID(org_id, item.Creator)
  566. ie_cbm1.BCK01C = departmwnt.Number
  567. ie_cbm1.BCE02A = doctor_info.DoctorNumber
  568. ie_cbm1.BCE03A = doctor_info.UserName
  569. ie_cbm1.BCE03B = ""
  570. ie_cbm1.VAF53 = "-1"
  571. ie_cbm1.VAF55 = subitem.Remark
  572. ie_cbm1.BCK01D = departmwnt.Number
  573. ie_cbm1.VAF58 = "0"
  574. ie_cbm1.VAF59 = strconv.FormatInt(int64(subitem.Groupno), 10)
  575. ie_cbm1.VAF60 = ""
  576. ie_cbm1.VAF61 = "1"
  577. ie_cbm1.VAF62 = "0"
  578. ie_cbm1.LSign = "0"
  579. ie_cbm1.BDA01A = ie_cbm1.BDA01
  580. ie_cbm1.LRoute = "0"
  581. ie_cbm1.BCE01A = doctor_info.DoctorNumber
  582. ie_cbm1.BCE01B = "0"
  583. ie_cbm1.VAF01B = "0"
  584. ie_cbm1.VCO01 = "0"
  585. ie_cbm1.BCE01H = "0"
  586. ie_cbm1.BCE03H = ""
  587. ie_cbm1.BIW02 = ""
  588. ie_cbm1.RCurrent = "0"
  589. ie_cbm1.FCheck = "0"
  590. ie_cbm1.UnameA = ""
  591. ie_cbm1.VEH02 = ""
  592. vAF1.Ie = append(vAF1.Ie, ie_cbm1)
  593. }
  594. //每种药品下的给药途径
  595. for _, subitem := range item.HisDoctorAdviceInfo {
  596. way, _ := service.GetDrugwayDicByName(subitem.DeliveryWay, c.GetAdminUserInfo().CurrentOrgId)
  597. var ie_cbm1 models.IEtwo
  598. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  599. ie_cbm1.VAF04 = strconv.FormatInt(int64(li.Acf01), 10)
  600. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  601. ie_cbm1.VAF06 = strconv.FormatInt(int64(li.Vaa07), 10)
  602. ie_cbm1.BCK01A = strconv.FormatInt(int64(li.Bck01A), 10)
  603. ie_cbm1.ROWNR = "0"
  604. ie_cbm1.VAF10 = "1"
  605. ie_cbm1.VAF11 = "2"
  606. ie_cbm1.BDA01 = "T" //诊疗类型
  607. ie_cbm1.BBX01 = way.Code
  608. ie_cbm1.VAF14 = "" //检验样本类型
  609. ie_cbm1.VAF15 = "" //检验样本类型
  610. ie_cbm1.BBY01 = "" //药品规格id或材料规格id
  611. if li.Acf01 == 1 {
  612. ie_cbm1.VAF17 = strconv.FormatInt(int64(subitem.Day), 10) //药品规格id或材料规格id
  613. } else {
  614. ie_cbm1.VAF17 = "0" //药品规格id或材料规格id
  615. }
  616. ie_cbm1.VAF18 = fmt.Sprintf("%.2f", subitem.SingleDose) //药品规格id或材料规格id
  617. ie_cbm1.VAF19 = fmt.Sprintf("%.2f", subitem.SingleDose) + " " + subitem.SingleDoseUnit //药品规格id或材料规格id
  618. ie_cbm1.VAF20 = fmt.Sprintf("%.2f", subitem.SingleDose)
  619. //ie_cbm1.VAF21 = fmt.Sprintf("%.2f",subitem.PrescribingNumber)
  620. //ie_cbm1.VAF18 = "" //药品规格id或材料规格id
  621. //ie_cbm1.VAF19 = ""
  622. //ie_cbm1.VAF20 = ""
  623. ie_cbm1.VAF21 = "1"
  624. ie_cbm1.VAF22 = way.Name
  625. ie_cbm1.Crypt = "0"
  626. ie_cbm1.VAF23 = ""
  627. ie_cbm1.BCK01B = subitem.BaseDrugLib.Bck01b
  628. ie_cbm1.VAF26 = ""
  629. ie_cbm1.VAF27 = ""
  630. ie_cbm1.VAF28 = ""
  631. ie_cbm1.VAF29 = ""
  632. ie_cbm1.BCK01C = departmwnt.Number
  633. ie_cbm1.VAF30 = ""
  634. ie_cbm1.VAF31 = "0"
  635. ie_cbm1.VAF32 = "1" //todo
  636. ie_cbm1.VAF33 = "0"
  637. ie_cbm1.VAF34 = "0"
  638. ie_cbm1.VAF35 = "0"
  639. tempTime1 := time.Unix(subitem.StartTime, 0)
  640. timeFormatOne := tempTime1.Format("2006-01-02 15:04:05")
  641. ie_cbm1.VAF36 = timeFormatOne
  642. ie_cbm1.VAF37 = "1899-12-30"
  643. doctor_info, _ := service.GetAdminUserInfoByID(org_id, item.Creator)
  644. ie_cbm1.BCE02A = doctor_info.DoctorNumber
  645. ie_cbm1.BCE03A = doctor_info.UserName
  646. ie_cbm1.BCE03B = ""
  647. ie_cbm1.VAF53 = "-1"
  648. ie_cbm1.VAF55 = subitem.Remark
  649. ie_cbm1.BCK01D = departmwnt.Number
  650. ie_cbm1.VAF58 = "0"
  651. ie_cbm1.VAF59 = strconv.FormatInt(int64(subitem.Groupno), 10)
  652. ie_cbm1.VAF60 = ""
  653. ie_cbm1.VAF61 = "1"
  654. ie_cbm1.VAF62 = "0"
  655. ie_cbm1.LSign = "0"
  656. ie_cbm1.BDA01A = ie_cbm1.BDA01
  657. ie_cbm1.LRoute = "0"
  658. ie_cbm1.BCE01A = doctor_info.DoctorNumber
  659. ie_cbm1.BCE01B = "0"
  660. ie_cbm1.VAF01B = "0"
  661. ie_cbm1.VCO01 = "0"
  662. ie_cbm1.BCE01H = "0"
  663. ie_cbm1.BCE03H = ""
  664. ie_cbm1.BIW02 = ""
  665. ie_cbm1.RCurrent = "0"
  666. ie_cbm1.FCheck = "0"
  667. ie_cbm1.UnameA = ""
  668. ie_cbm1.VEH02 = ""
  669. vAF1.Ie = append(vAF1.Ie, ie_cbm1)
  670. }
  671. } else if item.Type == 2 {
  672. for index, subitem := range item.HisPrescriptionProject {
  673. if subitem.Type == 2 {
  674. if subitem.HisProject.CostClassify != 3 {
  675. var ie_cbm1 models.IEtwo
  676. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  677. ie_cbm1.VAF04 = strconv.FormatInt(int64(li.Acf01), 10)
  678. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  679. ie_cbm1.VAF06 = strconv.FormatInt(int64(li.Vaa07), 10)
  680. ie_cbm1.BCK01A = strconv.FormatInt(int64(li.Bck01A), 10)
  681. ie_cbm1.ROWNR = strconv.FormatInt(int64(index), 10)
  682. ie_cbm1.VAF10 = "1"
  683. ie_cbm1.VAF11 = "2"
  684. ie_cbm1.BDA01 = "T" //诊疗类型
  685. ie_cbm1.BBX01 = subitem.HisProject.ZuobiaoId
  686. ie_cbm1.VAF14 = "" //检验样本类型
  687. ie_cbm1.VAF15 = "" //检验样本类型
  688. ie_cbm1.BBY01 = "" //药品规格id或材料规格id
  689. if li.Acf01 == 1 {
  690. ie_cbm1.VAF17 = subitem.Day //药品规格id或材料规格id
  691. } else {
  692. ie_cbm1.VAF17 = "0" //药品规格id或材料规格idn
  693. }
  694. ie_cbm1.VAF18 = subitem.SingleDose //药品规格id或材料规格id
  695. ie_cbm1.VAF19 = subitem.SingleDose + " " + subitem.Unit //药品规格id或材料规格id
  696. ie_cbm1.VAF20 = subitem.SingleDose
  697. ie_cbm1.VAF21 = subitem.Count
  698. ie_cbm1.VAF22 = subitem.HisProject.ProjectName
  699. ie_cbm1.Crypt = "0"
  700. ie_cbm1.VAF23 = ""
  701. ie_cbm1.BCK01B = subitem.HisProject.Bck01b
  702. ie_cbm1.VAF26 = subitem.ExecutionFrequency
  703. ie_cbm1.VAF27 = "1"
  704. ie_cbm1.VAF28 = ""
  705. ie_cbm1.VAF29 = ""
  706. ie_cbm1.BCK01C = departmwnt.Number
  707. ie_cbm1.VAF30 = ""
  708. ie_cbm1.VAF31 = "0"
  709. ie_cbm1.VAF32 = "0" //todo
  710. ie_cbm1.VAF33 = "0"
  711. ie_cbm1.VAF34 = "0"
  712. ie_cbm1.VAF35 = "0"
  713. tempTime1 := time.Unix(subitem.StartTime, 0)
  714. timeFormatOne := tempTime1.Format("2006-01-02 15:04:05")
  715. ie_cbm1.VAF36 = timeFormatOne
  716. ie_cbm1.VAF37 = "1899-12-30"
  717. doctor_info, _ := service.GetAdminUserInfoByID(org_id, item.Creator)
  718. ie_cbm1.BCE02A = doctor_info.DoctorNumber
  719. ie_cbm1.BCE03A = doctor_info.UserName
  720. ie_cbm1.BCE03B = ""
  721. ie_cbm1.VAF53 = "-1"
  722. ie_cbm1.VAF55 = subitem.Remark
  723. ie_cbm1.BCK01D = departmwnt.Number
  724. ie_cbm1.VAF58 = "0"
  725. ie_cbm1.VAF59 = strconv.FormatInt(int64(index), 10)
  726. ie_cbm1.VAF60 = ""
  727. ie_cbm1.VAF61 = "1"
  728. ie_cbm1.VAF62 = "0"
  729. ie_cbm1.LSign = "0"
  730. ie_cbm1.BDA01A = "" //诊疗类型
  731. ie_cbm1.LRoute = "0"
  732. ie_cbm1.BCE01A = doctor_info.DoctorNumber
  733. //ie_cbm1.BCE01A = doctor_info.UserName
  734. ie_cbm1.BCE01B = "0"
  735. ie_cbm1.VAF01B = "0"
  736. ie_cbm1.VCO01 = "0"
  737. ie_cbm1.BCE01H = "0"
  738. ie_cbm1.BCE03H = ""
  739. ie_cbm1.BIW02 = ""
  740. ie_cbm1.RCurrent = "0"
  741. ie_cbm1.FCheck = "0"
  742. ie_cbm1.UnameA = ""
  743. ie_cbm1.VEH02 = ""
  744. vAF1.Ie = append(vAF1.Ie, ie_cbm1)
  745. }
  746. if subitem.HisProject.CostClassify == 3 {
  747. var ie_cbm1 models.IEtwo
  748. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  749. ie_cbm1.VAF04 = strconv.FormatInt(int64(li.Acf01), 10)
  750. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  751. ie_cbm1.VAF06 = strconv.FormatInt(int64(li.Vaa07), 10)
  752. ie_cbm1.BCK01A = strconv.FormatInt(int64(li.Bck01A), 10)
  753. ie_cbm1.ROWNR = strconv.FormatInt(int64(index), 10)
  754. ie_cbm1.VAF10 = "1"
  755. ie_cbm1.VAF11 = "2"
  756. ie_cbm1.BDA01 = "L" //诊疗类型
  757. ie_cbm1.BBX01 = subitem.HisProject.ZuobiaoId
  758. ie_cbm1.VAF14 = "" //检验样本类型
  759. ie_cbm1.VAF15 = "" //检验样本类型
  760. ie_cbm1.BBY01 = "" //药品规格id或材料规格id
  761. if li.Acf01 == 1 {
  762. ie_cbm1.VAF17 = subitem.Day //药品规格id或材料规格id
  763. } else {
  764. ie_cbm1.VAF17 = "0" //药品规格id或材料规格idn
  765. }
  766. ie_cbm1.VAF18 = subitem.SingleDose //药品规格id或材料规格id
  767. ie_cbm1.VAF19 = subitem.SingleDose + " " + subitem.Unit //药品规格id或材料规格id
  768. ie_cbm1.VAF20 = subitem.SingleDose
  769. ie_cbm1.VAF21 = subitem.Count
  770. ie_cbm1.VAF22 = subitem.HisProject.ProjectName
  771. ie_cbm1.Crypt = "0"
  772. ie_cbm1.VAF23 = ""
  773. ie_cbm1.BCK01B = subitem.HisProject.Bck01b
  774. ie_cbm1.VAF26 = subitem.ExecutionFrequency
  775. ie_cbm1.VAF27 = "1"
  776. ie_cbm1.VAF28 = ""
  777. ie_cbm1.VAF29 = ""
  778. ie_cbm1.BCK01C = departmwnt.Number
  779. ie_cbm1.VAF30 = ""
  780. ie_cbm1.VAF31 = "0"
  781. ie_cbm1.VAF32 = "0" //todo
  782. ie_cbm1.VAF33 = "0"
  783. ie_cbm1.VAF34 = "0"
  784. ie_cbm1.VAF35 = "0"
  785. tempTime1 := time.Unix(subitem.StartTime, 0)
  786. timeFormatOne := tempTime1.Format("2006-01-02 15:04:05")
  787. ie_cbm1.VAF36 = timeFormatOne
  788. ie_cbm1.VAF37 = "1899-12-30"
  789. doctor_info, _ := service.GetAdminUserInfoByID(org_id, item.Creator)
  790. ie_cbm1.BCE02A = doctor_info.DoctorNumber
  791. ie_cbm1.BCE03A = doctor_info.UserName
  792. ie_cbm1.BCE03B = ""
  793. ie_cbm1.VAF53 = "-1"
  794. ie_cbm1.VAF55 = subitem.Remark
  795. ie_cbm1.BCK01D = departmwnt.Number
  796. ie_cbm1.VAF58 = "0"
  797. ie_cbm1.VAF59 = strconv.FormatInt(int64(index), 10)
  798. ie_cbm1.VAF60 = ""
  799. ie_cbm1.VAF61 = "1"
  800. ie_cbm1.VAF62 = "0"
  801. ie_cbm1.LSign = "0"
  802. ie_cbm1.BDA01A = "" //诊疗类型
  803. ie_cbm1.LRoute = "0"
  804. ie_cbm1.BCE01A = doctor_info.DoctorNumber
  805. //ie_cbm1.BCE01A = doctor_info.UserName
  806. ie_cbm1.BCE01B = "0"
  807. ie_cbm1.VAF01B = "0"
  808. ie_cbm1.VCO01 = "0"
  809. ie_cbm1.BCE01H = "0"
  810. ie_cbm1.BCE03H = ""
  811. ie_cbm1.BIW02 = ""
  812. ie_cbm1.RCurrent = "0"
  813. ie_cbm1.FCheck = "0"
  814. ie_cbm1.UnameA = ""
  815. ie_cbm1.VEH02 = ""
  816. vAF1.Ie = append(vAF1.Ie, ie_cbm1)
  817. }
  818. } else if subitem.Type == 3 {
  819. var ie_cbm1 models.IEtwo
  820. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  821. ie_cbm1.VAF04 = strconv.FormatInt(int64(li.Acf01), 10)
  822. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  823. ie_cbm1.VAF06 = strconv.FormatInt(int64(li.Vaa07), 10)
  824. ie_cbm1.BCK01A = strconv.FormatInt(int64(li.Bck01A), 10)
  825. ie_cbm1.ROWNR = strconv.FormatInt(int64(index), 10)
  826. ie_cbm1.VAF10 = "1"
  827. ie_cbm1.VAF11 = "2"
  828. ie_cbm1.BDA01 = "4" //诊疗类型
  829. ie_cbm1.BBX01 = subitem.GoodInfo.ZuobiaoId
  830. ie_cbm1.VAF14 = "" //检验样本类型
  831. ie_cbm1.VAF15 = "" //检验样本类型
  832. ie_cbm1.BBY01 = "" //药品规格id或材料规格id
  833. if li.Acf01 == 1 {
  834. ie_cbm1.VAF17 = subitem.Day //药品规格id或材料规格id
  835. } else {
  836. ie_cbm1.VAF17 = "0" //药品规格id或材料规格id
  837. }
  838. ie_cbm1.VAF18 = subitem.SingleDose //药品规格id或材料规格id
  839. ie_cbm1.VAF19 = subitem.SingleDose + " " + subitem.Unit //药品规格id或材料规格id
  840. ie_cbm1.VAF20 = subitem.SingleDose
  841. ie_cbm1.VAF21 = subitem.Count
  842. ie_cbm1.BCK01C = departmwnt.Number
  843. ie_cbm1.VAF22 = subitem.GoodInfo.GoodName
  844. ie_cbm1.Crypt = "0"
  845. ie_cbm1.VAF23 = ""
  846. ie_cbm1.BCK01B = subitem.GoodInfo.Bck01b
  847. ie_cbm1.VAF26 = ""
  848. ie_cbm1.VAF27 = ""
  849. ie_cbm1.VAF28 = ""
  850. ie_cbm1.VAF29 = ""
  851. ie_cbm1.VAF30 = ""
  852. ie_cbm1.VAF31 = "0"
  853. ie_cbm1.VAF32 = "0" //todo
  854. ie_cbm1.VAF33 = "0"
  855. ie_cbm1.VAF34 = "0"
  856. ie_cbm1.VAF35 = "0"
  857. tempTime1 := time.Unix(subitem.StartTime, 0)
  858. timeFormatOne := tempTime1.Format("2006-01-02 15:04:05")
  859. ie_cbm1.VAF36 = timeFormatOne
  860. ie_cbm1.VAF37 = "1899-12-30"
  861. doctor_info, _ := service.GetAdminUserInfoByID(org_id, item.Creator)
  862. ie_cbm1.BCE02A = doctor_info.DoctorNumber
  863. ie_cbm1.BCE03A = doctor_info.UserName
  864. ie_cbm1.BCE03B = ""
  865. ie_cbm1.BCK01C = departmwnt.Number
  866. ie_cbm1.VAF53 = "-1"
  867. ie_cbm1.VAF55 = subitem.Remark
  868. ie_cbm1.BCK01D = departmwnt.Number
  869. ie_cbm1.VAF58 = "0"
  870. ie_cbm1.VAF59 = strconv.FormatInt(int64(index), 10)
  871. ie_cbm1.VAF60 = ""
  872. ie_cbm1.VAF61 = "1"
  873. ie_cbm1.VAF62 = "0"
  874. ie_cbm1.LSign = "0"
  875. ie_cbm1.BDA01A = "" //诊疗类型
  876. ie_cbm1.LRoute = "0"
  877. ie_cbm1.BCE01A = doctor_info.DoctorNumber
  878. ie_cbm1.BCE01B = "0"
  879. ie_cbm1.VAF01B = "0"
  880. ie_cbm1.VCO01 = "0"
  881. ie_cbm1.BCE01H = "0"
  882. ie_cbm1.BCE03H = ""
  883. ie_cbm1.BIW02 = ""
  884. ie_cbm1.RCurrent = "0"
  885. ie_cbm1.FCheck = "0"
  886. ie_cbm1.UnameA = ""
  887. ie_cbm1.VEH02 = ""
  888. vAF1.Ie = append(vAF1.Ie, ie_cbm1)
  889. }
  890. }
  891. }
  892. }
  893. root.VAF1 = vAF1
  894. for _, item := range prescriptions {
  895. dias := strings.Split(patientPrescription.Diagnosis, ",")
  896. //service.get
  897. //诊断
  898. for index, subitem := range dias {
  899. diagnosisConfig, _ := service.FindDiagnoseByIdtwo(subitem)
  900. if index == 0 {
  901. var ie_cbm1 models.IEthree
  902. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  903. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  904. ie_cbm1.VAA07 = strconv.FormatInt(int64(li.Vaa07), 10)
  905. ie_cbm1.ACF01 = strconv.FormatInt(int64(li.Acf01), 10)
  906. ie_cbm1.VAO06 = strconv.FormatInt(int64(index+1), 10)
  907. ie_cbm1.VAO07 = "1"
  908. ie_cbm1.VAO10 = "0"
  909. ie_cbm1.VAO11 = "6"
  910. ie_cbm1.BAK01A = "31537"
  911. ie_cbm1.CAM01 = diagnosisConfig.CountryCode
  912. ie_cbm1.VAO15 = diagnosisConfig.ClassName
  913. ie_cbm1.VAO18 = "0"
  914. ie_cbm1.VAO22 = "1"
  915. ie_cbm1.IAA01 = ""
  916. ie_cbm1.IAD03 = ""
  917. ie_cbm1.BAK01B = ""
  918. ie_cbm1.VAO26 = ""
  919. ie_cbm1.IAD04 = ""
  920. ie_cbm1.IAD01 = ""
  921. ie_cbm1.VAO25 = "1"
  922. ie_cbm1.VAO35 = ""
  923. vAO1.Ie = append(vAO1.Ie, ie_cbm1)
  924. } else {
  925. var ie_cbm1 models.IEthree
  926. ie_cbm1.CBMID = strconv.FormatInt(int64(item.ID), 10)
  927. ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  928. ie_cbm1.VAA07 = strconv.FormatInt(int64(li.Vaa07), 10)
  929. ie_cbm1.ACF01 = strconv.FormatInt(int64(li.Acf01), 10)
  930. ie_cbm1.VAO06 = strconv.FormatInt(int64(index+1), 10)
  931. ie_cbm1.VAO07 = "1"
  932. ie_cbm1.VAO10 = "0"
  933. ie_cbm1.VAO11 = "6"
  934. ie_cbm1.BAK01A = "31537"
  935. ie_cbm1.CAM01 = diagnosisConfig.CountryCode
  936. ie_cbm1.VAO15 = diagnosisConfig.ClassName
  937. ie_cbm1.VAO18 = "0"
  938. ie_cbm1.VAO22 = "1"
  939. ie_cbm1.IAA01 = ""
  940. ie_cbm1.IAD03 = ""
  941. ie_cbm1.BAK01B = ""
  942. ie_cbm1.VAO26 = ""
  943. ie_cbm1.IAD04 = ""
  944. ie_cbm1.IAD01 = ""
  945. ie_cbm1.VAO25 = "2"
  946. ie_cbm1.VAO35 = ""
  947. vAO1.Ie = append(vAO1.Ie, ie_cbm1)
  948. }
  949. }
  950. }
  951. ////
  952. //////检验检查医嘱
  953. //for _, item := range prescriptions{
  954. // fmt.Println("6666666666666")
  955. // if item.Type == 2{
  956. // for _, subitem := range item.HisPrescriptionProject {
  957. // if subitem.Type == 2{
  958. // if subitem.HisProject.CostClassify == 3 {
  959. // var ie_cbm1 models.IEfour
  960. // ie_cbm1.VBQ01 = strconv.FormatInt(int64(item.ID), 10)
  961. // ie_cbm1.VAA01 = strconv.FormatInt(int64(li.Vaa01), 10)
  962. // ie_cbm1.VAA07 = strconv.FormatInt(int64(li.Vaa07), 10)
  963. // ie_cbm1.ACF01 = strconv.FormatInt(int64(li.Acf01), 10)
  964. // ie_cbm1.VAP01 = "0"
  965. // ie_cbm1.VBQ07 = "0"
  966. // ie_cbm1.BCK01A = departmwnt.Number
  967. // ie_cbm1.BCK01B= "0"
  968. // ie_cbm1.BCE03A= ""
  969. // ie_cbm1.BCE01A= "0"
  970. // ie_cbm1.VBQ27= subitem.HisProject.ProjectName
  971. // ie_cbm1.VBQ28= patientPrescription.Diagnosis
  972. // ie_cbm1.VBQ29= ""
  973. // ie_cbm1.VBQ30= ""
  974. // vBQ1.Ie = append(vBQ1.Ie, ie_cbm1)
  975. // }
  976. //
  977. // }
  978. //
  979. // }
  980. // }
  981. //}
  982. root.VAO1 = vAO1
  983. root.VBQ1 = vBQ1
  984. zuobiao, _ := service.Getzuobiao(c.GetAdminUserInfo().CurrentOrgId, patient_id, recordDateTime)
  985. //idss := strings.Split(zuobiao.AdiviceIds,",")
  986. is_success := true
  987. failed_mag := ""
  988. //查询出对应的坐标系统医嘱id,先进行删除操作,在创建医嘱。如果没有医嘱id,则直接创建医嘱
  989. if zuobiao.ID > 0 {
  990. cbm01s := strings.Split(zuobiao.Cbm01, ",")
  991. fmt.Println(cbm01s)
  992. for _, iditem := range cbm01s {
  993. fmt.Println(iditem)
  994. var root2 models.Root2
  995. var tradeInfo2 models.TradeInfo
  996. if li.Acf01 == 1 {
  997. tradeInfo2.PatSource = 1
  998. tradeInfo2.Type = 0
  999. } else {
  1000. tradeInfo2.PatSource = 2
  1001. tradeInfo2.Type = 1
  1002. }
  1003. tradeInfo2.Detpid = departmwnt.Number
  1004. tradeInfo2.Empid = doctor_info.DoctorNumber
  1005. tradeInfo2.Empno = doctor_info.DoctorCode
  1006. tradeInfo2.Empname = doctor_info.UserName
  1007. var vaf01 models.VAF10
  1008. var ie1111 models.IEfive
  1009. ie1111.VAF01 = iditem
  1010. vaf01.Ie = append(vaf01.Ie, ie1111)
  1011. root2.TradeInfo = tradeInfo2
  1012. root2.VAF1 = vaf01
  1013. xmlStr2, err := xml.MarshalIndent(root2, "", " ")
  1014. if err != nil {
  1015. fmt.Println("转换为XML时发生错误:", err)
  1016. return
  1017. }
  1018. result1, log := service.CancleNMGPrescriptionForCoordinatetwo("0002", string(xmlStr2))
  1019. fmt.Println(string(xmlStr2))
  1020. fmt.Println(result1)
  1021. fmt.Println(log)
  1022. saveLog(result1, log, "删除明细", "删除明细", org.OrgName)
  1023. var res8 Responsexml
  1024. if err = xml.Unmarshal([]byte(result1), &res8); err != nil {
  1025. fmt.Println(err)
  1026. return
  1027. }
  1028. if res8.ErrorCode != 0 {
  1029. is_success = false
  1030. failed_mag = res8.ErrorMsg
  1031. }
  1032. }
  1033. }
  1034. if is_success {
  1035. xmlStr, err := xml.MarshalIndent(root, "", " ")
  1036. if err != nil {
  1037. fmt.Println("转换为XML时发生错误:", err)
  1038. return
  1039. }
  1040. //上传医嘱版本2
  1041. result3, request3 := service.UploadNMGPrescriptionForCoordinatetwo("0001", string(xmlStr))
  1042. fmt.Println(string(xmlStr))
  1043. saveLog(result3, request3, "上传明细", "上传明细", org.OrgName)
  1044. var res3 Responsexml
  1045. if err = xml.Unmarshal([]byte(result3), &res3); err != nil {
  1046. fmt.Println(err)
  1047. }
  1048. fmt.Println(res3)
  1049. if res3.ErrorCode == 0 {
  1050. var zuobiao_advice models.HisZuobiaoAdvice
  1051. zuobiao_advice.Status = 1
  1052. zuobiao_advice.RecordDate = recordDateTime
  1053. zuobiao_advice.PatientId = patient_id
  1054. zuobiao_advice.Cbm01 = res3.Data
  1055. zuobiao_advice.Ctime = time.Now().Unix()
  1056. zuobiao_advice.Mtime = time.Now().Unix()
  1057. zuobiao_advice.UserOrgId = c.GetAdminUserInfo().CurrentOrgId
  1058. service.Createzuobiao(&zuobiao_advice)
  1059. if li.Acf01 != 1{
  1060. //记账
  1061. result2, request2 := service.NMGSettleForCoordinate(info)
  1062. saveLog(result2, request2, "记账", "记账", org.OrgName)
  1063. var res2 ResultUpload
  1064. if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  1065. utils.ErrorLog("解析失败:%v", err)
  1066. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1067. return
  1068. }
  1069. }
  1070. timestamp := time.Now().Unix()
  1071. tempTime := time.Unix(timestamp, 0)
  1072. timeFormat := tempTime.Format("20060102150405")
  1073. chrgBchno := rand.Intn(100000) + 10000
  1074. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  1075. his := models.VMHisPatient{
  1076. Name: patient.Name,
  1077. Gender: patient.Gender,
  1078. Birthday: patient.Birthday,
  1079. MedicalTreatmentType: 0,
  1080. IdType: 1,
  1081. IdCardNo: patient.IdCardNo,
  1082. BalanceAccountsType: 1,
  1083. MedicalInsuranceNumber: "",
  1084. RegisterType: 0,
  1085. RegisterCost: 0,
  1086. TreatmentCost: 0,
  1087. Status: 1,
  1088. Ctime: time.Now().Unix(),
  1089. Mtime: time.Now().Unix(),
  1090. PsnNo: strconv.FormatInt(int64(li.Vaa01), 10),
  1091. PsnCertType: "",
  1092. Certno: patient.IdCardNo,
  1093. PsnName: patient.Name,
  1094. Gend: "",
  1095. Naty: "",
  1096. Brdy: "",
  1097. Age: 0,
  1098. Iinfo: "",
  1099. Idetinfo: "",
  1100. PatientId: patient.ID,
  1101. RecordDate: theTime.Unix(),
  1102. UserOrgId: org_id,
  1103. AdminUserId: admin_user_id,
  1104. IsReturn: 1,
  1105. Doctor: patientPrescription.DoctorId,
  1106. Departments: patientPrescription.Departments,
  1107. IptOtpNo: ipt_otp_no,
  1108. Number: strconv.FormatInt(int64(li.Vaa07), 10),
  1109. PhoneNumber: patient.Phone,
  1110. }
  1111. service.UpdateHisPatientStatusten(&his)
  1112. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  1113. tm := time.Unix(time.Now().Unix(), 0)
  1114. order := &models.HisOrder{
  1115. PsnNo: his.PsnNo,
  1116. UserOrgId: org_id,
  1117. HisPatientId: his.ID,
  1118. PatientId: patient_id,
  1119. SettleAccountsDate: recordDateTime,
  1120. Ctime: time.Now().Unix(),
  1121. Mtime: time.Now().Unix(),
  1122. Status: 1,
  1123. OrderStatus: 1,
  1124. MdtrtId: strconv.FormatInt(int64(li.Vaa07), 10),
  1125. Number: strconv.FormatInt(int64(li.Vaa07), 10),
  1126. SetlId: "",
  1127. MedfeeSumamt: 0,
  1128. MedType: strconv.Itoa(int(reg_type)),
  1129. SettleEndTime: 0,
  1130. SettleStartTime: 0,
  1131. SettleType: settle_accounts_type,
  1132. Diagnosis: diagnosis_id,
  1133. PType: int64(li.Acf01),
  1134. SetlTime: tm.Format("2006-01-02 15:04:05"),
  1135. }
  1136. err = service.CreateOrder(order)
  1137. if err != nil {
  1138. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1139. return
  1140. }
  1141. for _, item := range customs {
  1142. var advice_id int64 = 0
  1143. var project_id int64 = 0
  1144. //var item_id int64 = 0
  1145. var types int64 = 0
  1146. if item.Type == 1 {
  1147. advice_id = item.AdviceId
  1148. project_id = 0
  1149. //item_id = 0.
  1150. } else if item.Type == 2 {
  1151. advice_id = 0
  1152. //item_id = 0
  1153. project_id = item.ProjectId
  1154. }
  1155. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1156. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1157. pric, _ := strconv.ParseFloat(item.Price, 32)
  1158. info := &models.HisOrderInfo{
  1159. OrderNumber: order.Number,
  1160. UploadDate: time.Now().Unix(),
  1161. AdviceId: advice_id,
  1162. DetItemFeeSumamt: detItemFeeSumamt,
  1163. Cnt: cut,
  1164. Pric: pric,
  1165. PatientId: patient_id,
  1166. Status: 1,
  1167. Mtime: time.Now().Unix(),
  1168. Ctime: time.Now().Unix(),
  1169. UserOrgId: org_id,
  1170. HisPatientId: his.ID,
  1171. OrderId: order.ID,
  1172. ProjectId: project_id,
  1173. Type: types,
  1174. //ItemId: item_id,
  1175. }
  1176. service.CreateOrderInfo(info)
  1177. }
  1178. his.Diagnosis = diagnosis_id
  1179. his.SickType = sick_type
  1180. his.RegisterType = reg_type
  1181. his.MedicalTreatmentType = reg_type
  1182. service.UpdataHisPateintTwo(&his)
  1183. err = service.UpDatePrescriptionNumber(org_id, ids, strconv.FormatInt(int64(chrgBchno), 10))
  1184. err = service.UpDateHisPrescriptionInfoNumbertwo(org_id, patient_id, strconv.FormatInt(int64(chrgBchno), 10), recordDateTime, his.ID)
  1185. err = service.UpdataOrderStatusThreef(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  1186. c.ServeSuccessJSON(map[string]interface{}{
  1187. "msg": "成功",
  1188. })
  1189. } else {
  1190. c.ServeSuccessJSON(map[string]interface{}{
  1191. "failed_code": -10,
  1192. "msg": res3.ErrorMsg,
  1193. })
  1194. }
  1195. } else {
  1196. c.ServeSuccessJSON(map[string]interface{}{
  1197. "failed_code": -10,
  1198. "msg": failed_mag,
  1199. })
  1200. }
  1201. }else{
  1202. c.ServeSuccessJSON(map[string]interface{}{
  1203. "failed_code": -10,
  1204. "msg": res.Msg,
  1205. })
  1206. }
  1207. }
  1208. func (c *CoordinateController)NMGCancelSettleAccount(){
  1209. order_id, _ := c.GetInt64("order_id")
  1210. record_date := c.GetString("record_date")
  1211. order, _ := service.GetHisOrderByID(order_id)
  1212. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  1213. if order.ID == 0 {
  1214. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  1215. return
  1216. }
  1217. //住院
  1218. result, request := service.GetNMGHisPatientForCoordinate(0,0,2,patient.Name)
  1219. //门诊
  1220. result5, request5 := service.GetNMGHisPatientForCoordinate(0,0,1,patient.Name)
  1221. saveLog(result, request, "住院查询", "住院查询", "")
  1222. saveLog(result5, request5, "门诊查询", "门诊查询", "")
  1223. var res Data
  1224. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1225. utils.ErrorLog("解析失败:%v", err)
  1226. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1227. return
  1228. }
  1229. var res8 Data
  1230. if err := json.Unmarshal([]byte(result5), &res8); err != nil {
  1231. utils.ErrorLog("解析失败:%v", err)
  1232. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1233. return
  1234. }
  1235. if res.Code == 200 || res8.Code == 200 {
  1236. var res9 Data
  1237. res9.List = append(res9.List, res.List...)
  1238. res9.List = append(res9.List, res8.List...)
  1239. var li ListItem
  1240. for _, item := range res9.List {
  1241. cure_date := strings.Split(item.Vae11, " ")
  1242. if cure_date[0] == record_date && patient.Name == item.Vaa05 {
  1243. li = item
  1244. }
  1245. }
  1246. if li.Acf01 == 0 && li.Vaa07 == 0 && li.Vaa01 == 0 {
  1247. c.ServeSuccessJSON(map[string]interface{}{
  1248. "failed_code": -10,
  1249. "msg": "患者今天尚未挂号,请先挂号进行记账操作",
  1250. })
  1251. return
  1252. }
  1253. if li.Acf01 == 1 {
  1254. err := service.UpdataOrderStatustwo(order_id, order.Number, c.GetAdminUserInfo().CurrentOrgId)
  1255. if err == nil {
  1256. c.ServeSuccessJSON(map[string]interface{}{
  1257. "msg": "撤销记账成功",
  1258. })
  1259. } else {
  1260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1261. return
  1262. }
  1263. }else {
  1264. result, request_log := service.NMGCancleSettleForCoordinate(order.PType,order.Number)
  1265. saveLog(result, request_log, "撤销记账", "撤销记账", "")
  1266. var res RefundDetailtwo
  1267. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1268. utils.ErrorLog("解析失败:%v", err)
  1269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1270. return
  1271. }
  1272. if res.Code == "200" {
  1273. err := service.UpdataOrderStatustwo(order_id, order.Number, c.GetAdminUserInfo().CurrentOrgId)
  1274. if err == nil {
  1275. c.ServeSuccessJSON(map[string]interface{}{
  1276. "msg": "撤销记账成功",
  1277. })
  1278. } else {
  1279. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1280. return
  1281. }
  1282. } else {
  1283. c.ServeSuccessJSON(map[string]interface{}{
  1284. "failed_code": -10,
  1285. "msg": res.Msg,
  1286. })
  1287. }
  1288. }
  1289. }else{
  1290. c.ServeSuccessJSON(map[string]interface{}{
  1291. "failed_code": -10,
  1292. "msg": res.Msg,
  1293. })
  1294. }
  1295. }
  1296. //func (c *CoordinateController)NMGgetcheck(){
  1297. // patient_id, _ := c.GetInt64("patient_id")
  1298. // record_date := c.GetString("record_date")
  1299. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1300. // //diagnosis_id := c.GetString("diagnosis")
  1301. // //sick_type, _ := c.GetInt64("sick_type")
  1302. // //reg_type, _ := c.GetInt64("p_type")
  1303. // org_id, _ := c.GetInt64("org_id")
  1304. // org_id = 10454
  1305. // org, _ := service.GetOrgById(org_id)
  1306. // patient, _ := service.GetPatientByID(org.Id, patient_id)
  1307. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1308. // result, request := service.GetNMGHisPatientForCoordinate(0,0,2,patient.Name)
  1309. // result5, request5 := service.GetNMGHisPatientForCoordinate(0,0,1,patient.Name)
  1310. //
  1311. // saveLog(result, request, "查询", "查询", "")
  1312. // saveLog(result5, request5, "查询", "查询", "")
  1313. //
  1314. // var res Data
  1315. // if err := json.Unmarshal([]byte(result), &res); err != nil {
  1316. // utils.ErrorLog("解析失败:%v", err)
  1317. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1318. // return
  1319. // }
  1320. //
  1321. // var res8 Data
  1322. // if err := json.Unmarshal([]byte(result5), &res8); err != nil {
  1323. // utils.ErrorLog("解析失败:%v", err)
  1324. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1325. // return
  1326. // }
  1327. //
  1328. // if res.Code == 200 || res8.Code == 200 {
  1329. // var res9 Data
  1330. // res9.List = append(res9.List,res.List...)
  1331. // res9.List = append(res9.List,res8.List...)
  1332. //
  1333. //
  1334. // var li ListItem
  1335. // for _, item := range res9.List{
  1336. // cure_date := strings.Split(item.Vae11, " ")
  1337. // if cure_date[0] == record_date && patient.Name == item.Vaa05{
  1338. // li = item
  1339. // }
  1340. // }
  1341. // fmt.Println("11111111")
  1342. // fmt.Println(li)
  1343. // fmt.Println("11111111")
  1344. // timeLayout := "2006-01-02"
  1345. // loc, _ := time.LoadLocation("Local")
  1346. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1347. // if err != nil {
  1348. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1349. // return
  1350. // }
  1351. // org_id := org.Id
  1352. // recordDateTime := theTime.Unix()
  1353. // patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  1354. // if patientPrescription.ID == 0 {
  1355. // patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  1356. // }
  1357. // //departmwnt, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1358. // //admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  1359. // //doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  1360. //
  1361. //
  1362. //
  1363. //
  1364. // //service.QueryNMGChenckForCoordinate(li.Acf01,li.Vaa01,li.Vaa07,"")
  1365. //
  1366. //
  1367. // } else {
  1368. // c.ServeSuccessJSON(map[string]interface{}{
  1369. // "failed_code": -10,
  1370. // "msg": res.Msg,
  1371. // })
  1372. // }
  1373. //
  1374. //
  1375. //}
  1376. //func (c *CoordinateController) SettleAccount() {
  1377. // patient_id, _ := c.GetInt64("patient_id")
  1378. // record_date := c.GetString("record_date")
  1379. // admin_user_id, _ := c.GetInt64("admin_user_id")
  1380. // diagnosis_id := c.GetString("diagnosis")
  1381. // sick_type, _ := c.GetInt64("sick_type")
  1382. // reg_type, _ := c.GetInt64("p_type")
  1383. // org_id, _ := c.GetInt64("org_id")
  1384. // org_id = 3877
  1385. // org, _ := service.GetOrgById(org_id)
  1386. // patient, _ := service.GetPatientByID(org.Id, patient_id)
  1387. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1388. //
  1389. // result, request := service.GetHisPatientForCoordinate(patient.IdCardNo)
  1390. // saveLog(result, request, "查询", "查询", org.OrgName)
  1391. // var res ResultQuery
  1392. // if err := json.Unmarshal([]byte(result), &res); err != nil {
  1393. // utils.ErrorLog("解析失败:%v", err)
  1394. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1395. // return
  1396. // }
  1397. // if res.Code == "10000" {
  1398. // if len(res.Result) == 0 {
  1399. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientNoRegException)
  1400. // return
  1401. // }
  1402. // timeLayout := "2006-01-02"
  1403. // loc, _ := time.LoadLocation("Local")
  1404. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1405. // if err != nil {
  1406. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1407. // return
  1408. // }
  1409. // org_id := org.Id
  1410. // recordDateTime := theTime.Unix()
  1411. // patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  1412. // if patientPrescription.ID == 0 {
  1413. // patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  1414. // }
  1415. // departmwnt, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1416. // doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  1417. // //admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  1418. //
  1419. // var prescriptions []*models.HisPrescription
  1420. //
  1421. // if settle_accounts_type == 1 { //日结
  1422. // prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, patient_id, recordDateTime, 2)
  1423. // } else { //月结
  1424. //
  1425. // start_time_str := c.GetString("start_time")
  1426. // end_time_str := c.GetString("end_time")
  1427. // timeLayout := "2006-01-02"
  1428. // loc, _ := time.LoadLocation("Local")
  1429. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  1430. // if err != nil {
  1431. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1432. // return
  1433. // }
  1434. // recordStartTime := theStartTime.Unix()
  1435. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  1436. // if err != nil {
  1437. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1438. // return
  1439. // }
  1440. // recordEndTime := theEndTime.Unix()
  1441. // prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, patient_id, recordStartTime, recordEndTime)
  1442. // }
  1443. // var total float64
  1444. //
  1445. // for _, item := range prescriptions {
  1446. // fmt.Println(item)
  1447. // if item.Type == 1 { //药品
  1448. // for _, subItem := range item.HisDoctorAdviceInfo {
  1449. // total = total + (subItem.Price * subItem.PrescribingNumber)
  1450. // }
  1451. // }
  1452. // if item.Type == 2 { //项目
  1453. // for _, subItem := range item.HisPrescriptionProject {
  1454. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1455. // total = total + (subItem.Price * cnt)
  1456. // }
  1457. // }
  1458. //
  1459. // }
  1460. //
  1461. // var ids []int64
  1462. //
  1463. // for _, item := range prescriptions {
  1464. // ids = append(ids, item.ID)
  1465. // }
  1466. //
  1467. // var customs []*models.NewCustomTwo
  1468. // for _, item := range prescriptions {
  1469. // if item.Type == 1 { //药品
  1470. // for _, subItem := range item.HisDoctorAdviceInfo {
  1471. // cus := &models.NewCustomTwo{
  1472. // AdviceId: subItem.ID,
  1473. // ProjectId: 0,
  1474. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  1475. // Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  1476. // FeedetlSn: subItem.FeedetlSn,
  1477. // Price: fmt.Sprintf("%.2f", subItem.Price),
  1478. // MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  1479. // Type: 1,
  1480. // }
  1481. // customs = append(customs, cus)
  1482. // }
  1483. // }
  1484. // if item.Type == 2 { //项目
  1485. // for _, subItem := range item.HisPrescriptionProject {
  1486. // if subItem.Type == 2 {
  1487. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1488. // cus := &models.NewCustomTwo{
  1489. // AdviceId: 0,
  1490. // ProjectId: subItem.ID,
  1491. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1492. // Cut: fmt.Sprintf("%.4f", cnt),
  1493. // FeedetlSn: subItem.FeedetlSn,
  1494. // Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1495. // MedListCodg: subItem.HisProject.MedicalCode,
  1496. // Type: 2,
  1497. // }
  1498. // customs = append(customs, cus)
  1499. //
  1500. // } else {
  1501. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  1502. // cus := &models.NewCustomTwo{
  1503. // AdviceId: 0,
  1504. // ProjectId: subItem.ID,
  1505. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  1506. // Cut: fmt.Sprintf("%.4f", cnt),
  1507. // FeedetlSn: subItem.FeedetlSn,
  1508. // Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  1509. // MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  1510. // Type: 3,
  1511. // }
  1512. // customs = append(customs, cus)
  1513. // }
  1514. //
  1515. // }
  1516. // }
  1517. // }
  1518. //
  1519. // var info models.UploadInfo
  1520. // info.Vaa01 = int64(res.Result[0].Vaa01)
  1521. // info.Fasong = "1"
  1522. // info.Vaa07 = int64(res.Result[0].Vaa07)
  1523. // info.Bck01c = departmwnt.Number
  1524. // info.Bce02a = doctor_info.DoctorNumber
  1525. //
  1526. // diagnosis_ids := strings.Split(patientPrescription.Diagnosis, ",")
  1527. // var config []*models.HisXtDiagnoseConfig
  1528. // for _, item := range diagnosis_ids {
  1529. // id, _ := strconv.ParseInt(item, 10, 64)
  1530. // diagnosisConfig, _ := service.FindDiagnoseById(id)
  1531. // config = append(config, &diagnosisConfig)
  1532. // }
  1533. // for index, item := range config {
  1534. // var diag models.Diag
  1535. // diag.Vao06 = strconv.FormatInt(int64(index+1), 10)
  1536. // diag.Bak02 = item.CountryCode
  1537. // info.Diag = append(info.Diag, &diag)
  1538. // }
  1539. // var presInfos []*models.PresInfo
  1540. // var presDetails []*models.PresDetail
  1541. // for index, item := range prescriptions {
  1542. // var presDetail models.PresDetail
  1543. // var presInfo models.PresInfo
  1544. // presInfo.Cbmid = strconv.FormatInt(item.ID, 10)
  1545. // if item.Type == 1 {
  1546. // presInfo.Cbm06 = "0"
  1547. // } else {
  1548. // presInfo.Cbm06 = "5"
  1549. // }
  1550. //
  1551. // if item.Type == 1 {
  1552. // presInfo.Cbm07 = item.MedType
  1553. // } else {
  1554. // presInfo.Cbm07 = item.MedType
  1555. // }
  1556. //
  1557. // presDetail.Vaf59 = strconv.FormatInt(int64(index+1), 10)
  1558. // var infoItems []*models.Item
  1559. // for _, subItem := range item.HisDoctorAdviceInfo {
  1560. // ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  1561. //
  1562. // var infoItem models.Item
  1563. // infoItem.Rownr = "0"
  1564. // infoItem.Vaf11 = "1"
  1565. // infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  1566. // infoItem.Bbx01 = subItem.BaseDrugLib.MedicalInsuranceNumber
  1567. // infoItem.Bda01 = "1"
  1568. // infoItem.Bby01 = ""
  1569. // if subItem.BaseDrugLib.MinUnit != subItem.BaseDrugLib.DoseUnit {
  1570. // infoItem.Vaf22 = subItem.BaseDrugLib.DrugName + " " + subItem.BaseDrugLib.Dose + subItem.BaseDrugLib.DoseUnit + "*" + strconv.FormatInt(subItem.BaseDrugLib.MinNumber, 10) + subItem.BaseDrugLib.MinUnit + "/" + subItem.BaseDrugLib.MaxUnit
  1571. // }
  1572. // infoItem.Vaf14 = subItem.BaseDrugLib.DrugName
  1573. // infoItem.Bdi01 = ef.Code
  1574. // infoItem.Vaf17 = strconv.FormatInt(subItem.Day, 10)
  1575. // infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  1576. // infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.PrescribingNumber)
  1577. // infoItem.Vaf35 = "0"
  1578. // infoItem.Vaf32 = "0"
  1579. // infoItem.Bck01b = departmwnt.Number
  1580. // infoItem.Bck01d = departmwnt.Number
  1581. // infoItem.Vaf58 = "0"
  1582. // infoItem.Vaf61 = "1"
  1583. // infoItems = append(infoItems, &infoItem)
  1584. // }
  1585. // for _, subItem := range item.HisPrescriptionProject {
  1586. // ef, _ := service.GetExecutionFrequencyByName(subItem.ExecutionFrequency, subItem.UserOrgId)
  1587. //
  1588. // if subItem.Type == 2 {
  1589. // var infoItem models.Item
  1590. // infoItem.Rownr = "0"
  1591. // infoItem.Vaf11 = "1"
  1592. // infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  1593. // infoItem.Bbx01 = subItem.HisProject.MedicalCode
  1594. //
  1595. // if subItem.HisProject.CostClassify == 2 {
  1596. // infoItem.Bda01 = "T"
  1597. // } else if subItem.HisProject.CostClassify == 3 {
  1598. // infoItem.Bda01 = "L"
  1599. // } else {
  1600. // infoItem.Bda01 = "T"
  1601. // }
  1602. // infoItem.Bby01 = ""
  1603. // infoItem.Vaf22 = subItem.HisProject.ProjectName
  1604. // infoItem.Bdi01 = ef.Code
  1605. // infoItem.Vaf17 = subItem.Day
  1606. // infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  1607. // infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.Count)
  1608. // infoItem.Vaf35 = "0"
  1609. // infoItem.Vaf18 = "0"
  1610. // infoItem.Vaf32 = "0"
  1611. // infoItem.Bck01b = departmwnt.Number
  1612. // infoItem.Bck01d = departmwnt.Number
  1613. // infoItem.Vaf58 = "0"
  1614. // infoItem.Vaf61 = "1"
  1615. // infoItems = append(infoItems, &infoItem)
  1616. //
  1617. // } else {
  1618. // var infoItem models.Item
  1619. // infoItem.Rownr = "0"
  1620. // infoItem.Vaf11 = "1"
  1621. // infoItem.Vaf36 = time.Unix(subItem.ExecutionTime, 0).Format("2006-01-02 15:04:05")
  1622. // infoItem.Bbx01 = subItem.GoodInfo.MedicalInsuranceNumber
  1623. // infoItem.Bda01 = "M"
  1624. // infoItem.Bby01 = ""
  1625. // infoItem.Vaf22 = subItem.GoodInfo.GoodName + " " + subItem.GoodInfo.SpecificationName
  1626. // infoItem.Bdi01 = ef.Code
  1627. // infoItem.Vaf17 = subItem.Day
  1628. // infoItem.Vaf20 = fmt.Sprintf("%.2f", subItem.SingleDose)
  1629. // infoItem.Vaf21 = fmt.Sprintf("%.2f", subItem.Count)
  1630. // infoItem.Vaf35 = "0"
  1631. // infoItem.Vaf32 = "0"
  1632. // infoItem.Bck01b = departmwnt.Number
  1633. // infoItem.Bck01d = departmwnt.Number
  1634. // infoItem.Vaf58 = "0"
  1635. // infoItem.Vaf61 = "1"
  1636. // infoItems = append(infoItems, &infoItem)
  1637. //
  1638. // }
  1639. //
  1640. // }
  1641. // presDetail.Item = infoItems
  1642. // presDetails = append(presDetails, &presDetail)
  1643. // presInfo.PresDetail = presDetails
  1644. // presInfos = append(presInfos, &presInfo)
  1645. // }
  1646. // info.PresInfo = presInfos
  1647. //
  1648. // result2, request2 := service.UploadPrescriptionForCoordinate(info)
  1649. // saveLog(result2, request2, "上传明细", "上传明细", org.OrgName)
  1650. //
  1651. // var res2 ResultUpload
  1652. // if err := json.Unmarshal([]byte(result2), &res2); err != nil {
  1653. // utils.ErrorLog("解析失败:%v", err)
  1654. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1655. // return
  1656. // }
  1657. // if res2.Code == "10000" {
  1658. //
  1659. // timestamp := time.Now().Unix()
  1660. // tempTime := time.Unix(timestamp, 0)
  1661. // timeFormat := tempTime.Format("20060102150405")
  1662. // chrgBchno := rand.Intn(100000) + 10000
  1663. // ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  1664. // his := models.VMHisPatient{
  1665. // Name: patient.Name,
  1666. // Gender: patient.Gender,
  1667. // Birthday: patient.Birthday,
  1668. // MedicalTreatmentType: 0,
  1669. // IdType: 1,
  1670. // IdCardNo: patient.IdCardNo,
  1671. // BalanceAccountsType: 1,
  1672. // MedicalInsuranceNumber: "",
  1673. // RegisterType: 0,
  1674. // RegisterCost: 0,
  1675. // TreatmentCost: 0,
  1676. // Status: 1,
  1677. // Ctime: time.Now().Unix(),
  1678. // Mtime: time.Now().Unix(),
  1679. // PsnNo: strconv.FormatInt(int64(res.Result[0].Vaa01), 10),
  1680. // PsnCertType: "",
  1681. // Certno: patient.IdCardNo,
  1682. // PsnName: patient.Name,
  1683. // Gend: "",
  1684. // Naty: "",
  1685. // Brdy: "",
  1686. // Age: 0,
  1687. // Iinfo: "",
  1688. // Idetinfo: "",
  1689. // PatientId: patient.ID,
  1690. // RecordDate: theTime.Unix(),
  1691. // UserOrgId: org_id,
  1692. // AdminUserId: admin_user_id,
  1693. // IsReturn: 1,
  1694. // Doctor: patientPrescription.DoctorId,
  1695. // Departments: patientPrescription.Departments,
  1696. // IptOtpNo: ipt_otp_no,
  1697. // Number: strconv.FormatInt(int64(res.Result[0].Vaa07), 10),
  1698. // PhoneNumber: patient.Phone,
  1699. // }
  1700. // service.UpdateHisPatientStatusten(&his)
  1701. // service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  1702. // tm := time.Unix(time.Now().Unix(), 0)
  1703. //
  1704. // order := &models.HisOrder{
  1705. // PsnNo: his.PsnNo,
  1706. // UserOrgId: org_id,
  1707. // HisPatientId: his.ID,
  1708. // PatientId: patient_id,
  1709. // SettleAccountsDate: recordDateTime,
  1710. // Ctime: time.Now().Unix(),
  1711. // Mtime: time.Now().Unix(),
  1712. // Status: 1,
  1713. // OrderStatus: 1,
  1714. // MdtrtId: his.Number,
  1715. // Number: ipt_otp_no,
  1716. // SetlId: "",
  1717. // MedfeeSumamt: total,
  1718. // MedType: strconv.Itoa(int(reg_type)),
  1719. // SettleEndTime: 0,
  1720. // SettleStartTime: 0,
  1721. // SettleType: settle_accounts_type,
  1722. // Diagnosis: diagnosis_id,
  1723. // PType: 2,
  1724. // SetlTime: tm.Format("2006-01-02 15:04:05"),
  1725. // }
  1726. // err = service.CreateOrder(order)
  1727. // if err != nil {
  1728. // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1729. // return
  1730. // }
  1731. //
  1732. // for _, item := range customs {
  1733. // var advice_id int64 = 0
  1734. // var project_id int64 = 0
  1735. // var item_id int64 = 0
  1736. //
  1737. // var types int64 = 0
  1738. //
  1739. // if item.Type == 1 {
  1740. // advice_id = item.AdviceId
  1741. // project_id = 0
  1742. // item_id = 0
  1743. // } else if item.Type == 2 {
  1744. // advice_id = 0
  1745. // item_id = 0
  1746. //
  1747. // project_id = item.ProjectId
  1748. // } else if item.Type == 3 {
  1749. // advice_id = 0
  1750. // item_id = item.ItemId
  1751. // project_id = 0
  1752. // }
  1753. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1754. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  1755. // pric, _ := strconv.ParseFloat(item.Price, 32)
  1756. // info := &models.HisOrderInfo{
  1757. // OrderNumber: order.Number,
  1758. // UploadDate: time.Now().Unix(),
  1759. // AdviceId: advice_id,
  1760. // DetItemFeeSumamt: detItemFeeSumamt,
  1761. // Cnt: cut,
  1762. // Pric: pric,
  1763. // PatientId: patient_id,
  1764. // Status: 1,
  1765. // Mtime: time.Now().Unix(),
  1766. // Ctime: time.Now().Unix(),
  1767. // UserOrgId: org_id,
  1768. // HisPatientId: his.ID,
  1769. // OrderId: order.ID,
  1770. // ProjectId: project_id,
  1771. // Type: types,
  1772. // ItemId: item_id,
  1773. // }
  1774. // service.CreateOrderInfo(info)
  1775. // }
  1776. // his.Diagnosis = diagnosis_id
  1777. // his.SickType = sick_type
  1778. // his.RegisterType = reg_type
  1779. // his.MedicalTreatmentType = reg_type
  1780. // service.UpdataHisPateintTwo(&his)
  1781. // err = service.UpDatePrescriptionNumber(org_id, ids, strconv.FormatInt(int64(chrgBchno), 10))
  1782. // err = service.UpDateHisPrescriptionInfoNumbertwo(org_id, patient_id, strconv.FormatInt(int64(chrgBchno), 10), recordDateTime, his.ID)
  1783. // err = service.UpdataOrderStatusThreef(strconv.FormatInt(int64(chrgBchno), 10), org_id)
  1784. //
  1785. // c.ServeSuccessJSON(map[string]interface{}{
  1786. // "msg": "医嘱保存成功",
  1787. // })
  1788. //
  1789. // } else {
  1790. // c.ServeSuccessJSON(map[string]interface{}{
  1791. // "failed_code": -10,
  1792. // "msg": res.Msg,
  1793. // })
  1794. //
  1795. // }
  1796. //
  1797. // } else {
  1798. // c.ServeSuccessJSON(map[string]interface{}{
  1799. // "failed_code": -10,
  1800. // "msg": res.Msg,
  1801. // })
  1802. //
  1803. // }
  1804. //
  1805. //}
  1806. func (c *CoordinateController) Settle() {
  1807. //参数1 patient_id
  1808. //参数2 就诊号
  1809. //参数3 单据id
  1810. fmt.Println(c.Ctx.Request.Body)
  1811. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  1812. fmt.Println(string(body))
  1813. var respJSON map[string]interface{}
  1814. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1815. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1816. return
  1817. }
  1818. patien_id := respJSON["vaa01"].(float64)
  1819. infoSeq := respJSON["vaa07"].(float64)
  1820. //strconv.For(patien_id, 10)
  1821. vaa001 := fmt.Sprintf("%f", patien_id)
  1822. vaa007 := fmt.Sprintf("%f", infoSeq)
  1823. setl_id := respJSON["setl_id"].(string)
  1824. order, _ := service.GetHisOrderFour(vaa001, vaa007, "")
  1825. order.SetlId = setl_id
  1826. if order.ID == 0 {
  1827. json := make(map[string]interface{})
  1828. json["msg"] = "结算记录不存在,请检查参数是否正确"
  1829. json["code"] = "-1"
  1830. c.Data["json"] = json
  1831. c.ServeJSON()
  1832. return
  1833. }
  1834. order.OrderStatus = 2
  1835. service.UpDateOrder(order)
  1836. service.UpdataOrderStatusTwo(order.Number, order.UserOrgId)
  1837. json := make(map[string]interface{})
  1838. json["msg"] = "结算成功"
  1839. json["code"] = "0"
  1840. c.Data["json"] = json
  1841. c.ServeJSON()
  1842. return
  1843. }
  1844. func (c *CoordinateController) Refund() {
  1845. //参数1 patient_id
  1846. //参数2 就诊号
  1847. //参数3 单据id
  1848. body, _ := ioutil.ReadAll(c.Ctx.Request.Body)
  1849. var respJSON map[string]interface{}
  1850. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1851. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1852. return
  1853. }
  1854. patien_id := respJSON["vaa01"].(float64)
  1855. infoSeq := respJSON["vaa07"].(float64)
  1856. //strconv.For(patien_id, 10)
  1857. vaa001 := fmt.Sprintf("%f", patien_id)
  1858. vaa007 := fmt.Sprintf("%f", infoSeq)
  1859. docId := respJSON["setl_id"].(string)
  1860. order, _ := service.GetHisOrderFour(vaa001, vaa007, docId)
  1861. if order.ID == 0 {
  1862. json := make(map[string]interface{})
  1863. json["msg"] = "结算记录不存在,请检查参数是否正确"
  1864. json["code"] = "-1"
  1865. c.Data["json"] = json
  1866. c.ServeJSON()
  1867. return
  1868. }
  1869. service.UpdataOrderStatustwo(order.ID, order.Number, order.UserOrgId)
  1870. json := make(map[string]interface{})
  1871. json["msg"] = "退费成功"
  1872. json["code"] = "0"
  1873. c.Data["json"] = json
  1874. c.ServeJSON()
  1875. return
  1876. }
  1877. func (c *CoordinateController) SavePatientMessageInfo() {
  1878. result, request_log := service.SavePatientMessageInfo()
  1879. fmt.Println(result)
  1880. fmt.Println(request_log)
  1881. }
  1882. func (c *CoordinateController) checkpatient() {
  1883. }
  1884. func (c *CoordinateController) Register() {
  1885. patient_id, _ := c.GetInt64("patient_id")
  1886. diagnosis_time := c.GetString("diagnosis_time")
  1887. record_date := c.GetString("record_date")
  1888. admin_user_id, _ := c.GetInt64("admin_user_id")
  1889. org_id, _ := c.GetInt64("org_id")
  1890. patient, _ := service.GetPatientByID(org_id, patient_id)
  1891. org, _ := service.GetOrgById(org_id)
  1892. timeLayout := "2006-01-02"
  1893. loc, _ := time.LoadLocation("Local")
  1894. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1895. if err != nil {
  1896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1897. return
  1898. }
  1899. if len(patient.ZbPatientId) == 0 {
  1900. c.ServeFailJSONWithSGJErrorCode(enums.ErrorPsnNoEmpty)
  1901. return
  1902. }
  1903. recordDateTime := theTime.Unix()
  1904. patientPrescription, _ := service.FindPatientPrescriptionInfoTwo(org_id, patient.ID, recordDateTime, 2)
  1905. if patientPrescription.ID == 0 {
  1906. patientPrescription, _ = service.FindLastPatientPrescriptionInfo(org_id, patient.ID, recordDateTime)
  1907. }
  1908. doctor_info, _ := service.GetAdminUserInfoByID(org_id, patientPrescription.DoctorId)
  1909. admin_user_info, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  1910. reg := models.Reg{
  1911. DeptId: "0112",
  1912. PatientId: patient.ZbPatientId,
  1913. PatientName: patient.Name,
  1914. DoctorId: doctor_info.DoctorNumber,
  1915. RegDate: strings.Split(diagnosis_time, " ")[0],
  1916. RegFee: "0",
  1917. TreatFee: "0",
  1918. OperatorId: admin_user_info.UserName,
  1919. IdCardNo: patient.IdCardNo,
  1920. }
  1921. result, request_log := service.SaveReg(reg)
  1922. fmt.Println(result)
  1923. fmt.Println(request_log)
  1924. saveLog(result, request_log, "登记", "登记", org.OrgName)
  1925. var res ResultReg
  1926. if err := json.Unmarshal([]byte(result), &res); err != nil {
  1927. utils.ErrorLog("解析失败:%v", err)
  1928. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1929. return
  1930. }
  1931. if res.ResultCode == "0" {
  1932. timestamp := time.Now().Unix()
  1933. tempTime := time.Unix(timestamp, 0)
  1934. timeFormat := tempTime.Format("20060102150405")
  1935. chrgBchno := rand.Intn(100000) + 10000
  1936. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(patient.ID, 10)
  1937. his := models.VMHisPatient{
  1938. Name: patient.Name,
  1939. Gender: patient.Gender,
  1940. Birthday: patient.Birthday,
  1941. MedicalTreatmentType: 0,
  1942. IdType: 1,
  1943. IdCardNo: patient.IdCardNo,
  1944. BalanceAccountsType: 1,
  1945. MedicalInsuranceNumber: "",
  1946. RegisterType: 0,
  1947. RegisterCost: 0,
  1948. TreatmentCost: 0,
  1949. Status: 1,
  1950. Ctime: time.Now().Unix(),
  1951. Mtime: time.Now().Unix(),
  1952. PsnNo: patient.ZbPatientId,
  1953. PsnCertType: "",
  1954. Certno: patient.IdCardNo,
  1955. PsnName: patient.Name,
  1956. Gend: "",
  1957. Naty: "",
  1958. Brdy: "",
  1959. Age: 0,
  1960. Iinfo: "",
  1961. Idetinfo: "",
  1962. PatientId: patient.ID,
  1963. RecordDate: theTime.Unix(),
  1964. UserOrgId: org_id,
  1965. AdminUserId: admin_user_id,
  1966. IsReturn: 1,
  1967. Doctor: patientPrescription.DoctorId,
  1968. Departments: patientPrescription.Departments,
  1969. IptOtpNo: ipt_otp_no,
  1970. Number: res.InfoSeq,
  1971. PhoneNumber: patient.Phone,
  1972. }
  1973. service.UpdateHisPatientStatus(&his)
  1974. service.UpdateHisPrescriptionHisID(his.ID, patient.ID, recordDateTime, org_id)
  1975. c.ServeSuccessJSON(map[string]interface{}{
  1976. "his_info": his,
  1977. })
  1978. } else {
  1979. c.ServeSuccessJSON(map[string]interface{}{
  1980. "failed_code": -10,
  1981. "msg": res.ResultDesc,
  1982. })
  1983. }
  1984. }
  1985. //func (c *CoordinateController) GetWaitPayDetail() {
  1986. // result, request_log := service.GetWaitPayDetail()
  1987. // fmt.Println(result)
  1988. // fmt.Println(request_log)
  1989. //
  1990. //}
  1991. //func (c *CoordinateController) OpKeepAccounts() {
  1992. // id, _ := c.GetInt64("id")
  1993. // record_time := c.GetString("record_time")
  1994. // his_patient_id, _ := c.GetInt64("his_patient_id")
  1995. // timeLayout := "2006-01-02"
  1996. // loc, _ := time.LoadLocation("Local")
  1997. // settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  1998. // fapiao_code := c.GetString("fapiao_code")
  1999. // fapiao_number := c.GetString("fapiao_number")
  2000. // diagnosis_id := c.GetString("diagnosis")
  2001. // sick_type, _ := c.GetInt64("sick_type")
  2002. // reg_type, _ := c.GetInt64("p_type")
  2003. // org_id, _ := c.GetInt64("org_id")
  2004. // org, _ := service.GetOrgById(org_id)
  2005. //
  2006. // his, _ := service.GetHisPatientByIdThree(his_patient_id)
  2007. //
  2008. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2009. // if err != nil {
  2010. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2011. // return
  2012. // }
  2013. // recordDateTime := theTime.Unix()
  2014. // //adminUser := c.GetAdminUserInfo()
  2015. // var prescriptions []*models.HisPrescription
  2016. // var start_time int64
  2017. // var end_time int64
  2018. //
  2019. // //ids_str := c.GetString("ids")
  2020. // //ids_arr := strings.Split(ids_str, ",")
  2021. //
  2022. // if settle_accounts_type == 1 { //日结
  2023. // //fmt.Println(reg_type)
  2024. // prescriptions, _ = service.GetUnSettleHisPrescriptionFive(org_id, id, recordDateTime, 2)
  2025. //
  2026. // } else { //月结
  2027. //
  2028. // start_time_str := c.GetString("start_time")
  2029. // end_time_str := c.GetString("end_time")
  2030. // timeLayout := "2006-01-02"
  2031. // loc, _ := time.LoadLocation("Local")
  2032. // theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2033. // if err != nil {
  2034. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2035. // return
  2036. // }
  2037. // recordStartTime := theStartTime.Unix()
  2038. // start_time = recordStartTime
  2039. // theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2040. // if err != nil {
  2041. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2042. // return
  2043. // }
  2044. // recordEndTime := theEndTime.Unix()
  2045. // end_time = recordEndTime
  2046. // prescriptions, _ = service.GetUnSettleMonthHisPrescription(org_id, id, recordStartTime, recordEndTime)
  2047. // }
  2048. //
  2049. // timestamp := time.Now().Unix()
  2050. // tempTime := time.Unix(timestamp, 0)
  2051. // timeFormat := tempTime.Format("20060102150405")
  2052. // chrgBchno := rand.Intn(100000) + 10000
  2053. // chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2054. // strconv.FormatInt(his.PatientId, 10)
  2055. //
  2056. // var ids []int64
  2057. //
  2058. // for _, item := range prescriptions {
  2059. // ids = append(ids, item.ID)
  2060. // }
  2061. // var total float64
  2062. //
  2063. // for _, item := range prescriptions {
  2064. // fmt.Println(item)
  2065. // if item.Type == 1 { //药品
  2066. // for _, subItem := range item.HisDoctorAdviceInfo {
  2067. // total = total + (subItem.Price * subItem.PrescribingNumber)
  2068. // }
  2069. // }
  2070. // if item.Type == 2 { //项目
  2071. // for _, subItem := range item.HisPrescriptionProject {
  2072. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2073. // total = total + (subItem.Price * cnt)
  2074. // }
  2075. // }
  2076. //
  2077. // for _, subItem := range item.HisAdditionalCharge {
  2078. // total = total + (subItem.Price * float64(subItem.Count))
  2079. // }
  2080. // }
  2081. //
  2082. // tm := time.Unix(time.Now().Unix(), 0)
  2083. //
  2084. // var customs []*models.NewCustomTwo
  2085. // for _, item := range prescriptions {
  2086. // if item.Type == 1 { //药品
  2087. // for _, subItem := range item.HisDoctorAdviceInfo {
  2088. // cus := &models.NewCustomTwo{
  2089. // AdviceId: subItem.ID,
  2090. // ProjectId: 0,
  2091. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  2092. // Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  2093. // FeedetlSn: subItem.FeedetlSn,
  2094. // Price: fmt.Sprintf("%.2f", subItem.Price),
  2095. // MedListCodg: subItem.BaseDrugLib.MedicalInsuranceNumber,
  2096. // Type: 1,
  2097. // }
  2098. // customs = append(customs, cus)
  2099. // }
  2100. // }
  2101. // if item.Type == 2 { //项目
  2102. // for _, subItem := range item.HisPrescriptionProject {
  2103. // if subItem.Type == 2 {
  2104. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2105. // cus := &models.NewCustomTwo{
  2106. // AdviceId: 0,
  2107. // ProjectId: subItem.ID,
  2108. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2109. // Cut: fmt.Sprintf("%.4f", cnt),
  2110. // FeedetlSn: subItem.FeedetlSn,
  2111. // Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2112. // MedListCodg: subItem.HisProject.MedicalCode,
  2113. // Type: 2,
  2114. // }
  2115. // customs = append(customs, cus)
  2116. //
  2117. // } else {
  2118. // cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  2119. // cus := &models.NewCustomTwo{
  2120. // AdviceId: 0,
  2121. // ProjectId: subItem.ID,
  2122. // DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  2123. // Cut: fmt.Sprintf("%.4f", cnt),
  2124. // FeedetlSn: subItem.FeedetlSn,
  2125. // Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  2126. // MedListCodg: subItem.GoodInfo.MedicalInsuranceNumber,
  2127. // Type: 3,
  2128. // }
  2129. // customs = append(customs, cus)
  2130. //
  2131. // }
  2132. //
  2133. // }
  2134. // }
  2135. // for _, item := range item.HisAdditionalCharge {
  2136. // cus := &models.NewCustomTwo{
  2137. // ItemId: item.ID,
  2138. // AdviceId: 0,
  2139. // ProjectId: 0,
  2140. // DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  2141. // Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  2142. // FeedetlSn: item.FeedetlSn,
  2143. // Price: fmt.Sprintf("%.4f", float64(item.Price)),
  2144. // MedListCodg: item.XtHisAddtionConfig.Code,
  2145. // Type: 3,
  2146. // }
  2147. // customs = append(customs, cus)
  2148. // }
  2149. // }
  2150. // result, request_log := service.OpKeepAccounts(his.Number, customs)
  2151. // saveLog(result, request_log, "记账", "记账", org.OrgName)
  2152. //
  2153. // var res ResultSettle
  2154. // if err := json.Unmarshal([]byte(result), &res); err != nil {
  2155. // utils.ErrorLog("解析失败:%v", err)
  2156. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2157. // return
  2158. // }
  2159. // if res.ResultCode == "0" {
  2160. //
  2161. // //totals, _ := strconv.ParseFloat(total, 64)
  2162. // order := &models.HisOrder{
  2163. // PsnNo: his.PsnNo,
  2164. // UserOrgId: org_id,
  2165. // HisPatientId: his.ID,
  2166. // PatientId: id,
  2167. // SettleAccountsDate: recordDateTime,
  2168. // Ctime: time.Now().Unix(),
  2169. // Mtime: time.Now().Unix(),
  2170. // Status: 1,
  2171. // OrderStatus: 1,
  2172. // MdtrtId: his.Number,
  2173. // Number: chrg_bchno,
  2174. // SetlId: "",
  2175. // MedfeeSumamt: total,
  2176. // MedType: strconv.Itoa(int(reg_type)),
  2177. // SettleEndTime: end_time,
  2178. // SettleStartTime: start_time,
  2179. // SettleType: settle_accounts_type,
  2180. // FaPiaoCode: fapiao_code,
  2181. // FaPiaoNumber: fapiao_number,
  2182. // Diagnosis: diagnosis_id,
  2183. // PType: 2,
  2184. // SetlTime: tm.Format("2006-01-02 15:04:05"),
  2185. // }
  2186. // err = service.CreateOrder(order)
  2187. // if err != nil {
  2188. // //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2189. // return
  2190. // }
  2191. //
  2192. // for _, item := range customs {
  2193. // var advice_id int64 = 0
  2194. // var project_id int64 = 0
  2195. // var item_id int64 = 0
  2196. //
  2197. // var types int64 = 0
  2198. //
  2199. // if item.Type == 1 {
  2200. // advice_id = item.AdviceId
  2201. // project_id = 0
  2202. // item_id = 0
  2203. // } else if item.Type == 2 {
  2204. // advice_id = 0
  2205. // item_id = 0
  2206. //
  2207. // project_id = item.ProjectId
  2208. // } else if item.Type == 3 {
  2209. // advice_id = 0
  2210. // item_id = item.ItemId
  2211. // project_id = 0
  2212. // }
  2213. // detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2214. // cut, _ := strconv.ParseFloat(item.Cut, 32)
  2215. // pric, _ := strconv.ParseFloat(item.Price, 32)
  2216. // info := &models.HisOrderInfo{
  2217. // OrderNumber: order.Number,
  2218. // UploadDate: time.Now().Unix(),
  2219. // AdviceId: advice_id,
  2220. // DetItemFeeSumamt: detItemFeeSumamt,
  2221. // Cnt: cut,
  2222. // Pric: pric,
  2223. // PatientId: id,
  2224. // Status: 1,
  2225. // Mtime: time.Now().Unix(),
  2226. // Ctime: time.Now().Unix(),
  2227. // UserOrgId: org_id,
  2228. // HisPatientId: his.ID,
  2229. // OrderId: order.ID,
  2230. // ProjectId: project_id,
  2231. // Type: types,
  2232. // ItemId: item_id,
  2233. // }
  2234. // service.CreateOrderInfo(info)
  2235. // }
  2236. // his.Diagnosis = diagnosis_id
  2237. // his.SickType = sick_type
  2238. // his.RegisterType = reg_type
  2239. // his.MedicalTreatmentType = reg_type
  2240. // service.UpdataHisPateintThree(&his)
  2241. // err = service.UpDatePrescriptionNumber(org_id, ids, chrg_bchno)
  2242. // err = service.UpDateHisPrescriptionInfoNumbertwo(org_id, id, chrg_bchno, recordDateTime, his_patient_id)
  2243. // err = service.UpdataOrderStatusThreef(chrg_bchno, org_id)
  2244. // if err == nil {
  2245. // c.ServeSuccessJSON(map[string]interface{}{
  2246. // "msg": "记账成功",
  2247. // })
  2248. // }
  2249. // } else {
  2250. // c.ServeSuccessJSON(map[string]interface{}{
  2251. // "failed_code": -10,
  2252. // "msg": res.ResultDesc,
  2253. // })
  2254. // }
  2255. //
  2256. //}
  2257. //
  2258. //func (c *CoordinateController) OpCancelKeepAccounts() {
  2259. // order_id, _ := c.GetInt64("order_id")
  2260. // admin_user_id, _ := c.GetInt64("admin_user_id")
  2261. // org_id, _ := c.GetInt64("org_id")
  2262. // org, _ := service.GetOrgById(org_id)
  2263. //
  2264. // order, _ := service.GetHisOrderByID(order_id)
  2265. // if order.ID == 0 {
  2266. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2267. // return
  2268. // }
  2269. //
  2270. // role, _ := service.GetAdminUserInfoByID(org_id, admin_user_id)
  2271. // result, request_log := service.OpCancelKeepAccounts(order.SetlId, role.UserName, role.DoctorNumber)
  2272. // saveLog(result, request_log, "撤销记账", "撤销记账", org.OrgName)
  2273. // var res RefundDetail
  2274. // if err := json.Unmarshal([]byte(result), &res); err != nil {
  2275. // utils.ErrorLog("解析失败:%v", err)
  2276. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2277. // return
  2278. // }
  2279. // fmt.Println(result)
  2280. // fmt.Println(request_log)
  2281. // fmt.Println(res)
  2282. // flag := 0
  2283. // isSuccess := false
  2284. // for _, item := range res.Result {
  2285. // if item.Code == "200" {
  2286. // flag = flag + 1
  2287. // }
  2288. // }
  2289. // if len(res.Result) == flag {
  2290. // isSuccess = true
  2291. // }
  2292. // var errMsg string
  2293. // for _, item := range res.Result {
  2294. // errMsg = errMsg + "\n" + item.ResultMsg
  2295. // }
  2296. //
  2297. // if isSuccess {
  2298. // err := service.UpdataOrderStatustwo(order_id, order.Number, org_id)
  2299. // if err == nil {
  2300. // c.ServeSuccessJSON(map[string]interface{}{
  2301. // "msg": "撤销记账成功",
  2302. // })
  2303. // } else {
  2304. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2305. // return
  2306. // }
  2307. // } else {
  2308. // c.ServeSuccessJSON(map[string]interface{}{
  2309. // "failed_code": -10,
  2310. // "msg": errMsg,
  2311. // })
  2312. //
  2313. // }
  2314. //}
  2315. //func saveLog(result string, request string, infno string, desc string) {
  2316. //
  2317. // org_id, _ := beego.AppConfig.Int64("org_id")
  2318. // miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2319. // dir := miConfig.OrgName + "日志"
  2320. // utils.Mkdir(dir)
  2321. // month := time.Unix(1557042972, 0).Format("1")
  2322. // year := time.Now().Format("2006")
  2323. // month = time.Now().Format("01")
  2324. // day := time.Now().Format("02")
  2325. // hour := time.Now().Format("15")
  2326. // min := time.Now().Format("04")
  2327. // sec := time.Now().Format("05")
  2328. //
  2329. // result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2330. //
  2331. // file := strconv.FormatInt(org_id, 10) + "_" + year + month + day + "_log"
  2332. // file_name := file + ".txt"
  2333. // file_path := miConfig.OrgName + "日志" + "/" + file_name
  2334. // exist, _ := utils.PathExists(file_path)
  2335. // if exist { //存在
  2336. // fmt.Println("存在")
  2337. // f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2338. // if err != nil {
  2339. // fmt.Println("read fail")
  2340. // }
  2341. // content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2342. // n, _ := f.Seek(0, 2)
  2343. // _, err = f.WriteAt([]byte(content), n)
  2344. //
  2345. // } else { //不存在
  2346. // fmt.Println("文件不存在,创建文件")
  2347. // f, err := os.Create(miConfig.OrgName + "日志" + "/" + file_name)
  2348. // defer f.Close()
  2349. // if err != nil {
  2350. // } else {
  2351. // _, err = f.Write([]byte("记录日志"))
  2352. // }
  2353. // }
  2354. //
  2355. //}
  2356. type Charset string
  2357. const (
  2358. UTF8 = Charset("UTF-8")
  2359. GB18030 = Charset("GB18030")
  2360. )
  2361. func saveLog(result string, request string, infno string, desc string, org_name string) {
  2362. //org_id, _ := beego.AppConfig.Int64("org_id")
  2363. //miConfig, _ := service.FindMedicalInsuranceInfo(org_id)
  2364. dir := org_name + "日志"
  2365. utils.Mkdir(dir)
  2366. month := time.Unix(1557042972, 0).Format("1")
  2367. year := time.Now().Format("2006")
  2368. month = time.Now().Format("01")
  2369. day := time.Now().Format("02")
  2370. hour := time.Now().Format("15")
  2371. min := time.Now().Format("04")
  2372. sec := time.Now().Format("05")
  2373. result_time := year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec
  2374. file := org_name + "_" + year + month + day + "_log"
  2375. file_name := file + ".txt"
  2376. file_path := org_name + "日志" + "/" + file_name
  2377. exist, _ := utils.PathExists(file_path)
  2378. if exist { //存在
  2379. fmt.Println("存在")
  2380. f, err := os.OpenFile(file_path, os.O_WRONLY, 0644)
  2381. if err != nil {
  2382. fmt.Println("read fail")
  2383. }
  2384. content := "\r\n" + "\r\n" + "\r\n" + result_time + " " + "【 " + desc + infno + "入参" + " 】:" + "\r\n" + request + "\r\n" + result_time + " " + "【 " + desc + infno + "出参" + " 】:" + "\r\n" + result
  2385. n, _ := f.Seek(0, 2)
  2386. _, err = f.WriteAt([]byte(content), n)
  2387. } else { //不存在
  2388. fmt.Println("文件不存在,创建文件")
  2389. f, err := os.Create(org_name + "日志" + "/" + file_name)
  2390. defer f.Close()
  2391. if err != nil {
  2392. } else {
  2393. _, err = f.Write([]byte("记录日志"))
  2394. }
  2395. }
  2396. }