his_service.go 94KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  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. InsuplcAdmdvs string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
  150. }
  151. func (Patients) TableName() string {
  152. return "xt_patients"
  153. }
  154. type HisPrescription struct {
  155. ID int64 `gorm:"column:id" json:"id" form:"id"`
  156. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  157. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  158. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  159. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  160. Status int64 `gorm:"column:status" json:"status" form:"status"`
  161. }
  162. func (HisPrescription) TableName() string {
  163. return "his_prescription"
  164. }
  165. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  166. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  167. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  168. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  169. 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
  170. return
  171. }
  172. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  173. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  174. return
  175. }
  176. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  177. 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
  178. return
  179. }
  180. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  181. 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
  182. return
  183. }
  184. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  185. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  186. return
  187. }
  188. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  189. 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
  190. return
  191. }
  192. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  193. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  194. err = db.Find(&caseHistorys).Error
  195. return
  196. }
  197. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  198. likekey := "%" + keyword + "%"
  199. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  200. if startime > 0 {
  201. db = db.Where("record_date>=?", startime)
  202. }
  203. if endtime > 0 {
  204. db = db.Where("record_date<=?", endtime)
  205. }
  206. if len(keyword) > 0 {
  207. db = db.Where("template_name like ? ", likekey)
  208. }
  209. err = db.Find(&caseHistorys).Error
  210. return
  211. }
  212. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  213. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  214. return caseHistory, err
  215. }
  216. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  217. err = writeDb.Create(&template).Error
  218. return
  219. }
  220. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  221. history := models.HisPatientCaseHistory{}
  222. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  223. if err != nil {
  224. if err == gorm.ErrRecordNotFound {
  225. return nil, err
  226. } else {
  227. return nil, err
  228. }
  229. }
  230. return &history, nil
  231. }
  232. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  233. err := writeDb.Create(&caseHistory).Error
  234. return err
  235. }
  236. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  237. err = writeDb.Save(&prescription).Error
  238. return
  239. }
  240. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  241. 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
  242. 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
  243. 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
  244. return
  245. }
  246. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  247. 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
  248. return
  249. }
  250. func DelelteProject(id int64, user_org_id int64) (err error) {
  251. 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
  252. return
  253. }
  254. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  255. err = readDb.Model(&models.HisPrescription{}).
  256. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  257. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  258. }).
  259. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  260. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  261. }).
  262. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  263. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  264. }).
  265. 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).
  266. Find(&prescription).Error
  267. return
  268. }
  269. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  270. err = readDb.Model(&models.HisPrescription{}).
  271. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  272. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  273. }).
  274. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  275. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  276. }).
  277. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  278. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  279. }).
  280. 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).
  281. Find(&prescription).Error
  282. return
  283. }
  284. type OtherDrugWarehouseInfo struct {
  285. ID int64 `gorm:"column:id" json:"id" form:"id"`
  286. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  287. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  288. Status int64 `gorm:"column:status" json:"status" form:"status"`
  289. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  290. }
  291. func (OtherDrugWarehouseInfo) TableName() string {
  292. return "xt_drug_warehouse_info"
  293. }
  294. type VMDrugSalesReturnInfo struct {
  295. ID int64 `gorm:"column:id" json:"id" form:"id"`
  296. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  297. Count int64 `gorm:"column:count" json:"count" form:"count"`
  298. Status int64 `gorm:"column:status" json:"status" form:"status"`
  299. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  300. }
  301. func (VMDrugSalesReturnInfo) TableName() string {
  302. return "xt_drug_sales_return_info"
  303. }
  304. type VMDrugWarehouseOutInfo struct {
  305. ID int64 `gorm:"column:id" json:"id" form:"id"`
  306. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  307. Count int64 `gorm:"column:count" json:"count" form:"count"`
  308. Status int64 `gorm:"column:status" json:"status" form:"status"`
  309. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  310. }
  311. func (VMDrugWarehouseOutInfo) TableName() string {
  312. return "xt_drug_warehouse_out_info"
  313. }
  314. type VMDrugCancelStockInfo struct {
  315. ID int64 `gorm:"column:id" json:"id" form:"id"`
  316. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  317. Count int64 `gorm:"column:count" json:"count" form:"count"`
  318. Status int64 `gorm:"column:status" json:"status" form:"status"`
  319. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  320. }
  321. func (VMDrugCancelStockInfo) TableName() string {
  322. return "xt_drug_cancel_stock_info"
  323. }
  324. type BaseDrugLib struct {
  325. ID int64 `gorm:"column:id" json:"id" form:"id"`
  326. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  327. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  328. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  329. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  330. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  331. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  332. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  333. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  334. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  335. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  336. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  337. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  338. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  339. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  340. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  341. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  342. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  343. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  344. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  345. Number string `gorm:"column:number" json:"number" form:"number"`
  346. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  347. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  348. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  349. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  350. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  351. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  352. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  353. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  354. Code string `gorm:"column:code" json:"code" form:"code"`
  355. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  356. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  357. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  358. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  359. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  360. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  361. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  362. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  363. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  364. Label int64 `gorm:"column:label" json:"label" form:"label"`
  365. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  366. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  367. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  368. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  369. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  370. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  371. Status int64 `gorm:"column:status" json:"status" form:"status"`
  372. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  373. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  374. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  375. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  376. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  377. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  378. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  379. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  380. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  381. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  382. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  383. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  384. }
  385. func (BaseDrugLib) TableName() string {
  386. return "xt_base_drug"
  387. }
  388. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  389. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  390. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  391. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  392. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  393. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  394. return
  395. }
  396. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  397. err = writeDb.Create(&charge).Error
  398. return
  399. }
  400. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  401. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  402. 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")
  403. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  404. return
  405. }
  406. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  407. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  408. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  409. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  410. return
  411. }
  412. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  413. err = writeDb.Save(s).Error
  414. return
  415. }
  416. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  417. err = writeDb.Save(project).Error
  418. return
  419. }
  420. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  421. 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
  422. return
  423. }
  424. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  425. err := writeDb.Create(&patient).Error
  426. return err
  427. }
  428. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  429. 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
  430. return
  431. }
  432. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  433. 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
  434. return
  435. }
  436. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  437. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  438. return
  439. }
  440. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  441. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  442. return
  443. }
  444. func CreateOrder(order *models.HisOrder) (err error) {
  445. err = writeDb.Create(&order).Error
  446. return
  447. }
  448. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  449. err = writeDb.Create(&order).Error
  450. return
  451. }
  452. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  453. 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
  454. return
  455. }
  456. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  457. 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
  458. return
  459. }
  460. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  461. 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
  462. return
  463. }
  464. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  465. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  466. return
  467. }
  468. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  469. err = writeDb.Save(&info).Error
  470. return
  471. }
  472. 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) {
  473. offset := (page - 1) * limit
  474. db := readDb.Model(&models.HisOrder{})
  475. if doctor_id > 0 {
  476. 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)
  477. }
  478. if len(keywords) > 0 {
  479. keywords = "%" + keywords + "%"
  480. 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)
  481. }
  482. if start_time != 0 {
  483. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  484. }
  485. if end_time != 0 {
  486. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  487. }
  488. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  489. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  490. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  491. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  492. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  493. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  494. })
  495. db = db.Count(&total)
  496. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  497. return
  498. }
  499. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  500. 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
  501. return
  502. }
  503. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  504. 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
  505. return
  506. }
  507. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  508. 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
  509. return
  510. }
  511. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  512. 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
  513. return
  514. }
  515. type HisOrder struct {
  516. ID int64 `gorm:"column:id" json:"id" form:"id"`
  517. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  518. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  519. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  520. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  521. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  522. Status int64 `gorm:"column:status" json:"status" form:"status"`
  523. Number string `gorm:"column:number" json:"number" form:"number"`
  524. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  525. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  526. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  527. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  528. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  529. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  530. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  531. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  532. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  533. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  534. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  535. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  536. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  537. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  538. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  539. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  540. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  541. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  542. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  543. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  544. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  545. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  546. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  547. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  548. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  549. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  550. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  551. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  552. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  553. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  554. }
  555. func (HisOrder) TableName() string {
  556. return "his_order"
  557. }
  558. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  559. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  560. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  561. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  562. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  563. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  564. Order("ctime desc").
  565. Find(&order).Error
  566. return
  567. }
  568. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  569. err = readDb.Model(&models.HisPrescription{}).
  570. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  571. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  572. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  573. }).
  574. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  575. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  576. Find(&prescription).Error
  577. return
  578. }
  579. type HisPrescriptionInfo struct {
  580. ID int64 `gorm:"column:id" json:"id" form:"id"`
  581. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  582. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  583. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  584. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  585. Status int64 `gorm:"column:status" json:"status" form:"status"`
  586. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  587. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  588. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  589. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  590. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  591. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  592. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  593. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  594. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  595. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  596. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  597. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  598. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  599. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  600. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  601. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  602. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  603. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  604. }
  605. func (HisPrescriptionInfo) TableName() string {
  606. return "his_prescription_info"
  607. }
  608. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  609. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  610. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  611. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  612. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  613. Order("ctime desc").Find(&prescriptionOrder).Error
  614. return
  615. }
  616. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  617. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  618. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  619. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  620. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  621. return
  622. }
  623. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  624. err = readDb.Model(&models.HisPrescription{}).
  625. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  626. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  627. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  628. }).
  629. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  630. Find(&prescription).Error
  631. return
  632. }
  633. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  634. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  635. return
  636. }
  637. func UpdataOrderStatus(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": 1, "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 UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  644. 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
  645. 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
  646. 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
  647. return
  648. }
  649. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  650. 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()})
  651. //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
  652. //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
  653. }
  654. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  655. 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()})
  656. 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()})
  657. 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()})
  658. }
  659. func UpdataRegStatus2(id int64) error {
  660. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  661. return err
  662. }
  663. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  664. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  665. return
  666. }
  667. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  668. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  669. return
  670. }
  671. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  672. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  673. First(&order).Error
  674. return
  675. }
  676. func UpDateOrder(order models.HisOrder) (err error) {
  677. err = writeDb.Save(&order).Error
  678. return
  679. }
  680. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  681. err = writeDb.Save(&order).Error
  682. return
  683. }
  684. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  685. 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
  686. 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
  687. return
  688. }
  689. func CreateErrMsgLog(log *models.HisOrderError) {
  690. writeDb.Model(&models.HisOrderError{}).Create(&log)
  691. }
  692. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  693. 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
  694. return
  695. }
  696. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  697. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  698. return
  699. }
  700. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  701. db := readDb.Model(&models.OutpatientServiceSick{})
  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 FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  707. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  708. db = db.Where("user_org_id = ? AND status = 1", orgId)
  709. err = db.Order("ctime desc").Find(&list).Error
  710. return
  711. }
  712. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  713. db := readDb.Model(&models.XtHisAddtionConfig{})
  714. db = db.Where("user_org_id = ? AND status = 1", orgId)
  715. err = db.Order("ctime desc").Find(&list).Error
  716. return
  717. }
  718. type XtHisOrder struct {
  719. ID int64 `gorm:"column:id" json:"id" form:"id"`
  720. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  721. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  722. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  723. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  724. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  725. Status int64 `gorm:"column:status" json:"status" form:"status"`
  726. Number string `gorm:"column:number" json:"number" form:"number"`
  727. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  728. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  729. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  730. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  731. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  732. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  733. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  734. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  735. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  736. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  737. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  738. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  739. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  740. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  741. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  742. }
  743. func (XtHisOrder) TableName() string {
  744. return "his_order"
  745. }
  746. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  747. err = readDb.Model(&models.HisPrescription{}).
  748. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  749. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  750. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  751. }).
  752. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  753. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  754. Find(&prescription).Error
  755. return
  756. }
  757. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  758. 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
  759. return
  760. }
  761. func DelelteAddition(id int64, user_org_id int64) (err error) {
  762. 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
  763. return
  764. }
  765. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  766. offset := (page - 1) * limit
  767. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  768. if len(keywords) > 0 {
  769. keywords = "%" + keywords + "%"
  770. 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)
  771. 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)
  772. }
  773. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  774. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  775. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  776. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  777. db = db.Count(&total)
  778. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  779. return
  780. }
  781. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  782. patient := models.VMHisPatient{}
  783. 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
  784. return patient, err
  785. }
  786. type VMOtherHisPrescriptionInfo struct {
  787. ID int64 `gorm:"column:id" json:"id" form:"id"`
  788. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  789. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  790. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  791. Status int64 `gorm:"column:status" json:"status" form:"status"`
  792. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  793. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  794. }
  795. func (VMOtherHisPrescriptionInfo) TableName() string {
  796. return "his_prescription_info"
  797. }
  798. type VMHisPrescription struct {
  799. ID int64 `gorm:"column:id" json:"id" form:"id"`
  800. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  801. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  802. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  803. Status int64 `gorm:"column:status" json:"status" form:"status"`
  804. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  805. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  806. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  807. Type int64 `gorm:"column:type" json:"type" form:"type"`
  808. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  809. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  810. }
  811. func (VMHisPrescription) TableName() string {
  812. return "his_prescription"
  813. }
  814. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  815. 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).
  816. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  817. return db.Where("status = 1 AND user_org_id = ?", org_id).
  818. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  819. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  820. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  821. })
  822. }).Find(&advice).Error
  823. return
  824. }
  825. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  826. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  827. return
  828. }
  829. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  830. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  831. return
  832. }
  833. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  834. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  835. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  836. })
  837. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  838. return
  839. }
  840. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  841. db := readDb.Model(&models.HisOrderInfo{})
  842. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  843. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  844. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  845. })
  846. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  847. return
  848. }
  849. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  850. db := readDb.Model(&models.HisOrderInfo{})
  851. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  852. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  853. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  854. })
  855. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  856. return
  857. }
  858. 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) {
  859. db := readDb.Model(&models.HisOrder{})
  860. 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)
  861. if len(clr_org) > 0 {
  862. db = db.Where("clr_optins = ?", clr_org)
  863. }
  864. if len(clr_type) > 0 {
  865. if mdtrtareaAdmvs == "150499" {
  866. if clr_type == "11" {
  867. db = db.Where("clr_type = ?", clr_type)
  868. }
  869. } else {
  870. db = db.Where("clr_type = ?", clr_type)
  871. }
  872. } else {
  873. db = db.Where("clr_type <> ?", "9903")
  874. }
  875. err = db.Find(&orders).Error
  876. return
  877. }
  878. 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) {
  879. db := readDb.Model(&models.HisOrder{})
  880. 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)
  881. if len(clr_org) > 0 {
  882. db = db.Where("clr_optins = ?", clr_org)
  883. }
  884. if len(clr_type) > 0 {
  885. if mdtrtareaAdmvs == "150499" {
  886. if clr_type == "11" {
  887. db = db.Where("clr_type = ?", clr_type)
  888. }
  889. } else {
  890. db = db.Where("clr_type = ?", clr_type)
  891. }
  892. }
  893. err = db.Find(&orders).Error
  894. return
  895. }
  896. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  897. db := readDb.Model(&models.HisOrder{})
  898. 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)
  899. err = db.Find(&orders).Error
  900. return
  901. }
  902. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  903. 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
  904. return
  905. }
  906. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  907. 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
  908. return
  909. }
  910. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  911. var patient models.Patients
  912. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  913. if err != nil {
  914. if err == gorm.ErrRecordNotFound {
  915. return nil, nil
  916. } else {
  917. return nil, err
  918. }
  919. }
  920. return &patient, nil
  921. }
  922. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  923. dealer := models.HisXtDiagnoseConfig{}
  924. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ?", id).First(&dealer).Error
  925. return dealer, err
  926. }
  927. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  928. dealer := []*models.HisXtDiagnoseConfig{}
  929. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  930. return dealer, err
  931. }
  932. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  933. outPatient := &models.OutpatientServiceSick{}
  934. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  935. return outPatient, err
  936. }
  937. //
  938. //type MonthHisPrescription struct {
  939. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  940. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  941. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  942. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  943. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  944. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  945. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  946. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  947. // Number string `gorm:"column:number" json:"number" form:"number"`
  948. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  949. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  950. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  951. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  952. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  953. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  954. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  955. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  956. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  957. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  958. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  959. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  960. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  961. //}
  962. //
  963. //func (MonthHisPrescription) TableName() string {
  964. // return "his_prescription"
  965. //}
  966. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  967. err = readDb.Model(&models.HisPrescription{}).
  968. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  969. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  970. }).
  971. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  972. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  973. }).
  974. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  975. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  976. }).
  977. 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).
  978. Find(&prescription).Error
  979. return
  980. }
  981. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  982. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  983. return
  984. }
  985. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  986. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  987. return
  988. }
  989. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  990. 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
  991. return
  992. }
  993. func GetAppRole(orgID int64) (models.App_Role, error) {
  994. var appRole models.App_Role
  995. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  996. return appRole, err
  997. }
  998. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  999. var patient Patients
  1000. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1001. return patient, err
  1002. }
  1003. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  1004. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1005. table := XTReadDB().Table("xt_manufacturer as m")
  1006. fmt.Print(table)
  1007. if orgID > 0 {
  1008. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  1009. }
  1010. 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
  1011. return drug, err
  1012. }
  1013. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1014. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1015. return dataconfig, err
  1016. }
  1017. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1018. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1019. //return role, err
  1020. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1021. table := UserReadDB().Table("sgj_user_admin as a")
  1022. fmt.Println(table)
  1023. 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
  1024. return role, err
  1025. }
  1026. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1027. err = readDb.Model(&models.HisPrescription{}).
  1028. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1029. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1030. }).
  1031. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1032. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1033. }).
  1034. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1035. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1036. }).
  1037. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1038. Find(&prescription).Error
  1039. return
  1040. }
  1041. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1042. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1043. //table := UserReadDB().Table("sgj_user_admin as a")
  1044. //fmt.Println(table)
  1045. 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
  1046. return role, err
  1047. }
  1048. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1049. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1050. return role, err
  1051. }
  1052. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1053. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1054. table := XTReadDB().Table("xt_manufacturer as m")
  1055. fmt.Print(table)
  1056. if orgID > 0 {
  1057. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1058. }
  1059. 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
  1060. return drug, err
  1061. }
  1062. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1063. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1064. table := XTReadDB().Table("xt_manufacturer as m")
  1065. fmt.Println(table)
  1066. if orgid > 0 {
  1067. db = db.Where("x.org_id = ?", orgid)
  1068. }
  1069. 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
  1070. return good, err
  1071. }
  1072. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1073. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1074. table := XTReadDB().Table("xt_manufacturer as m")
  1075. fmt.Println(table)
  1076. if orgid > 0 {
  1077. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1078. }
  1079. 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
  1080. return good, err
  1081. }
  1082. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1083. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1084. table := UserReadDB().Table("sgj_user_admin as a")
  1085. fmt.Println(table)
  1086. if id > 0 {
  1087. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1088. }
  1089. 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
  1090. return role, err
  1091. }
  1092. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1093. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1094. return project, err
  1095. }
  1096. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1097. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1098. return project, err
  1099. }
  1100. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1101. db := XTReadDB().Table("xt_his_project")
  1102. if len(idss) == 1 {
  1103. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1104. } else {
  1105. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1106. }
  1107. return project, err
  1108. }
  1109. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1110. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1111. table := UserReadDB().Table("sgj_user_admin as a")
  1112. fmt.Println(table)
  1113. if len(idss) == 1 {
  1114. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1115. } else {
  1116. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1117. }
  1118. 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
  1119. return role, err
  1120. }
  1121. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1122. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1123. return
  1124. }
  1125. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1126. 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})
  1127. 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})
  1128. return
  1129. }
  1130. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1131. 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})
  1132. 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})
  1133. return
  1134. }
  1135. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1136. 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
  1137. return
  1138. }
  1139. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1140. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1141. return
  1142. }
  1143. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1144. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1145. return
  1146. }
  1147. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1148. err = writeDb.Create(&result).Error
  1149. return
  1150. }
  1151. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1152. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(result).Error
  1153. return
  1154. }
  1155. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1156. err = writeDb.Save(&result).Error
  1157. return
  1158. }
  1159. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1160. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1161. return
  1162. }
  1163. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1164. writeDb.Save(&his)
  1165. }
  1166. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1167. 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
  1168. return
  1169. }
  1170. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1171. 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
  1172. return
  1173. }
  1174. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1175. 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
  1176. return
  1177. }
  1178. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1179. 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).
  1180. Order("ctime desc").
  1181. Find(&order).Error
  1182. return
  1183. }
  1184. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1185. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1186. return
  1187. }
  1188. func UpdateHisPatientThree(his *models.HisPatient) {
  1189. writeDb.Save(&his)
  1190. }
  1191. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1192. err = readDb.Model(&models.HisPrescription{}).
  1193. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1194. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1195. }).
  1196. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1197. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1198. }).
  1199. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1200. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1201. }).
  1202. 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).
  1203. Find(&prescription).Error
  1204. return
  1205. }
  1206. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1207. err = readDb.Model(&models.HisPrescription{}).
  1208. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1209. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1210. }).
  1211. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1212. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1213. }).
  1214. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1215. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1216. }).
  1217. 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).
  1218. Find(&prescription).Error
  1219. return
  1220. }
  1221. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1222. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1223. return
  1224. }
  1225. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1226. 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
  1227. return
  1228. }
  1229. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1230. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1231. return
  1232. }
  1233. func GetOrderError(org_id int64) (order []*models.HisOrderError, err error) {
  1234. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10106 ", org_id).Find(&order).Error
  1235. return
  1236. }
  1237. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1238. 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
  1239. return
  1240. }
  1241. func CreateHisPsn(psn *models.HisPsn) {
  1242. writeDb.Save(&psn)
  1243. }
  1244. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1245. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1246. return
  1247. }
  1248. func GetPsnByPatientIdtWO(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1249. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ?", patient_id, record_date).Last(&psn).Error
  1250. return
  1251. }
  1252. //func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1253. // err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1254. // return
  1255. //}
  1256. func GetPsnByPatientIdTwo(patient_id int64) (psn models.HisPsn, err error) {
  1257. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1258. return
  1259. }
  1260. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1261. 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
  1262. fmt.Println(err)
  1263. return
  1264. }
  1265. func GetAllHisOrderTwo(org_id int64) (his []*models.HisOrder, err error) {
  1266. 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 >= 247903", org_id).Order("setl_time asc").Find(&his).Error
  1267. fmt.Println(err)
  1268. return
  1269. }
  1270. func GetAllHisOrder10106(org_id int64) (his []*models.HisOrder, err error) {
  1271. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-05-01 00:00:00' AND setl_time <= '2023-05-31 00:00:00'").Order("setl_time asc").Find(&his).Error
  1272. fmt.Println(err)
  1273. return
  1274. }
  1275. func GetAllHisOrder10138() (his []*models.HisOrder, err error) {
  1276. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10138 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-04-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1277. fmt.Println(err)
  1278. return
  1279. }
  1280. func GetAllHisOrder10278() (his []*models.HisOrder, err error) {
  1281. err = readDb.Model(&models.HisOrder{}).Where("id = 263631 and user_org_id = 10278 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-04-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1282. fmt.Println(err)
  1283. return
  1284. }
  1285. // func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1286. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1287. // return
  1288. // }
  1289. func GetAllHisOrderErr10278() (his []*models.HisOrderError, err error) {
  1290. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = 10278 AND status = 1 AND stage = 10276").Find(&his).Error
  1291. return
  1292. }
  1293. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1294. db := readDb.Model(&models.HisOrderInfo{})
  1295. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1296. return
  1297. }
  1298. func UpdataOrderStatusByNumber(number string) (err error) {
  1299. 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
  1300. return
  1301. }
  1302. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1303. 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
  1304. 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
  1305. 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
  1306. return
  1307. }
  1308. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1309. db := readDb.Model(&models.HisFundSettleListResult{})
  1310. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1311. return
  1312. }
  1313. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1314. writeDb.Save(&record)
  1315. }
  1316. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1317. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1318. return
  1319. }
  1320. func UpdateOrder(order models.HisOrder) (err error) {
  1321. err = writeDb.Save(&order).Error
  1322. return
  1323. }
  1324. func UpdateOrderTwo(order models.NewHisOrder111) (err error) {
  1325. err = writeDb.Save(&order).Error
  1326. return
  1327. }
  1328. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1329. err = readDb.Model(&models.HisPrescriptionTen{}).
  1330. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1331. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1332. }).
  1333. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1334. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1335. }).
  1336. 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).
  1337. Find(&prescription).Error
  1338. return
  1339. }
  1340. func GetHisOrderByIDTwo1111(order_id int64) (order models.NewHisOrder111, err error) {
  1341. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1342. return
  1343. }
  1344. func GetHisPrescriptionForMedType(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1345. err = readDb.Model(&models.HisPrescription{}).
  1346. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1347. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1348. }).
  1349. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1350. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1351. }).
  1352. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1353. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1354. }).
  1355. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 148801) or (user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 118801)", org_id, record_date, patient_id, org_id, record_date, patient_id).
  1356. Find(&prescription).Error
  1357. return
  1358. }