his_api_controller.go 76KB

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