his_api_controller.go 93KB

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