his_api_controller.go 82KB

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