his_service.go 90KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518
  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 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, mdtrtareaAdmvs 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. if mdtrtareaAdmvs == "150499" {
  855. if clr_type == "11" {
  856. db = db.Where("clr_type = ?", clr_type)
  857. }
  858. } else {
  859. db = db.Where("clr_type = ?", clr_type)
  860. }
  861. }
  862. err = db.Find(&orders).Error
  863. return
  864. }
  865. func GetOrderByTimeFive(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  866. db := readDb.Model(&models.HisOrder{})
  867. 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)
  868. if len(clr_org) > 0 {
  869. db = db.Where("clr_optins = ?", clr_org)
  870. }
  871. if len(clr_type) > 0 {
  872. if mdtrtareaAdmvs == "150499" {
  873. if clr_type == "11" {
  874. db = db.Where("clr_type = ?", clr_type)
  875. }
  876. } else {
  877. db = db.Where("clr_type = ?", clr_type)
  878. }
  879. }
  880. err = db.Find(&orders).Error
  881. return
  882. }
  883. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  884. db := readDb.Model(&models.HisOrder{})
  885. 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)
  886. err = db.Find(&orders).Error
  887. return
  888. }
  889. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  890. 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
  891. return
  892. }
  893. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  894. 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
  895. return
  896. }
  897. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  898. var patient models.Patients
  899. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  900. if err != nil {
  901. if err == gorm.ErrRecordNotFound {
  902. return nil, nil
  903. } else {
  904. return nil, err
  905. }
  906. }
  907. return &patient, nil
  908. }
  909. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  910. dealer := models.HisXtDiagnoseConfig{}
  911. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", id).First(&dealer).Error
  912. return dealer, err
  913. }
  914. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  915. dealer := []*models.HisXtDiagnoseConfig{}
  916. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  917. return dealer, err
  918. }
  919. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  920. outPatient := &models.OutpatientServiceSick{}
  921. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  922. return outPatient, err
  923. }
  924. //
  925. //type MonthHisPrescription struct {
  926. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  927. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  928. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  929. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  930. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  931. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  932. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  933. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  934. // Number string `gorm:"column:number" json:"number" form:"number"`
  935. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  936. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  937. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  938. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  939. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  940. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  941. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  942. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  943. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  944. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  945. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  946. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  947. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  948. //}
  949. //
  950. //func (MonthHisPrescription) TableName() string {
  951. // return "his_prescription"
  952. //}
  953. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  954. err = readDb.Model(&models.HisPrescription{}).
  955. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  956. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  957. }).
  958. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  959. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  960. }).
  961. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  962. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  963. }).
  964. 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).
  965. Find(&prescription).Error
  966. return
  967. }
  968. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  969. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  970. return
  971. }
  972. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  973. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  974. return
  975. }
  976. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  977. 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
  978. return
  979. }
  980. func GetAppRole(orgID int64) (models.App_Role, error) {
  981. var appRole models.App_Role
  982. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  983. return appRole, err
  984. }
  985. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  986. var patient Patients
  987. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  988. return patient, err
  989. }
  990. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  991. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  992. table := XTReadDB().Table("xt_manufacturer as m")
  993. fmt.Print(table)
  994. if orgID > 0 {
  995. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  996. }
  997. 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
  998. return drug, err
  999. }
  1000. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1001. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1002. return dataconfig, err
  1003. }
  1004. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1005. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1006. //return role, err
  1007. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1008. table := UserReadDB().Table("sgj_user_admin as a")
  1009. fmt.Println(table)
  1010. 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
  1011. return role, err
  1012. }
  1013. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1014. err = readDb.Model(&models.HisPrescription{}).
  1015. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1016. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1017. }).
  1018. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1019. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1020. }).
  1021. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1022. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1023. }).
  1024. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1025. Find(&prescription).Error
  1026. return
  1027. }
  1028. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1029. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1030. //table := UserReadDB().Table("sgj_user_admin as a")
  1031. //fmt.Println(table)
  1032. 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
  1033. return role, err
  1034. }
  1035. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1036. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1037. return role, err
  1038. }
  1039. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1040. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1041. table := XTReadDB().Table("xt_manufacturer as m")
  1042. fmt.Print(table)
  1043. if orgID > 0 {
  1044. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1045. }
  1046. 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
  1047. return drug, err
  1048. }
  1049. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1050. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1051. table := XTReadDB().Table("xt_manufacturer as m")
  1052. fmt.Println(table)
  1053. if orgid > 0 {
  1054. db = db.Where("x.org_id = ?", orgid)
  1055. }
  1056. 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
  1057. return good, err
  1058. }
  1059. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1060. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1061. table := XTReadDB().Table("xt_manufacturer as m")
  1062. fmt.Println(table)
  1063. if orgid > 0 {
  1064. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1065. }
  1066. 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
  1067. return good, err
  1068. }
  1069. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1070. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1071. table := UserReadDB().Table("sgj_user_admin as a")
  1072. fmt.Println(table)
  1073. if id > 0 {
  1074. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1075. }
  1076. 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
  1077. return role, err
  1078. }
  1079. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1080. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1081. return project, err
  1082. }
  1083. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1084. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1085. return project, err
  1086. }
  1087. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1088. db := XTReadDB().Table("xt_his_project")
  1089. if len(idss) == 1 {
  1090. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1091. } else {
  1092. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1093. }
  1094. return project, err
  1095. }
  1096. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1097. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1098. table := UserReadDB().Table("sgj_user_admin as a")
  1099. fmt.Println(table)
  1100. if len(idss) == 1 {
  1101. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1102. } else {
  1103. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1104. }
  1105. 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
  1106. return role, err
  1107. }
  1108. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1109. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1110. return
  1111. }
  1112. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1113. 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})
  1114. 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})
  1115. return
  1116. }
  1117. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1118. 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})
  1119. 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})
  1120. return
  1121. }
  1122. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1123. 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
  1124. return
  1125. }
  1126. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1127. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1128. return
  1129. }
  1130. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1131. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1132. return
  1133. }
  1134. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1135. err = writeDb.Create(&result).Error
  1136. return
  1137. }
  1138. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1139. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(result).Error
  1140. return
  1141. }
  1142. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1143. err = writeDb.Save(&result).Error
  1144. return
  1145. }
  1146. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1147. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1148. return
  1149. }
  1150. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1151. writeDb.Save(&his)
  1152. }
  1153. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1154. 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
  1155. return
  1156. }
  1157. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1158. 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
  1159. return
  1160. }
  1161. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1162. 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
  1163. return
  1164. }
  1165. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1166. 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).
  1167. Order("ctime desc").
  1168. Find(&order).Error
  1169. return
  1170. }
  1171. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1172. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1173. return
  1174. }
  1175. func UpdateHisPatientThree(his *models.HisPatient) {
  1176. writeDb.Save(&his)
  1177. }
  1178. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1179. err = readDb.Model(&models.HisPrescription{}).
  1180. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1181. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1182. }).
  1183. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1184. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1185. }).
  1186. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1187. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1188. }).
  1189. 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).
  1190. Find(&prescription).Error
  1191. return
  1192. }
  1193. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1194. err = readDb.Model(&models.HisPrescription{}).
  1195. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1196. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1197. }).
  1198. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1199. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1200. }).
  1201. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1202. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1203. }).
  1204. 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).
  1205. Find(&prescription).Error
  1206. return
  1207. }
  1208. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1209. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1210. return
  1211. }
  1212. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1213. 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
  1214. return
  1215. }
  1216. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1217. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1218. return
  1219. }
  1220. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1221. 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
  1222. return
  1223. }
  1224. func CreateHisPsn(psn *models.HisPsn) {
  1225. writeDb.Save(&psn)
  1226. }
  1227. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1228. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1229. return
  1230. }
  1231. func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1232. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1233. return
  1234. }
  1235. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1236. 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-12-15 00:00:00'", org_id).Order("setl_time asc").Find(&his).Error
  1237. fmt.Println(err)
  1238. return
  1239. }
  1240. func GetAllHisOrderTwo(org_id int64, id int64) (his []*models.HisOrder, err error) {
  1241. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND id > ?", org_id, id).Order("setl_time asc").Find(&his).Error
  1242. fmt.Println(err)
  1243. return
  1244. }
  1245. //func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1246. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1247. // return
  1248. //}
  1249. //func GetAllHisOrderErr(org_id int64, stage int64) (his []*models.HisOrderError, err error) {
  1250. // err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 101060", org_id).Find(&his).Error
  1251. // return
  1252. //}
  1253. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1254. db := readDb.Model(&models.HisOrderInfo{})
  1255. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1256. return
  1257. }
  1258. func UpdataOrderStatusByNumber(number string) (err error) {
  1259. 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
  1260. return
  1261. }
  1262. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1263. 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
  1264. 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
  1265. 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
  1266. return
  1267. }
  1268. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1269. db := readDb.Model(&models.HisFundSettleListResult{})
  1270. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1271. return
  1272. }
  1273. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1274. writeDb.Save(&record)
  1275. }
  1276. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1277. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1278. return
  1279. }
  1280. func UpdateOrder(order models.HisOrder) (err error) {
  1281. err = writeDb.Save(&order).Error
  1282. return
  1283. }
  1284. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1285. err = readDb.Model(&models.HisPrescriptionTen{}).
  1286. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1287. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1288. }).
  1289. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1290. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1291. }).
  1292. 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).
  1293. Find(&prescription).Error
  1294. return
  1295. }