/// <summary>
        /// Inserts the specified prescription.
        /// </summary>
        /// <param name="prescription">The prescription.</param>
        public void Insert(Prescription prescription)
        {
            try
            {
                prescription.SetInfo(false);
                // prescription.Version = 0;
                // prescription.LastUpdatedDate = DateTime.Now;
                // prescription.CreatedDate = DateTime.Now;

                foreach (var item in prescription.PrescriptionDetails)
                {
                    item.SetInfo(false); // Version = 0);
                }
                this.Context.Prescription.Add(prescription);
                this.Context.SaveChanges();

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }
Пример #2
0
        /// <summary>
        /// Updates the form.
        /// </summary>
        /// <param name="patient">The patient.</param>
        private void UpdateForm(Patient patient)
        {
            Patient ptn = _patientRepo.GetById(patient.Id);
            this.bdsPatient.DataSource = ptn;
            _lastPrescription = _prescriptionRepo.GetLastByPatient(ptn.Id);

            if (_lastPrescription != null)
            {
                this.bdsPrescription.DataSource = _lastPrescription;
                var detailList = _prescriptionDetailRepo.GetByPrescription(_lastPrescription.Id);
                foreach (var detailItem in detailList)
                {
                    detailItem.MedicineName = detailItem.Medicine.Name;
                    detailItem.TradeName = detailItem.Medicine.TradeName;
                    detailItem.UnitName = detailItem.Medicine.Define.Name;
                }

                //this.bdsPrescription.DataSource = this.bdsPrescription;
                this.bdsPrescriptionDetail.DataSource = detailList;
                this.bdsPrescriptionDetail.ResetBindings(false);
                this.dataGridViewX1.Refresh();
            }
            else
            {
                this.bdsPrescription.Clear();
                this.bdsPrescriptionDetail.Clear();
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize()
        {
            this.btnDelete.Enabled = (this._isEditable);
            this._prescription = this._prescriptionRepo.Get(this._prescriptionId);

            var figures = _figureRepo.GetByClinicId(AppContext.CurrentClinic.Id);
            this.cboFigure.DataSource = figures;

            this.bdsPrescription.DataSource = this._prescription;
            foreach (var item in this._prescription.PrescriptionDetails)
            {
                item.TradeName = item.Medicine.TradeName;
                item.MedicineName = item.Medicine.Name;
                item.UnitName= item.Medicine.Define.Name;
            }
            this.bdsPrescriptionDetail.DataSource = this._prescription.PrescriptionDetails;
        }
Пример #4
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize()
        {
            this._vWareHouseDetailList = new List<VWareHouseDetail>();
            this.bdsMedicine.DataSource = _medicineRepo.GetAll();
            this._medDeliveryAllocationList = new List<MedicineDeliveryAllocationEntity>();
            this._prescription = _prescriptionRepo.Get(this._prescriptionId);
            this.bdsPrescription.DataSource = this._prescription;
            this._prescriptionDetailList = _prescriptionDetailRepo.GetByPrescription(this._prescriptionId);
            if (_prescription == null || this._prescriptionDetailList == null) throw new Exception("Data dosenot existed");

            this._medicineDelivery = this._medicineDeliveryRepo.GetByPrescriptionId(this._prescriptionId);
            this._formMode = this._medicineDelivery == null ? ViewModes.Add : ViewModes.View;

            if (this._formMode == ViewModes.Add)
            {
                // Createe MachineDelivery
                // Create MachineDeliveryDetail
                // Craete MedicindeDeliveryDetailAllocate
                // Get WareHouseDetail
                // Get WareHouse;
                // this._warehouseDetailList  = this._warehouseDetailRepo
                var medincineIdList = this._prescriptionDetailList.Select(item => item.MedicineId).ToList();
                this._warehouseList = this._warehouseRepo.GetByMedicineId(medincineIdList, AppContext.CurrentClinic.Id);
                this._vWareHouseDetailList = this._vWareHouseDetailRepo.GetByMedicine(medincineIdList);
                this._medicineDelivery = CreatePrescription(this._prescription);
                this._medicineDeliveryDetailList = CreateMedicineDeliveryDetail(this._prescriptionDetailList);
                this.AutoAllocate(this._medicineDeliveryDetailList, this._vWareHouseDetailList);
                // this._warehouseDetailList = this._warehouseDetailRepo.GetByMedicine(medincineIdList, AppContext.CurrentClinic.Id);)
                // this._mdecidineDeliveryDetailAllocate = AutoAllocate(this._medicineDeliveryDetailList, this._warehouseDetailList);
                // var item = this._warehouseDetailList.Select(x => new { x.MedicineId, x.LotNo, x.ExpiredDate}).GroupBy(x => new { x.MedicineId, x.LotNo, x.ExpiredDate }).ToList();

                var no = 1;
                foreach (var deliveryItem in this._medicineDeliveryDetailList)
                {
                    // var allocatedList = this._mdecidineDeliveryDetailAllocate.Where(x => x.MedicineDeliveryDetailId == deliveryItem.Id).ToList();
                    var warehouse = this._warehouseList.FirstOrDefault(x => x.MedicineId == deliveryItem.MedicineId);
                    var item = new MedicineDeliveryAllocationEntity(no++, deliveryItem, warehouse);
                    this._medDeliveryAllocationList.Add(item);

                    var subNo = 1;
                    foreach (var itm in deliveryItem.AllocatedWareHouseDetail)
                    {
                        var subItem = new MedicineDeliveryAllocationEntity(subNo++, itm);
                        _medDeliveryAllocationList.Add(subItem);
                    }
                }
                this.bindingSource1.DataSource = this._medDeliveryAllocationList;
            } else {
                var medincineIdList = this._prescriptionDetailList.Select(item => item.MedicineId).ToList();
                this._warehouseList = this._warehouseRepo.GetByMedicineId(medincineIdList, AppContext.CurrentClinic.Id);
                this._vWareHouseDetailList = this._vWareHouseDetailRepo.GetByMedicine(medincineIdList);

                this._medicineDelivery = this._medicineDeliveryRepo.GetByPrescriptionId(this._prescription.Id);
                this._medicineDeliveryDetailList = this._medicineDeliveryDetailRepo.GetByDelivery(this._medicineDelivery.Id);
                var deliveryDetailList = this._medicineDeliveryDetailList.Select(x => x.Id).ToList();
                this._vMedicineDeliveryDetailAllocateds = this._medicineDeliveryDetailRepo.GetDeliveryDetailAllocateds(deliveryDetailList);
                // this._mdecidineDeliveryDetailAllocate = AutoAllocate(this._medicineDeliveryDetailList, this._warehouseDetailList);
                // var item = this._warehouseDetailList.Select(x => new { x.MedicineId, x.LotNo, x.ExpiredDate}).GroupBy(x => new { x.MedicineId, x.LotNo, x.ExpiredDate }).ToList();
                // this._warehouseDetailList = this._warehouseDetailRepo.GetByMedicine(medincineIdList, AppContext.CurrentClinic.Id);)

                var no = 1;
                foreach (var deliveryItem in this._medicineDeliveryDetailList) {
                    // var allocatedList = this._mdecidineDeliveryDetailAllocate.Where(x => x.MedicineDeliveryDetailId == deliveryItem.Id).ToList();
                    var warehouse = this._warehouseList.FirstOrDefault(x => x.MedicineId == deliveryItem.MedicineId);
                    var item = new MedicineDeliveryAllocationEntity(no++, deliveryItem, warehouse);
                    this._medDeliveryAllocationList.Add(item);

                    List<VMedicineDeliveryDetailAllocated> allocatedWareHouseDetailList =
                        this._vMedicineDeliveryDetailAllocateds.Where(x => x.MedicineDeliveryDetailId == deliveryItem.Id)
                            .ToList();
                    var subNo = 1;
                    foreach (var itm in allocatedWareHouseDetailList) {
                        var subItem = new MedicineDeliveryAllocationEntity(subNo++, itm);
                        _medDeliveryAllocationList.Add(subItem);
                    }
                }
                this.dataGridViewX1.Columns[6].Visible = false;
                this.dataGridViewX1.Columns[8].Visible = false;
                this.bindingSource1.DataSource = this._medDeliveryAllocationList;

            }
        }
Пример #5
0
 /// <summary>
 /// Creates the prescription.
 /// </summary>
 /// <param name="prescription">The prescription.</param>
 /// <returns></returns>
 private MedicineDelivery CreatePrescription(Prescription prescription)
 {
     var medicineDelivery = new MedicineDelivery
                                {
                                    ClinicId = AppContext.CurrentClinic.Id,
                                    Date = DateTime.Today,
                                    PatientId = prescription.PatientId,
                                    PrescriptionId = prescription.Id
                                };
     return medicineDelivery;
 }
Пример #6
0
        /// <summary>
        /// Initializes the specified patient.
        /// </summary>
        /// <param name="patient">The patient.</param>
        private void Initialize(Patient patient)
        {
            this._isSkipUpdatingFigure = true;

            try
            {
                this._patient = patient;

                // Initialize combobox
                //var figures = _figureRepo.GetAll();
                // thangnn edit
                var figures = _figureRepo.GetByClinicId(AppContext.CurrentClinic.Id);
                // end
                this.cboFigure.DataSource = figures;
                // Get Doctor Name
                this.txtDoctor.Text = AppContext.LoggedInUser.Name;
                var medicines = _medicineRepo.GetAll();
                medicines.Insert(0, new Medicine() { Id = 0, Name = "..." });
                this.bdsMedicine.DataSource = medicines;

                // Get existing prescription
                this._prescription = _precriptionRepo.GetCurrent(patient.Id);
                var lastPrescription = _precriptionRepo.GetLastByPatient(patient.Id);

                // Binding data
                if (this._prescription == null)
                {
                    this._isUpdate = false;
                    this._prescription = new Prescription
                                             {
                                                 Date = DateTime.Today,
                                                 RecheckDate = DateTime.Today.AddDays(DefaultVolumn),
                                                 DoctorId = AppContext.LoggedInUser.Id,
                                                 //Doctor = AppContext.LoggedInUser,
                                                 PatientId = patient.Id,
                                                 CreatedUser = AppContext.LoggedInUser.Id,
                                                 LastUpdatedUser = AppContext.LoggedInUser.Id,
                                                 ClinicId = AppContext.CurrentClinic.Id
                                             };

                    this._prescriptionDetailList = new List<PrescriptionDetail>();

                    if (lastPrescription != null)
                    {
                        // this._prescription.Note = lastPrescription.Note;
                        // this._prescription.FigureId = lastPrescription.FigureId;

                        // Create FigureId
                        //var figureDetails = this._figureDetailRepo.GetByFigure(lastPrescription.FigureId);
                        //foreach (var figureDetail in figureDetails)
                        //{
                        //    var prescriptionDetail = new PrescriptionDetail
                        //                                 {
                        //                                     No = this._prescriptionDetailList.Count + 1,
                        //                                     FigureDetailId = figureDetail.Id,
                        //                                     MedicineId = figureDetail.MedicineId,
                        //                                     Medicine = figureDetail.Medicine,
                        //                                     VolumnPerDay = figureDetail.Volumn,
                        //                                     Day = DefaultVolumn,
                        //                                     Amount = DefaultVolumn*figureDetail.Volumn,
                        //                                     Version = 0
                        //                                 };
                        //    this._prescriptionDetailList.Add(prescriptionDetail);
                        //}
                    }

                    this._prescription.PrescriptionDetails = this._prescriptionDetailList;
                }
                else
                {
                    this._isUpdate = true;
                    this._prescription.DoctorId = AppContext.LoggedInUser.Id;
                    //this._prescription.Doctor = AppContext.LoggedInUser;
                    this._prescription.LastUpdatedUser = AppContext.LoggedInUser.Id;
                }

                Initialize(this._prescription);
            }
            finally
            {
                this._isSkipUpdatingFigure = false;
            }
        }
Пример #7
0
 /// <summary>
 /// Initializes the specified prescription.
 /// </summary>
 /// <param name="prescription">The prescription.</param>
 private void Initialize(Prescription prescription)
 {
     this.bdsPrescription.DataSource = prescription;
     this.bdsPrescriptionDetail.DataSource = prescription.PrescriptionDetails;
     ReupdateNo();
 }
Пример #8
0
 /// <summary>
 /// Initializes this instance.
 /// </summary>
 private void initialize()
 {
     this._prescription = this._prescriptionRepo.Get(this._prescriptionId);
     this.bdsPrescription.DataSource = this._prescription;
     this.bdsPrescriptionDetail.DataSource = this._prescription.PrescriptionDetails;
 }
        /// <summary>
        /// Updates the specified prescription.
        /// </summary>
        /// <param name="prescription">The prescription.</param>
        public void Update(Prescription prescription)
        {
            try
            {
                
                var originalPres = this.Context.Prescription.FirstOrDefault(x => x.Id == prescription.Id);
                if (originalPres == null) throw new Exception("Không tồn tại dữ liệu trong CSDL.");

                var prescriptionList = this.Context.PrescriptionDetails.Where(x => x.PrescriptionId == prescription.Id).ToList();
                
                originalPres.RecheckDate = prescription.RecheckDate;
                originalPres.Note = prescription.Note;
                originalPres.DoctorId = prescription.DoctorId;
                originalPres.Doctor = null;
                originalPres.FigureId = prescription.FigureId;
                originalPres.Version++;


                foreach (var orginItem in prescriptionList)
                {
                    var item = prescription.PrescriptionDetails.FirstOrDefault(x => x.Id == orginItem.Id);
                    if (item == null)
                    {
                        this.Context.PrescriptionDetails.Remove(orginItem);
                    }
                    else
                    {
                        orginItem.MedicineId = item.MedicineId;
                        orginItem.Day = item.Day;
                        orginItem.Description = item.Description;
                        orginItem.Amount = item.Amount;
                        orginItem.FigureDetailId = item.FigureDetailId;
                        orginItem.VolumnPerDay = item.VolumnPerDay;
                    }

                }

                foreach (var orginItem in prescription.PrescriptionDetails)
                {
                    var item = originalPres.PrescriptionDetails.FirstOrDefault(x => x.Id == orginItem.Id);
                    if (item != null) continue;
                    var newItem = new PrescriptionDetail
                                      {
                                          Amount = orginItem.Amount,
                                          Day = orginItem.Day,
                                          Description = orginItem.Description,
                                          FigureDetailId = orginItem.FigureDetailId,
                                          MedicineId = orginItem.MedicineId,
                                          PrescriptionId = orginItem.PrescriptionId,
                                          Version = 0
                                      };
                    originalPres.PrescriptionDetails.Add(newItem);
                }

                originalPres.LastUpdatedDate = DateTime.Now;
                

                this.Context.SaveChanges();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #10
0
 /// <summary>
 /// Initializes the specified prescription.
 /// </summary>
 /// <param name="prescription">The prescription.</param>
 private void Initialize(Prescription prescription)
 {
     this.bdsPrescription.DataSource = prescription;
     this.bdsPrescriptionDetail.DataSource = prescription.PrescriptionDetails;
     if (this._isEditable)
     {
         txtReCheckDate.Enabled = true;
         cboFigure.Enabled = true;
         txtStatus.ReadOnly = false;
         dataGridViewX1.ReadOnly = false;
         mnuDelete.Enabled = true;
     }
     else
     {
         txtReCheckDate.Enabled = false;
         cboFigure.Enabled = false;
         txtStatus.ReadOnly = true;
         dataGridViewX1.ReadOnly = true;
         mnuDelete.Enabled = false;
     }
 }
Пример #11
0
        /// <summary>
        /// Initializes the specified patient.
        /// </summary>
        /// <param name="patient">The patient.</param>
        private void Initialize(Patient patient)
        {
            this._isSkipUpdatingFigure = true;

            try
            {
                // this._patient = patient;

                // Initialize combobox
                // thangnn edit
                var figures = _figureRepo.GetByClinicId(AppContext.CurrentClinic.Id);

                this.cboFigure.DataSource = figures;

                // Get Doctor Name
                this.txtDoctor.Text = AppContext.LoggedInUser.Name;
                var medicines = _medicineRepo.GetAll();
                medicines.Insert(0, new Medicine() { Id = 0, Name = "..." });
                this.bdsMedicine.DataSource = medicines;

                // Get existing prescription
                this._prescription = _precriptionRepo.GetCurrent(patient.Id);
                // var lastPrescription = _precriptionRepo.GetLastByPatient(patient.Id);

                // Binding data
                if (this._prescription == null)
                {
                    this._isEditable = true;
                    this._isUpdate = false;
                    this._prescription = new Prescription
                                             {
                                                 Date = DateTime.Today,
                                                 RecheckDate = DateTime.Today.AddDays(DefaultVolumn),
                                                 DoctorId = AppContext.LoggedInUser.Id,
                                                 PatientId = patient.Id,
                                                 CreatedUser = AppContext.LoggedInUser.Id,
                                                 LastUpdatedUser = AppContext.LoggedInUser.Id,
                                                 ClinicId = AppContext.CurrentClinic.Id
                                             };

                    this._prescriptionDetailList = new List<PrescriptionDetail>();
                    this._prescription.PrescriptionDetails = this._prescriptionDetailList;
                }
                else
                {
                    var delivered = _medicineDeliveryRepo.GetByPrescriptionId(this._prescription.Id);
                    this._prescriptionDetailList = this._prescription.PrescriptionDetails;
                    this._isEditable = delivered == null;
                    this._isUpdate = true;
                    this._prescription.DoctorId = AppContext.LoggedInUser.Id;
                    this._prescription.LastUpdatedUser = AppContext.LoggedInUser.Id;
                    foreach (var detailItem in this._prescription.PrescriptionDetails)
                    {
                        detailItem.MedicineName = detailItem.Medicine.Name;
                        detailItem.TradeName= detailItem.Medicine.TradeName;
                        detailItem.UnitName= detailItem.Medicine.Define.Name;
                    }
                }

                Initialize(this._prescription);
            }
            finally
            {
                this._isSkipUpdatingFigure = false;

            }
        }
        /// <summary>
        /// Inserts the specified prescription.
        /// </summary>
        /// <param name="prescription">The prescription.</param>
        public void Insert(Prescription prescription)
        {
            prescription.SetInfo(false);
            this.Context.Prescription.Add(prescription);
            this.Context.SaveChanges();

            foreach (var item in prescription.PrescriptionDetails)
            {
                item.PrescriptionId = prescription.Id;
                item.SetInfo(false); // Version = 0);
                //this.Context.PrescriptionDetails.Add(item);
            }
            this.Context.SaveChanges();
        }
Пример #13
0
        /// <summary>
        /// Updates the form.
        /// </summary>
        /// <param name="patient">The patient.</param>
        private void UpdateForm(Patient patient)
        {
            this.bdsPrescription.Clear();
            this.bdsPrescriptionDetail.Clear();
            this.bdsPatient.DataSource = patient;
            this.selectedPatient = patient;

            if (patient == null)
            {
                this.btnCheck.Enabled = false;
                return;
            }

            this.btnCheck.Enabled = true;
            lastPrescription = prescriptionRepo.GetLastByPatient(patient.Id);

            if (lastPrescription == null) return;
            this.bdsPrescription.DataSource = lastPrescription;

            List<PrescriptionDetail> detailList = prescriptionDetailRepo.GetByPrescription(lastPrescription.Id);
            if (detailList != null)
            {
                for (int i = 0; i < detailList.Count; i++)
                {
                    detailList[i].No = i + 1;
                }
                this.bdsPrescriptionDetail.DataSource = detailList;
            }
        }