his_api_controller.go 93KB

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