his_api_controller.go 69KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "io/ioutil"
  13. "math/rand"
  14. "net/http"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  35. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  36. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  39. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  40. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  41. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  42. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  43. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  44. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  45. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  46. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  47. //新增附加费用
  48. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  49. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  50. }
  51. func (c *HisApiController) GetHisPatientList() {
  52. types, _ := c.GetInt64("type", 0)
  53. record_date := c.GetString("record_date")
  54. timeLayout := "2006-01-02"
  55. loc, _ := time.LoadLocation("Local")
  56. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  57. if err != nil {
  58. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  59. return
  60. }
  61. recordDateTime := theTime.Unix()
  62. adminInfo := c.GetAdminUserInfo()
  63. patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  64. var total_one int64
  65. var total_two int64
  66. for _, item := range patients {
  67. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  68. total_one = total_one + 1
  69. }
  70. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  71. total_two = total_two + 1
  72. }
  73. }
  74. if types == 0 {
  75. c.ServeSuccessJSON(map[string]interface{}{
  76. "list": patients,
  77. "total_one": total_one,
  78. "total_two": total_two,
  79. })
  80. } else if types == 1 { //未就诊
  81. var patientsOne []*service.Schedule
  82. for _, item := range patients {
  83. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  84. patientsOne = append(patientsOne, item)
  85. }
  86. }
  87. c.ServeSuccessJSON(map[string]interface{}{
  88. "list": patientsOne,
  89. "total_one": total_one,
  90. "total_two": total_two,
  91. })
  92. } else if types == 2 { //已就诊
  93. var patientsTwo []*service.Schedule
  94. for _, item := range patients {
  95. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  96. patientsTwo = append(patientsTwo, item)
  97. }
  98. }
  99. c.ServeSuccessJSON(map[string]interface{}{
  100. "list": patientsTwo,
  101. "total_one": total_one,
  102. "total_two": total_two,
  103. })
  104. }
  105. }
  106. func (c *HisApiController) GetHisPatientInfo() {
  107. patient_id, _ := c.GetInt64("patient_id")
  108. record_date := c.GetString("record_date")
  109. number := c.GetString("number")
  110. timeLayout := "2006-01-02"
  111. loc, _ := time.LoadLocation("Local")
  112. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  113. if err != nil {
  114. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  115. return
  116. }
  117. recordDateTime := theTime.Unix()
  118. admin := c.GetAdminUserInfo()
  119. his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  120. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  121. prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  122. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  123. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  124. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  125. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  126. //addtions, _ := service.GetAllAdditionCharge(admin.CurrentOrgId, patient_id, recordDateTime)
  127. c.ServeSuccessJSON(map[string]interface{}{
  128. "his_info": his_patient_info,
  129. "xt_info": xt_patient_info,
  130. "prescription": prescriptions,
  131. "case_history": case_history,
  132. "info": patientPrescriptionInfo,
  133. "last_info": lastPatientPrescriptionInfo,
  134. "order": order,
  135. })
  136. return
  137. }
  138. func (c *HisApiController) GetHisPrescriptionConfig() {
  139. adminInfo := c.GetAdminUserInfo()
  140. //获取医嘱模版
  141. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  142. //获取所有基础药
  143. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  144. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  145. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  146. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  147. //获取所有科室信息
  148. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  149. //获取诊断信息
  150. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  151. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  152. //获取当前用户的信息
  153. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  154. c.ServeSuccessJSON(map[string]interface{}{
  155. "drugs": drugs,
  156. "advices_template": advices,
  157. "drugways": drugways,
  158. "efs": efs,
  159. "doctors": doctors,
  160. "department": department,
  161. "sick": sick,
  162. "info": adminUserInfo,
  163. "additions": additions,
  164. })
  165. }
  166. func (c *HisApiController) CreateHisPrescription() {
  167. record_date := c.GetString("record_date")
  168. patient_id, _ := c.GetInt64("patient_id")
  169. reg_type := c.GetString("reg_type")
  170. diagnose := c.GetString("diagnose")
  171. sick_history := c.GetString("sick_history")
  172. doctor_id, _ := c.GetInt64("doctor", 0)
  173. department, _ := c.GetInt64("department", 0)
  174. his_patient_id, _ := c.GetInt64("his_patient_id")
  175. dataBody := make(map[string]interface{}, 0)
  176. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  177. if err != nil {
  178. utils.ErrorLog(err.Error())
  179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  180. return
  181. }
  182. timeLayout := "2006-01-02"
  183. loc, _ := time.LoadLocation("Local")
  184. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  185. if err != nil {
  186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  187. return
  188. }
  189. adminInfo := c.GetAdminUserInfo()
  190. recordDateTime := theTime.Unix()
  191. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  192. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  193. var hpInfo models.HisPrescriptionInfo
  194. if info.ID == 0 {
  195. var randNum int
  196. randNum = rand.Intn(10000) + 1000
  197. timestamp := time.Now().Unix()
  198. tempTime := time.Unix(timestamp, 0)
  199. timeFormat := tempTime.Format("20060102150405")
  200. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  201. hpInfo = models.HisPrescriptionInfo{
  202. UserOrgId: adminInfo.CurrentOrgId,
  203. RecordDate: theTime.Unix(),
  204. PatientId: patient_id,
  205. Status: 1,
  206. Ctime: time.Now().Unix(),
  207. Mtime: time.Now().Unix(),
  208. Creator: adminInfo.AdminUser.Id,
  209. Modifier: adminInfo.AdminUser.Id,
  210. Diagnosis: diagnose,
  211. SickHistory: sick_history,
  212. Departments: department,
  213. RegisterType: reg_type,
  214. PrescriptionNumber: p_number,
  215. PrescriptionStatus: 1,
  216. Doctor: role.UserName,
  217. DoctorId: doctor_id,
  218. }
  219. service.SavePatientPrescriptionInfo(hpInfo)
  220. } else {
  221. hpInfo = models.HisPrescriptionInfo{
  222. ID: info.ID,
  223. UserOrgId: adminInfo.CurrentOrgId,
  224. RecordDate: info.RecordDate,
  225. PatientId: info.PatientId,
  226. Status: 1,
  227. Ctime: info.Ctime,
  228. Mtime: time.Now().Unix(),
  229. Creator: info.Creator,
  230. Modifier: adminInfo.AdminUser.Id,
  231. Diagnosis: diagnose,
  232. SickHistory: sick_history,
  233. Departments: department,
  234. RegisterType: reg_type,
  235. PrescriptionNumber: info.PrescriptionNumber,
  236. Doctor: role.UserName,
  237. PrescriptionStatus: info.PrescriptionStatus,
  238. DoctorId: doctor_id,
  239. }
  240. service.SavePatientPrescriptionInfo(hpInfo)
  241. }
  242. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  243. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  244. if len(prescriptions) > 0 {
  245. for _, item := range prescriptions {
  246. items := item.(map[string]interface{})
  247. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  248. utils.ErrorLog("id")
  249. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  250. return
  251. }
  252. id := int64(items["id"].(float64))
  253. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  254. utils.ErrorLog("type")
  255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  256. return
  257. }
  258. types := int64(items["type"].(float64))
  259. ctime := time.Now().Unix()
  260. prescription := &models.HisPrescription{
  261. ID: id,
  262. PatientId: patient_id,
  263. UserOrgId: adminInfo.CurrentOrgId,
  264. RecordDate: recordDateTime,
  265. Ctime: ctime,
  266. Mtime: ctime,
  267. Type: types,
  268. Modifier: adminInfo.AdminUser.Id,
  269. Creator: adminInfo.AdminUser.Id,
  270. Status: 1,
  271. Doctor: role.UserName,
  272. HisPatientId: his_patient_id,
  273. OrderStatus: 1,
  274. BatchNumber: "",
  275. PrescriptionNumber: hpInfo.PrescriptionNumber,
  276. }
  277. service.SaveHisPrescription(prescription)
  278. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  279. advices := items["advices"].([]interface{})
  280. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  281. groupNo := int64(0)
  282. ctime := time.Now().Unix()
  283. mtime := ctime
  284. if len(advices) > 0 {
  285. for _, advice := range advices {
  286. var s models.HisDoctorAdviceInfo
  287. s.PrescriptionId = prescription.ID
  288. s.AdviceType = 2
  289. s.AdviceDoctor = adminInfo.AdminUser.Id
  290. s.StopState = 2
  291. s.ExecutionState = 2
  292. s.AdviceDate = recordDateTime
  293. s.Status = 1
  294. s.UserOrgId = adminInfo.CurrentOrgId
  295. s.RecordDate = recordDateTime
  296. s.StartTime = recordDateTime
  297. s.Groupno = groupNo
  298. s.CreatedTime = ctime
  299. s.UpdatedTime = mtime
  300. s.PatientId = patient_id
  301. s.HisPatientId = his_patient_id
  302. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  303. if errcode > 0 {
  304. c.ServeFailJSONWithSGJErrorCode(errcode)
  305. return
  306. }
  307. service.CreateHisDoctorAdvice(&s)
  308. var randNum int
  309. randNum = rand.Intn(10000) + 1000
  310. timestamp := time.Now().Unix()
  311. tempTime := time.Unix(timestamp, 0)
  312. timeFormat := tempTime.Format("20060102150405")
  313. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  314. service.CreateHisDoctorAdvice(&s)
  315. }
  316. }
  317. }
  318. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  319. projects := items["project"].([]interface{})
  320. if len(projects) > 0 {
  321. for _, project := range projects {
  322. var p models.HisPrescriptionProject
  323. p.PrescriptionId = prescription.ID
  324. p.Ctime = time.Now().Unix()
  325. p.Mtime = time.Now().Unix()
  326. p.PatientId = patient_id
  327. p.RecordDate = recordDateTime
  328. p.UserOrgId = adminInfo.CurrentOrgId
  329. p.HisPatientId = his_patient_id
  330. p.Status = 1
  331. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  332. if errcode > 0 {
  333. c.ServeFailJSONWithSGJErrorCode(errcode)
  334. return
  335. }
  336. service.CreateHisProjectTwo(&p)
  337. var randNum int
  338. randNum = rand.Intn(10000) + 1000
  339. timestamp := time.Now().Unix()
  340. tempTime := time.Unix(timestamp, 0)
  341. timeFormat := tempTime.Format("20060102150405")
  342. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  343. service.SaveHisProjectTwo(&p)
  344. }
  345. }
  346. }
  347. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  348. addition := items["addition"].([]interface{})
  349. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  350. ctime := time.Now().Unix()
  351. mtime := ctime
  352. if len(addition) > 0 {
  353. for _, item := range addition {
  354. var s models.HisAdditionalCharge
  355. s.PrescriptionId = prescription.ID
  356. s.Status = 1
  357. s.UserOrgId = adminInfo.CurrentOrgId
  358. s.RecordDate = recordDateTime
  359. s.CreatedTime = ctime
  360. s.UpdatedTime = mtime
  361. s.PatientId = patient_id
  362. s.HisPatientId = his_patient_id
  363. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}))
  364. if errcode > 0 {
  365. c.ServeFailJSONWithSGJErrorCode(errcode)
  366. return
  367. }
  368. service.CreateAdditionalCharge(&s)
  369. var randNum int
  370. randNum = rand.Intn(10000) + 1000
  371. timestamp := time.Now().Unix()
  372. tempTime := time.Unix(timestamp, 0)
  373. timeFormat := tempTime.Format("20060102150405")
  374. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  375. service.CreateAdditionalCharge(&s)
  376. }
  377. }
  378. }
  379. }
  380. }
  381. }
  382. if err == nil {
  383. c.ServeSuccessJSON(map[string]interface{}{
  384. "msg": "保存成功",
  385. })
  386. return
  387. } else {
  388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  389. return
  390. }
  391. }
  392. func (c *HisApiController) DeletePrescription() {
  393. prescription_id, _ := c.GetInt64("id")
  394. //TODO 需要判断是否已经结算
  395. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  396. if err == nil {
  397. c.ServeSuccessJSON(map[string]interface{}{
  398. "msg": "删除成功",
  399. })
  400. return
  401. } else {
  402. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  403. return
  404. }
  405. }
  406. func (c *HisApiController) DeleteDoctorAdvice() {
  407. id, _ := c.GetInt64("id")
  408. //TODO 需要判断是否已经结算
  409. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  410. if err == nil {
  411. c.ServeSuccessJSON(map[string]interface{}{
  412. "msg": "删除成功",
  413. })
  414. return
  415. } else {
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  417. return
  418. }
  419. }
  420. func (c *HisApiController) DeleteProject() {
  421. id, _ := c.GetInt64("id")
  422. //TODO 需要判断是否已经结算
  423. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  424. if err == nil {
  425. c.ServeSuccessJSON(map[string]interface{}{
  426. "msg": "删除成功",
  427. })
  428. return
  429. } else {
  430. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  431. return
  432. }
  433. }
  434. func (c *HisApiController) CreateHisAdditionalCharge() {
  435. his_patient_id, _ := c.GetInt64("his_patient_id")
  436. patient_id, _ := c.GetInt64("patient_id")
  437. record_date := c.GetString("record_date")
  438. timeLayout := "2006-01-02"
  439. loc, _ := time.LoadLocation("Local")
  440. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  441. if err != nil {
  442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  443. return
  444. }
  445. adminInfo := c.GetAdminUserInfo()
  446. recordDateTime := theTime.Unix()
  447. dataBody := make(map[string]interface{}, 0)
  448. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  449. if err != nil {
  450. utils.ErrorLog(err.Error())
  451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  452. return
  453. }
  454. var additions []*models.HisAdditionalCharge
  455. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  456. additions, _ := dataBody["addition"].([]interface{})
  457. if len(additions) > 0 {
  458. for _, item := range additions {
  459. items := item.(map[string]interface{})
  460. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  461. utils.ErrorLog("item_id")
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  463. return
  464. }
  465. item_id := int64(items["item_id"].(float64))
  466. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  467. utils.ErrorLog("item_name")
  468. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  469. return
  470. }
  471. item_name := items["item_name"].(string)
  472. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  473. utils.ErrorLog("price")
  474. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  475. return
  476. }
  477. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  478. ctime := time.Now().Unix()
  479. additional := &models.HisAdditionalCharge{
  480. PatientId: patient_id,
  481. HisPatientId: his_patient_id,
  482. UserOrgId: adminInfo.CurrentOrgId,
  483. RecordDate: recordDateTime,
  484. CreatedTime: ctime,
  485. UpdatedTime: ctime,
  486. Modifier: adminInfo.AdminUser.Id,
  487. Creator: adminInfo.AdminUser.Id,
  488. Price: price,
  489. ItemName: item_name,
  490. ItemId: item_id,
  491. Status: 1,
  492. }
  493. additions = append(additions, additional)
  494. }
  495. }
  496. }
  497. for _, item := range additions {
  498. service.CreateAddtionalCharge(item)
  499. }
  500. c.ServeSuccessJSON(map[string]interface{}{
  501. "msg": "创建成功",
  502. })
  503. }
  504. func (c *HisApiController) CreateHisPatientCaseHistory() {
  505. blood_fat := c.GetString("blood_fat")
  506. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  507. fmt.Println("33333333", bloodfatfloat)
  508. blood_sugar := c.GetString("blood_sugar")
  509. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  510. fmt.Println(bloodsugarfloat)
  511. chief_conplaint := c.GetString("chief_conplaint")
  512. dbp := c.GetString("dbp")
  513. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  514. delivery_way, _ := c.GetInt64("delivery_way")
  515. diagnostic := c.GetString("diagnostic")
  516. fmt.Println("diagnostic", diagnostic)
  517. family_history := c.GetString("family_history")
  518. fmt.Println(family_history)
  519. height := c.GetString("height")
  520. history_of_present_illness := c.GetString("history_of_present_illness")
  521. is_infect, _ := c.GetInt64("is_infect")
  522. fmt.Println("is", is_infect)
  523. past_history := c.GetString("past_history")
  524. patient_id, _ := c.GetInt64("patient_id")
  525. his_patient_id, _ := c.GetInt64("his_patient_id")
  526. fmt.Println("patient_id", patient_id)
  527. personal_history := c.GetString("personal_history")
  528. pulse := c.GetString("pulse")
  529. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  530. sbp := c.GetString("sbp")
  531. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  532. heightfloat, _ := strconv.ParseFloat(height, 64)
  533. sicktype := c.GetString("sick_type")
  534. fmt.Println("sicketype", sicktype)
  535. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  536. symptom := c.GetString("symptom")
  537. sick_date := c.GetString("sick_date")
  538. temperatures := c.GetString("temperature")
  539. fmt.Println("temperatures", temperatures)
  540. temperature, _ := strconv.ParseFloat(temperatures, 64)
  541. record_date := c.GetString("record_date")
  542. breathing := c.GetString("breathing")
  543. doctor_advice := c.GetString("doctor_advice")
  544. remark := c.GetString("remark")
  545. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  546. fmt.Println("breathingfloat", breathingfloat)
  547. timeLayout := "2006-01-02"
  548. loc, _ := time.LoadLocation("Local")
  549. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  550. if err != nil {
  551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  552. return
  553. }
  554. recordDateTime := theTime.Unix()
  555. fmt.Println("recordDataTime", recordDateTime)
  556. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  557. if err != nil {
  558. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  559. return
  560. }
  561. sickTimes := sickTime.Unix()
  562. ctime := time.Now().Unix()
  563. caseHistory := models.HisPatientCaseHistory{
  564. HisPatientId: his_patient_id,
  565. PatientId: patient_id,
  566. Temperature: temperature,
  567. BloodSugar: bloodsugarfloat,
  568. Pulse: pulsefloat,
  569. Sbp: sbpfloat,
  570. Dbp: dbpfloat,
  571. Height: heightfloat,
  572. BloodFat: bloodfatfloat,
  573. SickType: sick_type,
  574. Symptom: symptom,
  575. SickDate: sickTimes,
  576. IsInfect: is_infect,
  577. HistoryOfPresentIllness: history_of_present_illness,
  578. PastHistory: past_history,
  579. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  580. ChiefConplaint: chief_conplaint,
  581. PersonalHistory: personal_history,
  582. FamilyHistory: family_history,
  583. Diagnostic: diagnostic,
  584. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  585. Status: 1,
  586. Ctime: ctime,
  587. Mtime: ctime,
  588. RecordDate: recordDateTime,
  589. DeliveryWay: delivery_way,
  590. Breathing: breathingfloat,
  591. DoctorAdvice: doctor_advice,
  592. Remark: remark,
  593. }
  594. err = service.SaveHisPatientCaseHistory(&caseHistory)
  595. if err != nil {
  596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  597. return
  598. }
  599. c.ServeSuccessJSON(map[string]interface{}{
  600. "caseHistory": caseHistory,
  601. })
  602. return
  603. //查询该患者是否有病历
  604. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  605. //if errcode == gorm.ErrRecordNotFound {
  606. // err = service.SaveHisPatientCaseHistory(caseHistory)
  607. // if err != nil {
  608. // c.ServeSuccessJSON(map[string]interface{}{
  609. // "msg": "保存成功",
  610. // })
  611. // }
  612. //} else if errcode == nil {
  613. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  614. // return
  615. //}
  616. }
  617. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  618. patient_id, _ := c.GetInt64("patient_id", 0)
  619. adminUser := c.GetAdminUserInfo()
  620. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  621. c.ServeSuccessJSON(map[string]interface{}{
  622. "list": caseHistorys,
  623. })
  624. }
  625. func (c *HisApiController) GetHisPatientCaseHistory() {
  626. record_date, _ := c.GetInt64("record_date", 0)
  627. patient_id, _ := c.GetInt64("patient_id", 0)
  628. admin := c.GetAdminUserInfo()
  629. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  630. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  631. c.ServeSuccessJSON(map[string]interface{}{
  632. "info": info,
  633. "case_history": case_history,
  634. })
  635. }
  636. func (c *HisApiController) CreateCaseHistoryTemplate() {
  637. template_name := c.GetString("template_name")
  638. fmt.Println("template_name22222222222222", template_name)
  639. template_remark := c.GetString("template_remark")
  640. doctor := c.GetAdminUserInfo().AdminUser.Id
  641. diagnostic := c.GetString("diagnostic")
  642. chief_conplaint := c.GetString("chief_conplain")
  643. history_of_present_illness := c.GetString("history_of_present_illness")
  644. past_history := c.GetString("past_history")
  645. personal_history := c.GetString("personal_history")
  646. family_history := c.GetString("family_history")
  647. user_name := c.GetString("user_name")
  648. //record_date := c.GetString("record_date")
  649. //fmt.Println("record_date--------",record_date)
  650. //timeLayout := "2006-01-02"
  651. //loc, _ := time.LoadLocation("Local")
  652. //
  653. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  654. //if err != nil {
  655. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  656. // return
  657. //}
  658. //recordDateTime := theTime.Unix()
  659. ctime := time.Now().Unix()
  660. template := models.HisCaseHistoryTemplate{
  661. HistoryOfPresentIllness: history_of_present_illness,
  662. PastHistory: past_history,
  663. ChiefConplaint: chief_conplaint,
  664. PersonalHistory: personal_history,
  665. FamilyHistory: family_history,
  666. Diagnostic: diagnostic,
  667. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  668. Status: 1,
  669. Ctime: ctime,
  670. Mtime: ctime,
  671. RecordDate: time.Now().Unix(),
  672. TemplateName: template_name,
  673. TemplateRemark: template_remark,
  674. Creator: doctor,
  675. Modifier: doctor,
  676. UserName: user_name,
  677. }
  678. err := service.SaveHisPatientCaseHistoryTemplate(template)
  679. if err == nil {
  680. c.ServeSuccessJSON(map[string]interface{}{
  681. "msg": "保存成功",
  682. })
  683. } else {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  685. return
  686. }
  687. }
  688. func (c *HisApiController) GetCaseHistoryTemplate() {
  689. timeLayout := "2006-01-02"
  690. loc, _ := time.LoadLocation("Local")
  691. keyword := c.GetString("keyword")
  692. start_time := c.GetString("start_time")
  693. end_time := c.GetString("end_time")
  694. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  695. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  696. admin := c.GetAdminUserInfo()
  697. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  698. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  699. c.ServeSuccessJSON(map[string]interface{}{
  700. "template": template,
  701. //"history": history,
  702. })
  703. }
  704. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  705. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  706. utils.ErrorLog("drug_name")
  707. return enums.ErrorCodeParamWrong
  708. }
  709. adviceName, _ := json["drug_name"].(string)
  710. if len(adviceName) == 0 {
  711. utils.ErrorLog("len(advice_name) == 0")
  712. return enums.ErrorCodeParamWrong
  713. }
  714. advice.AdviceName = adviceName
  715. adviceDesc, _ := json["advice_desc"].(string)
  716. advice.AdviceDesc = adviceDesc
  717. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  718. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  719. advice.DrugSpec = drugSpec
  720. }
  721. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  722. remark, _ := json["remark"].(string)
  723. advice.Remark = remark
  724. }
  725. if json["id"] == nil {
  726. advice.DrugId = 0
  727. } else {
  728. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  729. drug_id := int64(json["id"].(float64))
  730. advice.DrugId = drug_id
  731. }
  732. }
  733. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  734. advice_id := int64(json["advice_id"].(float64))
  735. advice.ID = advice_id
  736. }
  737. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  738. drugSpecUnit, _ := json["min_unit"].(string)
  739. advice.DrugSpecUnit = drugSpecUnit
  740. }
  741. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  742. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  743. advice.SingleDose = singleDose
  744. }
  745. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  746. singleDoseUnit, _ := json["single_dose_unit"].(string)
  747. advice.SingleDoseUnit = singleDoseUnit
  748. }
  749. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  750. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  751. advice.PrescribingNumber = prescribingNumber
  752. }
  753. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  754. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  755. advice.PrescribingNumberUnit = prescribingNumberUnit
  756. }
  757. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  758. deliveryWay, _ := json["delivery_way"].(string)
  759. advice.DeliveryWay = deliveryWay
  760. }
  761. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  762. executionFrequency, _ := json["execution_frequency"].(string)
  763. advice.ExecutionFrequency = executionFrequency
  764. }
  765. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  766. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  767. advice.Price = price
  768. }
  769. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  770. med_list_codg, _ := json["medical_insurance_number"].(string)
  771. advice.MedListCodg = med_list_codg
  772. }
  773. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  774. day := int64(json["day"].(float64))
  775. advice.Day = day
  776. }
  777. return 0
  778. }
  779. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  780. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  781. id := int64(json["id"].(float64))
  782. project.ID = id
  783. }
  784. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  785. project_id := int64(json["project_id"].(float64))
  786. project.ProjectId = project_id
  787. fmt.Println(project_id)
  788. fmt.Println(project.ProjectId)
  789. }
  790. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  791. price := int64(json["price"].(float64))
  792. formatInt_price := strconv.FormatInt(price, 10)
  793. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  794. project.Price = float_price
  795. }
  796. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  797. total, _ := json["total"].(string)
  798. totals, _ := strconv.ParseInt(total, 10, 64)
  799. project.Count = totals
  800. }
  801. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  802. medical_code, _ := json["medical_code"].(string)
  803. project.MedListCodg = medical_code
  804. }
  805. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  806. single_dose, _ := json["single_dose"].(string)
  807. project.SingleDose = single_dose
  808. }
  809. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  810. delivery_way, _ := json["delivery_way"].(string)
  811. project.DeliveryWay = delivery_way
  812. }
  813. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  814. execution_frequency, _ := json["execution_frequency"].(string)
  815. project.ExecutionFrequency = execution_frequency
  816. }
  817. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  818. remark, _ := json["remark"].(string)
  819. project.Remark = remark
  820. }
  821. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  822. day, _ := json["number_days"].(string)
  823. project.Day = day
  824. }
  825. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  826. unit, _ := json["unit"].(string)
  827. project.Unit = unit
  828. }
  829. return 0
  830. }
  831. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}) int {
  832. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  833. id := int64(json["id"].(float64))
  834. additionalCharge.ID = id
  835. }
  836. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  837. item_id := int64(json["item_id"].(float64))
  838. additionalCharge.ItemId = item_id
  839. }
  840. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  841. price := int64(json["price"].(float64))
  842. formatInt_price := strconv.FormatInt(price, 10)
  843. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  844. additionalCharge.Price = float_price
  845. }
  846. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  847. count, _ := json["count"].(string)
  848. counts, _ := strconv.ParseInt(count, 10, 64)
  849. additionalCharge.Count = counts
  850. }
  851. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  852. item_name, _ := json["item_name"].(string)
  853. additionalCharge.ItemName = item_name
  854. }
  855. return 0
  856. }
  857. func (c *HisApiController) GetHisOrderList() {
  858. page, _ := c.GetInt64("page", -1)
  859. limit, _ := c.GetInt64("limit", -1)
  860. start_time := c.GetString("start_time")
  861. end_time := c.GetString("end_time")
  862. types, _ := c.GetInt64("type", 0)
  863. keywords := c.GetString("keywords")
  864. timeLayout := "2006-01-02"
  865. loc, _ := time.LoadLocation("Local")
  866. var startTime int64
  867. if len(start_time) > 0 {
  868. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  869. if err != nil {
  870. fmt.Println(err)
  871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  872. return
  873. }
  874. startTime = theTime.Unix()
  875. }
  876. var endTime int64
  877. if len(end_time) > 0 {
  878. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  879. if err != nil {
  880. utils.ErrorLog(err.Error())
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  882. return
  883. }
  884. endTime = theTime.Unix()
  885. }
  886. adminUser := c.GetAdminUserInfo()
  887. org_id := adminUser.CurrentOrgId
  888. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
  889. if err == nil {
  890. c.ServeSuccessJSON(map[string]interface{}{
  891. "order": order,
  892. "total": total,
  893. })
  894. } else {
  895. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  896. return
  897. }
  898. }
  899. func (c *HisApiController) GetHisOrder() {
  900. patient_id, _ := c.GetInt64("patient_id", 0)
  901. number := c.GetString("number")
  902. adminInfo := c.GetAdminUserInfo()
  903. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  904. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
  905. if err == nil {
  906. c.ServeSuccessJSON(map[string]interface{}{
  907. "order": order,
  908. "prescription": prescriptions,
  909. })
  910. } else {
  911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  912. return
  913. }
  914. }
  915. func (c *HisApiController) GetHisPrescriptionList() {
  916. record_date := c.GetString("record_date")
  917. keywords := c.GetString("keywords")
  918. page, _ := c.GetInt64("page")
  919. limit, _ := c.GetInt64("limit")
  920. timeLayout := "2006-01-02"
  921. loc, _ := time.LoadLocation("Local")
  922. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  923. if err != nil {
  924. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  925. return
  926. }
  927. recordDateTime := theTime.Unix()
  928. adminInfo := c.GetAdminUserInfo()
  929. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  930. //adminInfo := c.GetAdminUserInfo()
  931. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  932. //fmt.Println(prescriptionOrder)
  933. if err == nil {
  934. c.ServeSuccessJSON(map[string]interface{}{
  935. "order": prescriptionOrder,
  936. "total": total,
  937. })
  938. } else {
  939. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  940. return
  941. }
  942. }
  943. func (c *HisApiController) GetHisPrescriptionInfo() {
  944. id, _ := c.GetInt64("id")
  945. adminInfo := c.GetAdminUserInfo()
  946. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  947. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  948. if err == nil {
  949. c.ServeSuccessJSON(map[string]interface{}{
  950. "order": prescriptionOrder,
  951. "prescription": prescription,
  952. })
  953. } else {
  954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  955. return
  956. }
  957. }
  958. func (c *HisApiController) GetMedicalInsuranceConfig() {
  959. adminUser := c.GetAdminUserInfo()
  960. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  961. c.ServeSuccessJSON(map[string]interface{}{
  962. "config": config,
  963. })
  964. }
  965. type ResultTwo struct {
  966. ErrMsg interface{} `json:"err_msg"`
  967. InfRefmsgid string `json:"inf_refmsgid"`
  968. Infcode int64 `json:"infcode"`
  969. Output struct {
  970. Baseinfo struct {
  971. Age float64 `json:"age"`
  972. Brdy string `json:"brdy"`
  973. Certno string `json:"certno"`
  974. Gend string `json:"gend"`
  975. Naty string `json:"naty"`
  976. PsnCertType string `json:"psn_cert_type"`
  977. PsnName string `json:"psn_name"`
  978. PsnNo string `json:"psn_no"`
  979. } `json:"baseinfo"`
  980. Idetinfo []interface{} `json:"idetinfo"`
  981. Iinfo []struct {
  982. Balc int64 `json:"balc"`
  983. CvlservFlag string `json:"cvlserv_flag"`
  984. EmpName string `json:"emp_name"`
  985. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  986. Insutype string `json:"insutype"`
  987. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  988. PausInsuDate interface{} `json:"paus_insu_date"`
  989. PsnInsuDate string `json:"psn_insu_date"`
  990. PsnInsuStas string `json:"psn_insu_stas"`
  991. PsnType string `json:"psn_type"`
  992. } `json:"insuinfo"`
  993. } `json:"output"`
  994. RefmsgTime string `json:"refmsg_time"`
  995. RespondTime string `json:"respond_time"`
  996. Signtype interface{} `json:"signtype"`
  997. WarnInfo interface{} `json:"warn_info"`
  998. }
  999. type ResultThree struct {
  1000. Cainfo interface{} `json:"cainfo"`
  1001. ErrMsg interface{} `json:"err_msg"`
  1002. InfRefmsgid string `json:"inf_refmsgid"`
  1003. Infcode int64 `json:"infcode"`
  1004. Output struct {
  1005. Data struct {
  1006. IptOtpNo string `json:"ipt_otp_no"`
  1007. MdtrtID string `json:"mdtrt_id"`
  1008. PsnNo string `json:"psn_no"`
  1009. } `json:"data"`
  1010. } `json:"output"`
  1011. RefmsgTime string `json:"refmsg_time"`
  1012. RespondTime string `json:"respond_time"`
  1013. Signtype interface{} `json:"signtype"`
  1014. WarnMsg interface{} `json:"warn_msg"`
  1015. }
  1016. type ResultFour struct {
  1017. Cainfo string `json:"cainfo"`
  1018. ErrMsg string `json:"err_msg"`
  1019. InfRefmsgid string `json:"inf_refmsgid"`
  1020. Infcode int64 `json:"infcode"`
  1021. Output struct {
  1022. Result []struct {
  1023. BasMednFlag string `json:"bas_medn_flag"`
  1024. ChldMedcFlag string `json:"chld_medc_flag"`
  1025. ChrgitmLv string `json:"chrgitm_lv"`
  1026. Cnt float64 `json:"cnt"`
  1027. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1028. DrtReimFlag string `json:"drt_reim_flag"`
  1029. FeedetlSn string `json:"feedetl_sn"`
  1030. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1031. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1032. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1033. ListSpItemFlag string `json:"list_sp_item_flag"`
  1034. LmtUsedFlag string `json:"lmt_used_flag"`
  1035. MedChrgitmType string `json:"med_chrgitm_type"`
  1036. Memo string `json:"memo"`
  1037. OverlmtAmt float64 `json:"overlmt_amt"`
  1038. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1039. Pric float64 `json:"pric"`
  1040. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1041. SelfpayProp float64 `json:"selfpay_prop"`
  1042. } `json:"result"`
  1043. } `json:"output"`
  1044. RefmsgTime string `json:"refmsg_time"`
  1045. RespondTime string `json:"respond_time"`
  1046. Signtype string `json:"signtype"`
  1047. WarnMsg string `json:"warn_msg"`
  1048. }
  1049. type ResultFive struct {
  1050. Insutype string `json:"insutype"`
  1051. }
  1052. type ResultSix struct {
  1053. Cainfo interface{} `json:"cainfo"`
  1054. ErrMsg interface{} `json:"err_msg"`
  1055. InfRefmsgid string `json:"inf_refmsgid"`
  1056. Infcode int64 `json:"infcode"`
  1057. Output struct {
  1058. } `json:"output"`
  1059. RefmsgTime string `json:"refmsg_time"`
  1060. RespondTime string `json:"respond_time"`
  1061. Signtype interface{} `json:"signtype"`
  1062. WarnMsg interface{} `json:"warn_msg"`
  1063. }
  1064. type ResultSeven struct {
  1065. Cainfo string `json:"cainfo"`
  1066. ErrMsg string `json:"err_msg"`
  1067. InfRefmsgid string `json:"inf_refmsgid"`
  1068. Infcode int64 `json:"infcode"`
  1069. Output struct {
  1070. Setldetail []interface{} `json:"setldetail"`
  1071. Setlinfo struct {
  1072. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1073. AcctPay float64 `json:"acct_pay"`
  1074. ActPayDedc float64 `json:"act_pay_dedc"`
  1075. Age float64 `json:"age"`
  1076. Balc float64 `json:"balc"`
  1077. Brdy string `json:"brdy"`
  1078. Certno string `json:"certno"`
  1079. ClrOptins string `json:"clr_optins"`
  1080. ClrType string `json:"clr_type"`
  1081. ClrWay string `json:"clr_way"`
  1082. CvlservFlag string `json:"cvlserv_flag"`
  1083. CvlservPay float64 `json:"cvlserv_pay"`
  1084. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1085. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1086. Gend string `json:"gend"`
  1087. HifesPay float64 `json:"hifes_pay"`
  1088. HifmiPay float64 `json:"hifmi_pay"`
  1089. HifobPay float64 `json:"hifob_pay"`
  1090. HifpPay float64 `json:"hifp_pay"`
  1091. HospPartAmt float64 `json:"hosp_part_amt"`
  1092. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1093. Insutype string `json:"insutype"`
  1094. MafPay float64 `json:"maf_pay"`
  1095. MdtrtCertType string `json:"mdtrt_cert_type"`
  1096. MdtrtID string `json:"mdtrt_id"`
  1097. MedType string `json:"med_type"`
  1098. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1099. MedinsSetlID string `json:"medins_setl_id"`
  1100. Naty string `json:"naty"`
  1101. OthPay float64 `json:"oth_pay"`
  1102. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1103. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1104. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1105. PsnCashPay float64 `json:"psn_cash_pay"`
  1106. PsnCertType string `json:"psn_cert_type"`
  1107. PsnName string `json:"psn_name"`
  1108. PsnNo string `json:"psn_no"`
  1109. PsnPartAmt float64 `json:"psn_part_amt"`
  1110. PsnType string `json:"psn_type"`
  1111. SetlID string `json:"setl_id"`
  1112. SetlTime string `json:"setl_time"`
  1113. } `json:"setlinfo"`
  1114. } `json:"output"`
  1115. RefmsgTime string `json:"refmsg_time"`
  1116. RespondTime string `json:"respond_time"`
  1117. Signtype interface{} `json:"signtype"`
  1118. WarnMsg interface{} `json:"warn_msg"`
  1119. }
  1120. type Custom struct {
  1121. DetItemFeeSumamt string
  1122. Cut string
  1123. FeedetlSn string
  1124. Price string
  1125. MedListCodg string
  1126. Type int64
  1127. AdviceId int64
  1128. ProjectId int64
  1129. ItemId int64
  1130. }
  1131. //获取个人信息----挂号-----上传就诊信息
  1132. func (c *HisApiController) GetRegisterInfo() {
  1133. id, _ := c.GetInt64("id")
  1134. record_time := c.GetString("record_time")
  1135. timeLayout := "2006-01-02"
  1136. loc, _ := time.LoadLocation("Local")
  1137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1138. if err != nil {
  1139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1140. return
  1141. }
  1142. recordDateTime := theTime.Unix()
  1143. adminInfo := c.GetAdminUserInfo()
  1144. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1145. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1146. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1147. if patient == nil {
  1148. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1149. return
  1150. }
  1151. if len(patient.IdCardNo) == 0 {
  1152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1153. return
  1154. }
  1155. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1156. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1157. if config.IsOpen == 1 {
  1158. api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code
  1159. resp, requestErr := http.Get(api)
  1160. if requestErr != nil {
  1161. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1162. return
  1163. }
  1164. defer resp.Body.Close()
  1165. body, ioErr := ioutil.ReadAll(resp.Body)
  1166. if ioErr != nil {
  1167. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1169. return
  1170. }
  1171. var respJSON map[string]interface{}
  1172. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1173. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1174. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1175. return
  1176. }
  1177. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1178. userJSONBytes, _ := json.Marshal(userJSON)
  1179. var res ResultTwo
  1180. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1181. utils.ErrorLog("解析失败:%v", err)
  1182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1183. return
  1184. }
  1185. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1186. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1187. infoStr := string(Iinfos)
  1188. idetinfoStr := string(Idetinfos)
  1189. his := models.VMHisPatient{
  1190. PsnNo: res.Output.Baseinfo.PsnNo,
  1191. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1192. Certno: res.Output.Baseinfo.Certno,
  1193. PsnName: res.Output.Baseinfo.PsnName,
  1194. Gend: res.Output.Baseinfo.Gend,
  1195. Naty: res.Output.Baseinfo.Naty,
  1196. Brdy: res.Output.Baseinfo.Brdy,
  1197. Age: res.Output.Baseinfo.Age,
  1198. Iinfo: infoStr,
  1199. Idetinfo: idetinfoStr,
  1200. PatientId: patient.ID,
  1201. RecordDate: theTime.Unix(),
  1202. }
  1203. fmt.Println(his)
  1204. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1206. return
  1207. }
  1208. timestamp := time.Now().Unix()
  1209. tempTime := time.Unix(timestamp, 0)
  1210. timeFormat := tempTime.Format("20060102150405")
  1211. chrgBchno := rand.Intn(100000) + 10000
  1212. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1213. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1214. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1215. if count <= 0 {
  1216. api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1217. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1218. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1219. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code
  1220. resp, requestErr := http.Get(api)
  1221. if requestErr != nil {
  1222. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1223. return
  1224. }
  1225. defer resp.Body.Close()
  1226. body, ioErr := ioutil.ReadAll(resp.Body)
  1227. if ioErr != nil {
  1228. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1230. return
  1231. }
  1232. var respJSON map[string]interface{}
  1233. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1234. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1235. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1236. return
  1237. }
  1238. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1239. userJSONBytes, _ := json.Marshal(respJSON)
  1240. var res ResultThree
  1241. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1242. utils.ErrorLog("解析失败:%v", err)
  1243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1244. return
  1245. }
  1246. if res.Infcode == -1 {
  1247. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1248. return
  1249. }
  1250. fmt.Println("000!!!!!!")
  1251. fmt.Println(res)
  1252. fmt.Println(res.Output.Data.MdtrtID)
  1253. fmt.Println(res.Output.Data.PsnNo)
  1254. fmt.Println(res.Output.Data.IptOtpNo)
  1255. his.Number = res.Output.Data.MdtrtID
  1256. his.PsnNo = res.Output.Data.PsnNo
  1257. his.IptOtpNo = res.Output.Data.IptOtpNo
  1258. his.IdCardNo = patient.IdCardNo
  1259. his.PhoneNumber = patient.Phone
  1260. his.UserOrgId = adminInfo.CurrentOrgId
  1261. his.Status = 1
  1262. his.Ctime = time.Now().Unix()
  1263. his.Mtime = time.Now().Unix()
  1264. err := service.CreateHisPatientTwo(&his)
  1265. if err == nil {
  1266. api := "http://127.0.0.1:9531/" + "gdyb/four?psn_no=" + his.PsnNo +
  1267. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1268. "&diag=" + patientPrescription.Diagnosis + "&org_name=" + miConfig.OrgName + "&med_type=" + "11" + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code
  1269. resp, requestErr := http.Get(api)
  1270. if requestErr != nil {
  1271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1272. return
  1273. }
  1274. body, ioErr := ioutil.ReadAll(resp.Body)
  1275. if ioErr != nil {
  1276. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1278. return
  1279. }
  1280. var respJSON map[string]interface{}
  1281. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1282. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1284. return
  1285. }
  1286. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1287. userJSONBytes, _ := json.Marshal(respJSON)
  1288. fmt.Println(respJSON)
  1289. fmt.Println(userJSONBytes)
  1290. var res ResultSix
  1291. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1292. utils.ErrorLog("解析失败:%v", err)
  1293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1294. return
  1295. }
  1296. if res.Infcode == -1 {
  1297. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1298. return
  1299. }
  1300. c.ServeSuccessJSON(map[string]interface{}{
  1301. "his_info": his,
  1302. })
  1303. } else {
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1305. return
  1306. }
  1307. }
  1308. } else {
  1309. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1310. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1311. patient := models.XtHisPatient{
  1312. Age: patient.Age,
  1313. Birthday: patient.Birthday,
  1314. AdminUserId: adminInfo.AdminUser.Id,
  1315. IdCardNo: patient.IdCardNo,
  1316. Name: patient.Name,
  1317. Gender: patient.Gender,
  1318. UserOrgId: adminInfo.CurrentOrgId,
  1319. Status: 1,
  1320. RecordDate: recordDateTime,
  1321. IsReturn: 1,
  1322. PatientId: patient.ID,
  1323. Ctime: time.Now().Unix(),
  1324. Mtime: time.Now().Unix(),
  1325. }
  1326. service.CreateHisPatient(&patient)
  1327. }
  1328. c.ServeSuccessJSON(map[string]interface{}{
  1329. "his_info": patient,
  1330. })
  1331. }
  1332. }
  1333. //上传明细----结算
  1334. func (c *HisApiController) GetUploadInfo() {
  1335. id, _ := c.GetInt64("id")
  1336. record_time := c.GetString("record_time")
  1337. timeLayout := "2006-01-02"
  1338. loc, _ := time.LoadLocation("Local")
  1339. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1340. if err != nil {
  1341. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1342. return
  1343. }
  1344. recordDateTime := theTime.Unix()
  1345. adminUser := c.GetAdminUserInfo()
  1346. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1347. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1348. timestamp := time.Now().Unix()
  1349. tempTime := time.Unix(timestamp, 0)
  1350. timeFormat := tempTime.Format("20060102150405")
  1351. chrgBchno := rand.Intn(100000) + 10000
  1352. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1353. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1354. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1355. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1356. client := &http.Client{}
  1357. data := make(map[string]interface{})
  1358. data["psn_no"] = his.PsnNo
  1359. data["mdtrt_id"] = his.Number
  1360. data["pre"] = prescriptions
  1361. data["chrg_bchno"] = chrg_bchno
  1362. data["org_name"] = miConfig.OrgName
  1363. data["doctor"] = patientPrescription.Doctor
  1364. data["dept"] = patientPrescription.Departments
  1365. data["fixmedins_code"] = miConfig.Code
  1366. var ids []int64
  1367. //var idsTwo []int64
  1368. //
  1369. for _, item := range prescriptions {
  1370. ids = append(ids, item.ID)
  1371. }
  1372. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1373. if config.IsOpen == 1 { //对接了医保,走医保流程
  1374. bytesData, _ := json.Marshal(data)
  1375. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  1376. resp, _ := client.Do(req)
  1377. defer resp.Body.Close()
  1378. body, ioErr := ioutil.ReadAll(resp.Body)
  1379. if ioErr != nil {
  1380. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1382. return
  1383. }
  1384. var respJSON map[string]interface{}
  1385. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1386. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1388. return
  1389. }
  1390. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1391. userJSONBytes, _ := json.Marshal(respJSON)
  1392. var res ResultFour
  1393. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1394. utils.ErrorLog("解析失败:%v", err)
  1395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1396. return
  1397. }
  1398. if res.Infcode == 0 {
  1399. order := &models.HisOrder{
  1400. UserOrgId: adminUser.CurrentOrgId,
  1401. HisPatientId: his.ID,
  1402. PatientId: his.PatientId,
  1403. SettleAccountsDate: recordDateTime,
  1404. Ctime: time.Now().Unix(),
  1405. Mtime: time.Now().Unix(),
  1406. Status: 1,
  1407. Number: chrg_bchno,
  1408. Infcode: res.Infcode,
  1409. WarnMsg: res.WarnMsg,
  1410. Cainfo: res.Cainfo,
  1411. ErrMsg: res.ErrMsg,
  1412. RespondTime: res.RefmsgTime,
  1413. InfRefmsgid: res.InfRefmsgid,
  1414. OrderStatus: 1,
  1415. }
  1416. err = service.CreateOrder(order)
  1417. if err != nil {
  1418. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1419. return
  1420. }
  1421. for _, item := range res.Output.Result {
  1422. temp := strings.Split(item.FeedetlSn, "-")
  1423. var advice_id int64 = 0
  1424. var project_id int64 = 0
  1425. var types int64 = 0
  1426. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1427. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1428. if temp[1] == "1" {
  1429. advice_id = id
  1430. project_id = 0
  1431. } else if temp[1] == "2" {
  1432. advice_id = 0
  1433. project_id = id
  1434. }
  1435. info := &models.HisOrderInfo{
  1436. OrderNumber: order.Number,
  1437. FeedetlSn: item.FeedetlSn,
  1438. UploadDate: time.Now().Unix(),
  1439. AdviceId: advice_id,
  1440. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1441. Cnt: item.Cnt,
  1442. Pric: float64(item.Pric),
  1443. PatientId: his.PatientId,
  1444. PricUplmtAmt: item.PricUplmtAmt,
  1445. SelfpayProp: item.SelfpayProp,
  1446. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1447. OverlmtAmt: item.OverlmtAmt,
  1448. PreselfpayAmt: item.PreselfpayAmt,
  1449. BasMednFlag: item.BasMednFlag,
  1450. MedChrgitmType: item.MedChrgitmType,
  1451. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1452. Status: 1,
  1453. Memo: item.Memo,
  1454. Mtime: time.Now().Unix(),
  1455. InscpScpAmt: item.InscpScpAmt,
  1456. DrtReimFlag: item.DrtReimFlag,
  1457. Ctime: time.Now().Unix(),
  1458. ListSpItemFlag: item.ListSpItemFlag,
  1459. ChldMedcFlag: item.ChldMedcFlag,
  1460. LmtUsedFlag: item.LmtUsedFlag,
  1461. ChrgitmLv: item.ChrgitmLv,
  1462. UserOrgId: adminUser.CurrentOrgId,
  1463. HisPatientId: his.ID,
  1464. OrderId: order.ID,
  1465. ProjectId: project_id,
  1466. Type: types,
  1467. }
  1468. service.CreateOrderInfo(info)
  1469. }
  1470. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1471. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1472. var total float64
  1473. for _, item := range prescriptions {
  1474. if item.Type == 1 { //药品
  1475. for _, subItem := range item.HisDoctorAdviceInfo {
  1476. total = total + (subItem.Price * subItem.PrescribingNumber)
  1477. }
  1478. }
  1479. if item.Type == 2 { //项目
  1480. for _, subItem := range item.HisPrescriptionProject {
  1481. total = total + (subItem.Price * float64(subItem.Count))
  1482. }
  1483. }
  1484. }
  1485. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1486. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1487. allTotal := fmt.Sprintf("%.2f", total)
  1488. if res.Infcode == 0 {
  1489. var rf []*ResultFive
  1490. json.Unmarshal([]byte(his.Iinfo), &rf)
  1491. psn_no := his.PsnNo
  1492. mdtrt_id := his.Number
  1493. chrg_bchno := chrg_bchno
  1494. cert_no := his.Certno
  1495. insutype := rf[0].Insutype
  1496. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1497. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1498. "&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code
  1499. resp, requestErr := http.Get(api)
  1500. if requestErr != nil {
  1501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1502. return
  1503. }
  1504. defer resp.Body.Close()
  1505. body, ioErr := ioutil.ReadAll(resp.Body)
  1506. if ioErr != nil {
  1507. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1508. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1509. return
  1510. }
  1511. var respJSON map[string]interface{}
  1512. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1513. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1515. return
  1516. }
  1517. fmt.Println(respJSON)
  1518. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1519. userJSONBytes, _ := json.Marshal(respJSON)
  1520. var res ResultSeven
  1521. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1522. utils.ErrorLog("解析失败:%v", err)
  1523. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1524. return
  1525. }
  1526. if res.Infcode == -1 {
  1527. errlog := &models.HisOrderError{
  1528. UserOrgId: adminUser.CurrentOrgId,
  1529. Ctime: time.Now().Unix(),
  1530. Mtime: time.Now().Unix(),
  1531. Number: chrg_bchno,
  1532. ErrMsg: res.ErrMsg,
  1533. Status: 1,
  1534. PatientId: id,
  1535. RecordTime: recordDateTime,
  1536. Stage: 7,
  1537. }
  1538. service.CreateErrMsgLog(errlog)
  1539. } else {
  1540. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1541. order.OrderStatus = 2
  1542. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1543. order.SetlId = res.Output.Setlinfo.SetlID
  1544. order.PsnNo = res.Output.Setlinfo.PsnNo
  1545. order.PsnName = res.Output.Setlinfo.PsnName
  1546. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1547. order.Certno = res.Output.Setlinfo.Certno
  1548. order.Gend = res.Output.Setlinfo.Gend
  1549. order.Naty = res.Output.Setlinfo.Naty
  1550. order.Age = res.Output.Setlinfo.Age
  1551. order.Insutype = res.Output.Setlinfo.Insutype
  1552. order.PsnType = res.Output.Setlinfo.PsnType
  1553. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1554. order.SetlTime = res.Output.Setlinfo.SetlTime
  1555. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1556. order.MedType = res.Output.Setlinfo.MedType
  1557. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1558. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1559. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1560. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1561. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1562. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1563. order.HifpPay = res.Output.Setlinfo.HifpPay
  1564. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1565. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1566. order.HifesPay = res.Output.Setlinfo.HifesPay
  1567. order.HifobPay = res.Output.Setlinfo.HifobPay
  1568. order.MafPay = res.Output.Setlinfo.MafPay
  1569. order.OthPay = res.Output.Setlinfo.OthPay
  1570. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1571. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1572. order.AcctPay = res.Output.Setlinfo.AcctPay
  1573. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1574. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1575. order.Balc = res.Output.Setlinfo.Balc
  1576. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1577. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1578. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1579. order.ClrWay = res.Output.Setlinfo.ClrWay
  1580. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1581. detailStr := string(setlDetail)
  1582. order.SetlDetail = detailStr
  1583. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1584. err = service.UpDateOrder(order)
  1585. if err == nil {
  1586. c.ServeSuccessJSON(map[string]interface{}{
  1587. "msg": "结算成功",
  1588. })
  1589. }
  1590. }
  1591. } else {
  1592. }
  1593. } else {
  1594. }
  1595. } else {
  1596. var total float64
  1597. for _, item := range prescriptions {
  1598. if item.Type == 1 { //药品
  1599. for _, subItem := range item.HisDoctorAdviceInfo {
  1600. total = total + (subItem.Price * subItem.PrescribingNumber)
  1601. }
  1602. }
  1603. if item.Type == 2 { //项目
  1604. for _, subItem := range item.HisPrescriptionProject {
  1605. total = total + (subItem.Price * float64(subItem.Count))
  1606. }
  1607. }
  1608. for _, subItem := range item.HisAdditionalCharge {
  1609. total = total + (subItem.Price * float64(subItem.Count))
  1610. }
  1611. }
  1612. allTotal := fmt.Sprintf("%.2f", total)
  1613. totals, _ := strconv.ParseFloat(allTotal, 64)
  1614. order := &models.HisOrder{
  1615. UserOrgId: adminUser.CurrentOrgId,
  1616. HisPatientId: his.ID,
  1617. PatientId: id,
  1618. SettleAccountsDate: recordDateTime,
  1619. Ctime: time.Now().Unix(),
  1620. Mtime: time.Now().Unix(),
  1621. Status: 1,
  1622. OrderStatus: 2,
  1623. Number: chrg_bchno,
  1624. MedfeeSumamt: totals,
  1625. }
  1626. err = service.CreateOrder(order)
  1627. if err != nil {
  1628. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1629. return
  1630. }
  1631. var customs []*Custom
  1632. for _, item := range prescriptions {
  1633. if item.Type == 1 { //药品
  1634. for _, subItem := range item.HisDoctorAdviceInfo {
  1635. cus := &Custom{
  1636. AdviceId: subItem.ID,
  1637. ProjectId: 0,
  1638. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1639. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1640. FeedetlSn: subItem.FeedetlSn,
  1641. Price: fmt.Sprintf("%.2f", subItem.Price),
  1642. MedListCodg: subItem.MedListCodg,
  1643. Type: 1,
  1644. }
  1645. customs = append(customs, cus)
  1646. }
  1647. }
  1648. if item.Type == 2 { //项目
  1649. for _, subItem := range item.HisPrescriptionProject {
  1650. cus := &Custom{
  1651. AdviceId: 0,
  1652. ProjectId: subItem.ID,
  1653. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1654. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1655. FeedetlSn: subItem.FeedetlSn,
  1656. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1657. MedListCodg: subItem.MedListCodg,
  1658. Type: 2,
  1659. }
  1660. customs = append(customs, cus)
  1661. }
  1662. }
  1663. for _, item := range item.HisAdditionalCharge {
  1664. cus := &Custom{
  1665. ItemId: item.ID,
  1666. AdviceId: 0,
  1667. ProjectId: 0,
  1668. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1669. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1670. FeedetlSn: item.FeedetlSn,
  1671. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1672. MedListCodg: item.XtHisAddtionConfig.Code,
  1673. Type: 3,
  1674. }
  1675. customs = append(customs, cus)
  1676. }
  1677. }
  1678. for _, item := range customs {
  1679. var advice_id int64 = 0
  1680. var project_id int64 = 0
  1681. var item_id int64 = 0
  1682. var types int64 = 0
  1683. if item.Type == 1 {
  1684. advice_id = item.AdviceId
  1685. project_id = 0
  1686. item_id = 0
  1687. } else if item.Type == 2 {
  1688. advice_id = 0
  1689. item_id = 0
  1690. project_id = item.ProjectId
  1691. } else if item.Type == 3 {
  1692. advice_id = 0
  1693. item_id = item.ItemId
  1694. project_id = 0
  1695. }
  1696. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1697. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1698. pric, _ := strconv.ParseFloat(item.Price, 32)
  1699. info := &models.HisOrderInfo{
  1700. OrderNumber: order.Number,
  1701. UploadDate: time.Now().Unix(),
  1702. AdviceId: advice_id,
  1703. DetItemFeeSumamt: detItemFeeSumamt,
  1704. Cnt: cut,
  1705. Pric: pric,
  1706. PatientId: id,
  1707. Status: 1,
  1708. Mtime: time.Now().Unix(),
  1709. Ctime: time.Now().Unix(),
  1710. UserOrgId: adminUser.CurrentOrgId,
  1711. HisPatientId: his.ID,
  1712. OrderId: order.ID,
  1713. ProjectId: project_id,
  1714. Type: types,
  1715. ItemId: item_id,
  1716. }
  1717. service.CreateOrderInfo(info)
  1718. }
  1719. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1720. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1721. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1722. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1723. if err == nil {
  1724. c.ServeSuccessJSON(map[string]interface{}{
  1725. "msg": "结算成功",
  1726. })
  1727. }
  1728. }
  1729. }
  1730. //退款
  1731. func (c *HisApiController) Refund() {
  1732. order_id, _ := c.GetInt64("order_id")
  1733. number := c.GetString("number")
  1734. adminUser := c.GetAdminUserInfo()
  1735. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1736. if config.IsOpen == 1 { //对接了医保,走医保流程
  1737. } else {
  1738. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1739. if err == nil {
  1740. c.ServeSuccessJSON(map[string]interface{}{
  1741. "msg": "退费成功",
  1742. })
  1743. } else {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1745. return
  1746. }
  1747. }
  1748. }
  1749. func (this *HisApiController) AdditionalCharge() {
  1750. dataBody := make(map[string]interface{}, 0)
  1751. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1752. fmt.Println(err)
  1753. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  1754. patient_id := int64(dataBody["patient_id"].(float64))
  1755. medicineData, _ := dataBody["medicineData"].([]interface{})
  1756. adminUserInfo := this.GetAdminUserInfo()
  1757. orgId := adminUserInfo.CurrentOrgId
  1758. admin_user_id := adminUserInfo.AdminUser.Id
  1759. timeStr := time.Now().Format("2006-01-02")
  1760. timeLayout := "2006-01-02 15:04:05"
  1761. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1762. timenow := timeStringToTime.Unix()
  1763. var additionalCharges []*models.HisAdditionalCharge
  1764. for _, item := range medicineData {
  1765. var randNum int
  1766. randNum = rand.Intn(10000) + 1000
  1767. timestamp := time.Now().Unix()
  1768. tempTime := time.Unix(timestamp, 0)
  1769. timeFormat := tempTime.Format("20060102150405")
  1770. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1771. items := item.(map[string]interface{})
  1772. money := items["price"].(string)
  1773. item_id_str := items["item_id"].(string)
  1774. name := items["name"].(string)
  1775. id_str := items["id"].(string)
  1776. moneys, _ := strconv.ParseInt(money, 10, 64)
  1777. monStr := strconv.FormatInt(moneys, 10)
  1778. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  1779. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  1780. id, _ := strconv.ParseInt(id_str, 10, 64)
  1781. additionalCharge := &models.HisAdditionalCharge{
  1782. ID: id,
  1783. HisPatientId: his_patient_id,
  1784. UserOrgId: orgId,
  1785. PatientId: patient_id,
  1786. RecordDate: timenow,
  1787. Price: monneyStr,
  1788. Status: 1,
  1789. ItemName: name,
  1790. ItemId: item_id,
  1791. AdminUserId: admin_user_id,
  1792. CreatedTime: time.Now().Unix(),
  1793. OrderStatus: 0,
  1794. PrescriptionNumber: "",
  1795. BatchNumber: "",
  1796. FeedetlSn: p_number,
  1797. }
  1798. service.CreateAdditionalCharge(additionalCharge)
  1799. additionalCharges = append(additionalCharges, additionalCharge)
  1800. }
  1801. this.ServeSuccessJSON(map[string]interface{}{
  1802. "msg": "添加成功",
  1803. "additional_charges": additionalCharges,
  1804. })
  1805. }
  1806. func (this *HisApiController) DeleteAddition() {
  1807. id, _ := this.GetInt64("id")
  1808. //TODO 需要判断是否已经结算
  1809. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  1810. if err == nil {
  1811. this.ServeSuccessJSON(map[string]interface{}{
  1812. "msg": "删除成功",
  1813. })
  1814. return
  1815. } else {
  1816. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1817. return
  1818. }
  1819. }
  1820. func (this *HisApiController) GetAdminUsers() {
  1821. adminUser := this.GetAdminUserInfo()
  1822. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  1823. this.ServeSuccessJSON(map[string]interface{}{
  1824. "doctors": doctors,
  1825. })
  1826. }