123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- package service
-
- import (
- "time"
-
- "XT_New/models"
-
- "github.com/jinzhu/gorm"
- )
-
- func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
- var patient models.Patients
- err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1 and lapseto = 1", patientID, orgID).First(&patient).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return &patient, nil
- }
-
- func GetPatientByIDOne(orgID int64, patientID int64) (models.Patients, error) {
- var patient models.Patients
- err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
-
- return patient, err
- }
-
- func GetPatientByIDTwoOne(patientID int64) (models.Patients, error) {
- var patient models.Patients
- err = readDb.Model(&models.Patients{}).Where("id = ? and status=1", patientID).First(&patient).Error
-
- return patient, err
- }
-
- func GetPatientCourseOfDisease(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientDiseaseCourse, error) {
- var records []*models.PatientDiseaseCourse
- err := readDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
- if err != nil {
- return nil, err
- }
- return records, nil
- }
-
- func GetPatientSickHistory(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientSickHistory, error) {
- var records []*models.XtPatientSickHistory
- err := readDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
- if err != nil {
- return nil, err
- }
- return records, nil
- }
-
- func GetPatientSickHistoryByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientSickHistory, error) {
- var records []*models.XtPatientSickHistory
- err := readDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, ids).Order("record_time desc").Find(&records).Error
- if err != nil {
- return nil, err
- }
- return records, nil
- }
-
- func GetPatienttPhysiqueByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientPhysiqueCheck, error) {
- var records []*models.XtPatientPhysiqueCheck
- err := readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, ids).Order("record_time desc").Find(&records).Error
- if err != nil {
- return nil, err
- }
- return records, nil
- }
-
- func GetPatientPhysiqueCheck(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientPhysiqueCheck, error) {
- var records []*models.XtPatientPhysiqueCheck
- err := readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
- if err != nil {
- return nil, err
- }
- return records, nil
- }
-
- func GetLastPatientPhysiqueCheck(orgID int64, patientID int64, record_date int64) (records models.XtPatientPhysiqueCheck, err error) {
- err = readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and record_date = ? and status = 1", orgID, patientID, record_date).Order("record_time desc").Last(&records).Error
- return records, err
- }
-
- func CreatePatientCourseOfDisease(record *models.PatientDiseaseCourse) error {
- err := writeDb.Model(&models.PatientDiseaseCourse{}).Create(record).Error
- return err
- }
-
- func CreatePatientSickHistory(record *models.XtPatientSickHistory) error {
- err := writeDb.Model(&models.XtPatientSickHistory{}).Create(record).Error
- return err
- }
-
- func CreatePatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error {
- err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).Create(record).Error
- return err
- }
- func GetPatientRescueRecords(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientRescueRecord, error) {
- var records []*models.PatientRescueRecord
- err := readDb.Model(&models.PatientRescueRecord{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
- if err != nil {
- return nil, err
- }
- return records, nil
- }
-
- func CreatePatientRescueRecord(record *models.PatientRescueRecord) error {
- err := writeDb.Model(&models.PatientRescueRecord{}).Create(record).Error
- return err
- }
-
- func ModifyPatientCourses(record *models.PatientDiseaseCourse) error {
- err := writeDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgID, record.PatientID, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
- return err
- }
-
- func ModifyPatientSickHistory(record *models.XtPatientSickHistory) error {
- err := writeDb.Save(record).Error
- //err := writeDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgId, record.PatientId, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
- return err
- }
-
- func ModifyPatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error {
- err := writeDb.Save(record).Error
- //err := writeDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgId, record.PatientId, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
- return err
- }
- func DeletePatientCoursesInBatch(orgID int64, patientID int64, recordIDs []int64) error {
- err := writeDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func DeletePatientSickHistoryInBatch(orgID int64, patientID int64, recordIDs []int64) error {
- err := writeDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func DeletePatientResuceRecordsInBatch(orgID int64, patientID int64, recordIDs []int64) error {
- err := writeDb.Model(&models.PatientRescueRecord{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func DeletePatientPhysiqueCheckInBatch(orgID int64, patientID int64, recordIDs []int64) error {
- err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
- return err
- }
-
- func GetFaPiaoPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
- var patient models.Patients
- err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return &patient, nil
- }
-
- func GetPatientByIDThree(orgID int64, patientID int64) (*models.Patients, error) {
- var patient models.Patients
- err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- } else {
- return nil, err
- }
- }
- return &patient, nil
- }
|