his_api_controller.go 90KB

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