his_api_controller.go 94KB

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