his_service.go 89KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "time"
  7. )
  8. type HisPatient struct {
  9. ID int64 `gorm:"column:id" json:"id" form:"id"`
  10. Name string `gorm:"column:name" json:"name" form:"name"`
  11. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  12. Total float64 `gorm:"column:total" json:"total" form:"total"`
  13. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  14. Status int64 `gorm:"column:status" json:"status" form:"status"`
  15. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  16. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  17. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  18. Number string `gorm:"column:number" json:"number" form:"number"`
  19. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  20. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  21. }
  22. func (HisPatient) TableName() string {
  23. return "his_patient"
  24. }
  25. type Schedule struct {
  26. ID int64 `gorm:"column:id" json:"id" form:"id"`
  27. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  28. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  31. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  32. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  33. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  34. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  35. }
  36. func (Schedule) TableName() string {
  37. return "xt_schedule"
  38. }
  39. type VMHisPrescriptionInfo struct {
  40. ID int64 `gorm:"column:id" json:"id" form:"id"`
  41. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  42. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  43. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  44. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  45. Status int64 `gorm:"column:status" json:"status" form:"status"`
  46. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  47. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  48. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  49. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  50. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  51. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  52. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  53. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  54. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  55. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  56. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  57. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  58. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  59. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  60. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  61. }
  62. func (VMHisPrescriptionInfo) TableName() string {
  63. return "his_prescription_info"
  64. }
  65. type Patients struct {
  66. ID int64 `gorm:"column:id" json:"id" form:"id"`
  67. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  68. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  69. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  70. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  71. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  72. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  73. Source int64 `gorm:"column:source" json:"source" form:"source"`
  74. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  75. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  76. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  77. Name string `gorm:"column:name" json:"name" form:"name"`
  78. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  79. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  80. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  81. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  82. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  83. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  84. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  85. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  86. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  87. Height int64 `gorm:"column:height" json:"height" form:"height"`
  88. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  89. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  90. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  91. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  92. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  93. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  94. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  95. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  96. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  97. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  98. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  99. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  100. Children int64 `gorm:"column:children" json:"children" form:"children"`
  101. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  102. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  103. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  104. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  105. PredialysisCondition string `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
  106. PreHospitalDialysisFrequency string `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
  107. PreHospitalDialysisTimes int64 `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
  108. HospitalFirstDialysisDate int64 `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
  109. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  110. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  111. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  112. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  113. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  114. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  115. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  116. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  117. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  118. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  119. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  120. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  121. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
  122. PresentHistory string `gorm:"column:present_history" json:"present_history" form:"present_history"`
  123. PastHistory string `gorm:"column:past_history" json:"past_history" form:"past_history"`
  124. Temperature float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
  125. Pulse int64 `gorm:"column:pulse" json:"pulse" form:"pulse"`
  126. Respiratory int64 `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
  127. Sbp int64 `gorm:"column:sbp" json:"sbp" form:"sbp"`
  128. Dbp int64 `gorm:"column:dbp" json:"dbp" form:"dbp"`
  129. Status int64 `gorm:"column:status" json:"status" form:"status"`
  130. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  131. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  132. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  133. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  134. Age int64 `gorm:"column:age" json:"age" form:"age"`
  135. InfectiousNextRecordTime int64 `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
  136. IsInfectious int64 `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
  137. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
  138. RemindCycle int64 `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
  139. ResponseResult string `gorm:"column:response_result" json:"response_result" form:"response_result"`
  140. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  141. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  142. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  143. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  144. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  145. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  146. IsExcelExport int64 `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
  147. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  148. OutReason string `gorm:"column:out_reason" json:"out_reason" form:"out_reason"`
  149. }
  150. func (Patients) TableName() string {
  151. return "xt_patients"
  152. }
  153. type HisPrescription struct {
  154. ID int64 `gorm:"column:id" json:"id" form:"id"`
  155. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  156. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  157. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  158. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  159. Status int64 `gorm:"column:status" json:"status" form:"status"`
  160. }
  161. func (HisPrescription) TableName() string {
  162. return "his_prescription"
  163. }
  164. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  165. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  166. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  167. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  168. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  169. return
  170. }
  171. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  172. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  173. return
  174. }
  175. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  176. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  177. return
  178. }
  179. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  180. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  181. return
  182. }
  183. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  184. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  185. return
  186. }
  187. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  188. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  189. return
  190. }
  191. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  192. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  193. err = db.Find(&caseHistorys).Error
  194. return
  195. }
  196. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  197. likekey := "%" + keyword + "%"
  198. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  199. if startime > 0 {
  200. db = db.Where("record_date>=?", startime)
  201. }
  202. if endtime > 0 {
  203. db = db.Where("record_date<=?", endtime)
  204. }
  205. if len(keyword) > 0 {
  206. db = db.Where("template_name like ? ", likekey)
  207. }
  208. err = db.Find(&caseHistorys).Error
  209. return
  210. }
  211. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  212. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  213. return caseHistory, err
  214. }
  215. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  216. err = writeDb.Create(&template).Error
  217. return
  218. }
  219. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  220. history := models.HisPatientCaseHistory{}
  221. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  222. if err != nil {
  223. if err == gorm.ErrRecordNotFound {
  224. return nil, err
  225. } else {
  226. return nil, err
  227. }
  228. }
  229. return &history, nil
  230. }
  231. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  232. err := writeDb.Create(&caseHistory).Error
  233. return err
  234. }
  235. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  236. err = writeDb.Save(&prescription).Error
  237. return
  238. }
  239. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  240. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  241. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  242. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  243. return
  244. }
  245. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  246. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  247. return
  248. }
  249. func DelelteProject(id int64, user_org_id int64) (err error) {
  250. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  251. return
  252. }
  253. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  254. err = readDb.Model(&models.HisPrescription{}).
  255. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  257. }).
  258. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  259. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  260. }).
  261. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  262. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  263. }).
  264. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1", org_id, record_date, patient_id).
  265. Find(&prescription).Error
  266. return
  267. }
  268. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  269. err = readDb.Model(&models.HisPrescription{}).
  270. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  271. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  272. }).
  273. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  274. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  275. }).
  276. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  277. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  278. }).
  279. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, reg_type).
  280. Find(&prescription).Error
  281. return
  282. }
  283. type OtherDrugWarehouseInfo struct {
  284. ID int64 `gorm:"column:id" json:"id" form:"id"`
  285. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  286. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  287. Status int64 `gorm:"column:status" json:"status" form:"status"`
  288. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  289. }
  290. func (OtherDrugWarehouseInfo) TableName() string {
  291. return "xt_drug_warehouse_info"
  292. }
  293. type VMDrugSalesReturnInfo struct {
  294. ID int64 `gorm:"column:id" json:"id" form:"id"`
  295. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  296. Count int64 `gorm:"column:count" json:"count" form:"count"`
  297. Status int64 `gorm:"column:status" json:"status" form:"status"`
  298. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  299. }
  300. func (VMDrugSalesReturnInfo) TableName() string {
  301. return "xt_drug_sales_return_info"
  302. }
  303. type VMDrugWarehouseOutInfo struct {
  304. ID int64 `gorm:"column:id" json:"id" form:"id"`
  305. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  306. Count int64 `gorm:"column:count" json:"count" form:"count"`
  307. Status int64 `gorm:"column:status" json:"status" form:"status"`
  308. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  309. }
  310. func (VMDrugWarehouseOutInfo) TableName() string {
  311. return "xt_drug_warehouse_out_info"
  312. }
  313. type VMDrugCancelStockInfo struct {
  314. ID int64 `gorm:"column:id" json:"id" form:"id"`
  315. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  316. Count int64 `gorm:"column:count" json:"count" form:"count"`
  317. Status int64 `gorm:"column:status" json:"status" form:"status"`
  318. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  319. }
  320. func (VMDrugCancelStockInfo) TableName() string {
  321. return "xt_drug_cancel_stock_info"
  322. }
  323. type BaseDrugLib struct {
  324. ID int64 `gorm:"column:id" json:"id" form:"id"`
  325. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  326. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  327. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  328. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  329. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  330. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  331. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  332. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  333. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  334. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  335. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  336. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  337. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  338. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  339. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  340. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  341. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  342. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  343. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  344. Number string `gorm:"column:number" json:"number" form:"number"`
  345. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  346. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  347. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  348. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  349. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  350. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  351. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  352. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  353. Code string `gorm:"column:code" json:"code" form:"code"`
  354. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  355. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  356. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  357. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  358. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  359. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  360. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  361. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  362. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  363. Label int64 `gorm:"column:label" json:"label" form:"label"`
  364. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  365. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  366. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  367. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  368. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  369. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  370. Status int64 `gorm:"column:status" json:"status" form:"status"`
  371. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  372. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  373. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  374. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  375. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  376. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  377. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  378. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  379. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  380. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  381. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  382. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  383. }
  384. func (BaseDrugLib) TableName() string {
  385. return "xt_base_drug"
  386. }
  387. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  388. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  389. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  390. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  391. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  392. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  393. return
  394. }
  395. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  396. err = writeDb.Create(&charge).Error
  397. return
  398. }
  399. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  400. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  401. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  402. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  403. return
  404. }
  405. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  406. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  407. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  408. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  409. return
  410. }
  411. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  412. err = writeDb.Save(s).Error
  413. return
  414. }
  415. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  416. err = writeDb.Save(project).Error
  417. return
  418. }
  419. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  420. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  421. return
  422. }
  423. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  424. err := writeDb.Create(&patient).Error
  425. return err
  426. }
  427. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  428. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  429. return
  430. }
  431. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  432. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, his_patient_id).First(&info).Error
  433. return
  434. }
  435. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  436. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  437. return
  438. }
  439. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  440. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  441. return
  442. }
  443. func CreateOrder(order *models.HisOrder) (err error) {
  444. err = writeDb.Create(&order).Error
  445. return
  446. }
  447. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  448. err = writeDb.Create(&order).Error
  449. return
  450. }
  451. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  452. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  453. return
  454. }
  455. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  456. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ?", org_id, record_date, his_patient_id).First(&info).Error
  457. return
  458. }
  459. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  460. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  461. return
  462. }
  463. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  464. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  465. return
  466. }
  467. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  468. err = writeDb.Save(&info).Error
  469. return
  470. }
  471. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string) (order []*models.HisOrder, err error, total int64) {
  472. offset := (page - 1) * limit
  473. db := readDb.Model(&models.HisOrder{})
  474. if doctor_id > 0 {
  475. db = db.Joins("join his_prescription_info as info on info.patient_id = his_order.patient_id AND info.record_date = his_order.settle_accounts_date AND info.doctor_id = ? AND info.user_org_id = ?", doctor_id, user_org_id)
  476. }
  477. if len(keywords) > 0 {
  478. keywords = "%" + keywords + "%"
  479. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.name like ? AND patient.user_org_id = ?", keywords, user_org_id)
  480. }
  481. if start_time != 0 {
  482. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  483. }
  484. if end_time != 0 {
  485. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  486. }
  487. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  488. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  489. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  490. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  491. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  492. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  493. })
  494. db = db.Count(&total)
  495. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  496. return
  497. }
  498. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  499. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  500. return
  501. }
  502. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  503. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  504. return
  505. }
  506. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  507. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 2, "mtime": time.Now().Unix()}).Error
  508. return
  509. }
  510. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  511. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 2, "mtime": time.Now().Unix()}).Error
  512. return
  513. }
  514. type HisOrder struct {
  515. ID int64 `gorm:"column:id" json:"id" form:"id"`
  516. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  517. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  518. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  519. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  520. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  521. Status int64 `gorm:"column:status" json:"status" form:"status"`
  522. Number string `gorm:"column:number" json:"number" form:"number"`
  523. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  524. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  525. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  526. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  527. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  528. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  529. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  530. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  531. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  532. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  533. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  534. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  535. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  536. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  537. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  538. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  539. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  540. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  541. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  542. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  543. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  544. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  545. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  546. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  547. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  548. }
  549. func (HisOrder) TableName() string {
  550. return "his_order"
  551. }
  552. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  553. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  554. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  555. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  556. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  557. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  558. Order("ctime desc").
  559. Find(&order).Error
  560. return
  561. }
  562. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  563. err = readDb.Model(&models.HisPrescription{}).
  564. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  565. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  566. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  567. }).
  568. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  569. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  570. Find(&prescription).Error
  571. return
  572. }
  573. type HisPrescriptionInfo struct {
  574. ID int64 `gorm:"column:id" json:"id" form:"id"`
  575. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  576. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  577. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  578. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  579. Status int64 `gorm:"column:status" json:"status" form:"status"`
  580. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  581. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  582. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  583. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  584. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  585. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  586. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  587. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  588. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  589. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  590. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  591. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  592. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  593. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  594. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  595. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  596. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  597. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  598. }
  599. func (HisPrescriptionInfo) TableName() string {
  600. return "his_prescription_info"
  601. }
  602. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  603. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  604. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  605. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  606. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  607. Order("ctime desc").Find(&prescriptionOrder).Error
  608. return
  609. }
  610. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  611. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  612. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  613. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  614. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  615. return
  616. }
  617. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  618. err = readDb.Model(&models.HisPrescription{}).
  619. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  620. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  621. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  622. }).
  623. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  624. Find(&prescription).Error
  625. return
  626. }
  627. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  628. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  629. return
  630. }
  631. func UpdataOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  632. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  633. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  634. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  635. return
  636. }
  637. func UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  638. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  639. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  640. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  641. return
  642. }
  643. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  644. writeDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 AND record_date =? AND user_org_id = ?", patient_id, record_time, org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  645. //writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  646. //writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  647. }
  648. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  649. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", record_time, org_id, his_patient_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  650. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  651. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  652. }
  653. func UpdataRegStatus2(id int64) error {
  654. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  655. return err
  656. }
  657. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  658. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  659. return
  660. }
  661. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  662. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  663. return
  664. }
  665. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  666. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  667. First(&order).Error
  668. return
  669. }
  670. func UpDateOrder(order models.HisOrder) (err error) {
  671. err = writeDb.Save(&order).Error
  672. return
  673. }
  674. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  675. err = writeDb.Save(&order).Error
  676. return
  677. }
  678. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  679. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  680. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  681. return
  682. }
  683. func CreateErrMsgLog(log *models.HisOrderError) {
  684. writeDb.Model(&models.HisOrderError{}).Create(&log)
  685. }
  686. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  687. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  688. return
  689. }
  690. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  691. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  692. return
  693. }
  694. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  695. db := readDb.Model(&models.OutpatientServiceSick{})
  696. db = db.Where("user_org_id = ? AND status = 1", orgId)
  697. err = db.Order("ctime desc").Find(&list).Error
  698. return
  699. }
  700. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  701. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  702. db = db.Where("user_org_id = ? AND status = 1", orgId)
  703. err = db.Order("ctime desc").Find(&list).Error
  704. return
  705. }
  706. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  707. db := readDb.Model(&models.XtHisAddtionConfig{})
  708. db = db.Where("user_org_id = ? AND status = 1", orgId)
  709. err = db.Order("ctime desc").Find(&list).Error
  710. return
  711. }
  712. type XtHisOrder struct {
  713. ID int64 `gorm:"column:id" json:"id" form:"id"`
  714. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  715. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  716. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  717. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  718. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  719. Status int64 `gorm:"column:status" json:"status" form:"status"`
  720. Number string `gorm:"column:number" json:"number" form:"number"`
  721. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  722. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  723. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  724. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  725. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  726. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  727. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  728. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  729. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  730. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  731. }
  732. func (XtHisOrder) TableName() string {
  733. return "his_order"
  734. }
  735. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  736. err = readDb.Model(&models.HisPrescription{}).
  737. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  738. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  739. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  740. }).
  741. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  742. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  743. Find(&prescription).Error
  744. return
  745. }
  746. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  747. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Find(&addition).Error
  748. return
  749. }
  750. func DelelteAddition(id int64, user_org_id int64) (err error) {
  751. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  752. return
  753. }
  754. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  755. offset := (page - 1) * limit
  756. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  757. if len(keywords) > 0 {
  758. keywords = "%" + keywords + "%"
  759. db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  760. db = db.Joins("JOIN his_prescription_info as info On xt_schedule.patient_id = info.patient_id AND info.user_org_id = ? AND info.record_date = ? AND info.prescription_number like ?", org_id, record_date, keywords)
  761. }
  762. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  763. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  764. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  765. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  766. db = db.Count(&total)
  767. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  768. return
  769. }
  770. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  771. patient := models.VMHisPatient{}
  772. err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
  773. return patient, err
  774. }
  775. type VMOtherHisPrescriptionInfo struct {
  776. ID int64 `gorm:"column:id" json:"id" form:"id"`
  777. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  778. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  779. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  780. Status int64 `gorm:"column:status" json:"status" form:"status"`
  781. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  782. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  783. }
  784. func (VMOtherHisPrescriptionInfo) TableName() string {
  785. return "his_prescription_info"
  786. }
  787. type VMHisPrescription struct {
  788. ID int64 `gorm:"column:id" json:"id" form:"id"`
  789. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  790. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  791. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  792. Status int64 `gorm:"column:status" json:"status" form:"status"`
  793. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  794. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  795. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  796. Type int64 `gorm:"column:type" json:"type" form:"type"`
  797. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  798. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  799. }
  800. func (VMHisPrescription) TableName() string {
  801. return "his_prescription"
  802. }
  803. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  804. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
  805. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  806. return db.Where("status = 1 AND user_org_id = ?", org_id).
  807. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  808. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  809. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  810. })
  811. }).Find(&advice).Error
  812. return
  813. }
  814. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  815. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  816. return
  817. }
  818. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  819. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  820. return
  821. }
  822. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  823. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  824. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  825. })
  826. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  827. return
  828. }
  829. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  830. db := readDb.Model(&models.HisOrderInfo{})
  831. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  832. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  833. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  834. })
  835. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  836. return
  837. }
  838. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  839. db := readDb.Model(&models.HisOrderInfo{})
  840. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  841. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  842. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  843. })
  844. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  845. return
  846. }
  847. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string) (orders []*models.HisOrder, err error) {
  848. db := readDb.Model(&models.HisOrder{})
  849. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  850. if len(clr_org) > 0 {
  851. db = db.Where("clr_optins = ?", clr_org)
  852. }
  853. if len(clr_type) > 0 {
  854. db = db.Where("clr_type = ?", clr_type)
  855. }
  856. err = db.Find(&orders).Error
  857. return
  858. }
  859. func GetOrderByTimeFive(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string) (orders []*models.HisOrder, err error) {
  860. db := readDb.Model(&models.HisOrder{})
  861. db = db.Where("user_org_id = ? AND order_status = 3 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  862. if len(clr_org) > 0 {
  863. db = db.Where("clr_optins = ?", clr_org)
  864. }
  865. if len(clr_type) > 0 {
  866. db = db.Where("clr_type = ?", clr_type)
  867. }
  868. err = db.Find(&orders).Error
  869. return
  870. }
  871. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  872. db := readDb.Model(&models.HisOrder{})
  873. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org_id, end_time, start_time)
  874. err = db.Find(&orders).Error
  875. return
  876. }
  877. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  878. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype).Find(&orders).Error
  879. return
  880. }
  881. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  882. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time).Find(&orders).Error
  883. return
  884. }
  885. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  886. var patient models.Patients
  887. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  888. if err != nil {
  889. if err == gorm.ErrRecordNotFound {
  890. return nil, nil
  891. } else {
  892. return nil, err
  893. }
  894. }
  895. return &patient, nil
  896. }
  897. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  898. dealer := models.HisXtDiagnoseConfig{}
  899. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", id).First(&dealer).Error
  900. return dealer, err
  901. }
  902. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  903. dealer := []*models.HisXtDiagnoseConfig{}
  904. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  905. return dealer, err
  906. }
  907. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  908. outPatient := &models.OutpatientServiceSick{}
  909. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  910. return outPatient, err
  911. }
  912. //
  913. //type MonthHisPrescription struct {
  914. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  915. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  916. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  917. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  918. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  919. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  920. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  921. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  922. // Number string `gorm:"column:number" json:"number" form:"number"`
  923. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  924. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  925. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  926. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  927. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  928. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  929. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  930. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  931. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  932. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  933. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  934. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  935. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  936. //}
  937. //
  938. //func (MonthHisPrescription) TableName() string {
  939. // return "his_prescription"
  940. //}
  941. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  942. err = readDb.Model(&models.HisPrescription{}).
  943. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  944. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  945. }).
  946. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  947. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  948. }).
  949. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  950. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  951. }).
  952. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, reg_type).
  953. Find(&prescription).Error
  954. return
  955. }
  956. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  957. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  958. return
  959. }
  960. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  961. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  962. return
  963. }
  964. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  965. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
  966. return
  967. }
  968. func GetAppRole(orgID int64) (models.App_Role, error) {
  969. var appRole models.App_Role
  970. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  971. return appRole, err
  972. }
  973. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  974. var patient Patients
  975. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  976. return patient, err
  977. }
  978. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  979. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  980. table := XTReadDB().Table("xt_manufacturer as m")
  981. fmt.Print(table)
  982. if orgID > 0 {
  983. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  984. }
  985. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  986. return drug, err
  987. }
  988. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  989. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  990. return dataconfig, err
  991. }
  992. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  993. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  994. //return role, err
  995. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  996. table := UserReadDB().Table("sgj_user_admin as a")
  997. fmt.Println(table)
  998. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  999. return role, err
  1000. }
  1001. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1002. err = readDb.Model(&models.HisPrescription{}).
  1003. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1004. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1005. }).
  1006. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1007. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1008. }).
  1009. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1010. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1011. }).
  1012. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1013. Find(&prescription).Error
  1014. return
  1015. }
  1016. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1017. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1018. //table := UserReadDB().Table("sgj_user_admin as a")
  1019. //fmt.Println(table)
  1020. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1021. return role, err
  1022. }
  1023. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1024. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1025. return role, err
  1026. }
  1027. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1028. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1029. table := XTReadDB().Table("xt_manufacturer as m")
  1030. fmt.Print(table)
  1031. if orgID > 0 {
  1032. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1033. }
  1034. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1035. return drug, err
  1036. }
  1037. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1038. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1039. table := XTReadDB().Table("xt_manufacturer as m")
  1040. fmt.Println(table)
  1041. if orgid > 0 {
  1042. db = db.Where("x.org_id = ?", orgid)
  1043. }
  1044. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1045. return good, err
  1046. }
  1047. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1048. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1049. table := XTReadDB().Table("xt_manufacturer as m")
  1050. fmt.Println(table)
  1051. if orgid > 0 {
  1052. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1053. }
  1054. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1055. return good, err
  1056. }
  1057. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1058. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1059. table := UserReadDB().Table("sgj_user_admin as a")
  1060. fmt.Println(table)
  1061. if id > 0 {
  1062. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1063. }
  1064. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1065. return role, err
  1066. }
  1067. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1068. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1069. return project, err
  1070. }
  1071. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1072. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1073. return project, err
  1074. }
  1075. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1076. db := XTReadDB().Table("xt_his_project")
  1077. if len(idss) == 1 {
  1078. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1079. } else {
  1080. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1081. }
  1082. return project, err
  1083. }
  1084. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1085. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1086. table := UserReadDB().Table("sgj_user_admin as a")
  1087. fmt.Println(table)
  1088. if len(idss) == 1 {
  1089. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1090. } else {
  1091. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1092. }
  1093. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1094. return role, err
  1095. }
  1096. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1097. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1098. return
  1099. }
  1100. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1101. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1102. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1103. return
  1104. }
  1105. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1106. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date <= ? AND record_date >= ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1107. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1108. return
  1109. }
  1110. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1111. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  1112. return
  1113. }
  1114. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1115. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1116. return
  1117. }
  1118. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1119. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1120. return
  1121. }
  1122. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1123. err = writeDb.Create(&result).Error
  1124. return
  1125. }
  1126. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1127. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(result).Error
  1128. return
  1129. }
  1130. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1131. err = writeDb.Save(&result).Error
  1132. return
  1133. }
  1134. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1135. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1136. return
  1137. }
  1138. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1139. writeDb.Save(&his)
  1140. }
  1141. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1142. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> ''", org_id).Last(&his).Error
  1143. return
  1144. }
  1145. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1146. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  1147. return
  1148. }
  1149. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1150. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  1151. return
  1152. }
  1153. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1154. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
  1155. Order("ctime desc").
  1156. Find(&order).Error
  1157. return
  1158. }
  1159. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1160. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1161. return
  1162. }
  1163. func UpdateHisPatientThree(his *models.HisPatient) {
  1164. writeDb.Save(&his)
  1165. }
  1166. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1167. err = readDb.Model(&models.HisPrescription{}).
  1168. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1169. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1170. }).
  1171. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1172. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1173. }).
  1174. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1175. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1176. }).
  1177. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, med_type).
  1178. Find(&prescription).Error
  1179. return
  1180. }
  1181. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1182. err = readDb.Model(&models.HisPrescription{}).
  1183. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1184. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1185. }).
  1186. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1187. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1188. }).
  1189. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1190. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1191. }).
  1192. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, med_type).
  1193. Find(&prescription).Error
  1194. return
  1195. }
  1196. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1197. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1198. return
  1199. }
  1200. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1201. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 1 AND mdtrt_id = ?", org_id, patient_id, record_time, number).First(&order).Error
  1202. return
  1203. }
  1204. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1205. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  1206. return
  1207. }
  1208. func CreateHisPsn(psn *models.HisPsn) {
  1209. writeDb.Save(&psn)
  1210. }
  1211. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1212. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1213. return
  1214. }
  1215. func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1216. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1217. return
  1218. }
  1219. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1220. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2022-08-01 00:00:00' AND setl_time <= '2022-09-30 23:59:59'", org_id).Order("setl_time asc").Find(&his).Error
  1221. return
  1222. }
  1223. func GetAllHisOrderErr(org_id int64, stage int64) (his []*models.HisOrderError, err error) {
  1224. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 101060", org_id).Find(&his).Error
  1225. return
  1226. }
  1227. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1228. db := readDb.Model(&models.HisOrderInfo{})
  1229. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1230. return
  1231. }
  1232. func UpdataOrderStatusByNumber(number string) (err error) {
  1233. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND number = ?", number).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1234. return
  1235. }
  1236. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1237. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND order_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  1238. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1239. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1240. return
  1241. }
  1242. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1243. db := readDb.Model(&models.HisFundSettleListResult{})
  1244. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1245. return
  1246. }
  1247. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1248. writeDb.Save(&record)
  1249. }
  1250. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1251. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1252. return
  1253. }
  1254. func UpdateOrder(order models.HisOrder) (err error) {
  1255. err = writeDb.Save(&order).Error
  1256. return
  1257. }
  1258. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1259. err = readDb.Model(&models.HisPrescriptionTen{}).
  1260. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1261. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1262. }).
  1263. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1264. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1265. }).
  1266. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND p_type <> 1 ", org_id, record_date, his_patient_id).
  1267. Find(&prescription).Error
  1268. return
  1269. }