public async Task <IActionResult> DeletePrescription([FromRoute] int id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var prescription = await _prescriptionRepository.FindAsync(id);

            if (prescription == null)
            {
                return(NotFound());
            }

            foreach (var medicinePrescription in prescription.MedicinePrescriptions)
            {
                Medicine medicine = await _medicineRepository.FindAsync(medicinePrescription.MedicineId);

                medicine.Stock += medicinePrescription.Quantity;
                _medicineRepository.Update(medicine);
            }

            _prescriptionRepository.Delete(prescription);

            await _prescriptionRepository.SaveChangesAsync();

            return(Ok(prescription));
        }
예제 #2
0
        public bool DeletePrescription(PrescriptionDto prescription)
        {
            var entity = mDtoMapper.Map(prescription);


            return(mPrescriptionRepository.Delete(entity));
        }
예제 #3
0
        private void ProcessPrescriptionData(IEnumerable <Prescription> prescriptions, DataOP op, Treatment treatment)
        {
            if (prescriptions == null || treatment == null)
            {
                return;
            }

            foreach (var prescription in prescriptions)
            {
                prescription.TreatmentId = treatment.Id;
                if (DataOP.AddNew == op)
                {
                    _prescriptionRepository.Add(prescription);
                }
                else if (DataOP.EDIT == op)
                {
                    _prescriptionRepository.Update(prescription);
                }
                else if (DataOP.DEL == op)
                {
                    var removeRecord = _prescriptionRepository.GetById(prescription.Id);
                    if (removeRecord != null)
                    {
                        _prescriptionRepository.Delete(removeRecord);
                    }
                }
            }
        }
예제 #4
0
 public bool DeletePrescription(int prescriptionId)
 {
     return(_prescriptionRepository.Delete(prescriptionId));
 }
예제 #5
0
        public ActionResult Edit(MyClinic.Infrastructure.PrescriptionAdd itemAdd)
        {
            this.GetUserProfile();
            bool checkError = true;
            PrescriptionModels               viewModel           = null;
            DTODiagnosis                     dtoDiagnosis        = null;
            IEnumerable <MedicineType>       medicineTypeRecords = null;
            IEnumerable <vMedicineDiagnosis> medicineRecords     = null;
            string diffString = "";

            try
            {
                IMedicineTypeRepository objMedicineType     = new MedicineTypeRepository();
                IDiagnosisRepository    diagnosisRepository = new DiagnosisRepository();
                dtoDiagnosis    = diagnosisRepository.GetDTODiagnosisById(itemAdd.DiagnosisId);
                medicineRecords = objPrescription.GetPrescriptionDiagnosis(itemAdd.DiagnosisId);
                if (ModelState.IsValid)
                {
                    var intTotal = 0;
                    if (itemAdd.MedicineId != null)
                    {
                        intTotal = itemAdd.MedicineId.Count();
                    }

                    foreach (var record in medicineRecords)
                    {
                        bool blnFound = false;
                        for (int intIndex = 0; intIndex < intTotal; intIndex++)
                        {
                            var intId = 0;
                            if (int.TryParse(itemAdd.Id[intIndex], out intId))
                            {
                                if (intId == record.Id)
                                {
                                    blnFound = true;
                                    Prescription itemOld = new Prescription();
                                    itemOld.DiagnosisId = record.DiagnosisId;
                                    itemOld.Id          = record.Id;
                                    itemOld.MedicineId  = record.MedicineId;
                                    itemOld.Qty         = record.Qty;
                                    //itemOld.MedicineType = record.MedicineType;
                                    itemOld.Morning = record.Morning;
                                    itemOld.Noon    = record.Noon;
                                    itemOld.Night   = record.Night;
                                    itemOld.Remark  = record.Remark;
                                    itemOld.UsageId = record.UsageId;

                                    Prescription itemNew = new Prescription();
                                    int          itemId  = 0;
                                    int.TryParse(itemAdd.Id[intIndex], out itemId);
                                    itemNew.DiagnosisId = record.DiagnosisId;
                                    itemNew.Id          = itemId;
                                    int MedicineId = 0;
                                    int.TryParse(itemAdd.MedicineId[intIndex], out MedicineId);
                                    itemNew.MedicineId = MedicineId;
                                    itemNew.Qty        = itemAdd.Qty[intIndex];
                                    //itemNew.MedicineType = itemAdd.MedicineType[intIndex];
                                    itemNew.Morning = itemAdd.Morning[intIndex];
                                    itemNew.Noon    = itemAdd.Noon[intIndex];
                                    itemNew.Night   = itemAdd.Night[intIndex];
                                    itemNew.Remark  = itemAdd.Remark[intIndex];
                                    itemNew.UsageId = int.Parse(itemAdd.UsageId[intIndex]);
                                    itemNew.Status  = record.Status;
                                    diffString      = diffString + itemOld.EnumeratePropertyDifferencesInString(itemNew);
                                    objPrescription.Update(itemNew);
                                }
                            }
                        }
                        if (blnFound == false)
                        {
                            objPrescription.Delete(record.Id);
                        }
                    }
                    for (int intIndex = 0; intIndex < intTotal; intIndex++)
                    {
                        int itemId = 0;
                        int.TryParse(itemAdd.Id[intIndex], out itemId);
                        if (itemId == 0)
                        {
                            Prescription itemGet = new Prescription();
                            itemGet.DiagnosisId = itemAdd.DiagnosisId;
                            int MedicineId = 0;
                            int.TryParse(itemAdd.MedicineId[intIndex], out MedicineId);
                            itemGet.MedicineId = MedicineId;
                            itemGet.Qty        = itemAdd.Qty[intIndex];
                            //itemGet.MedicineType = itemAdd.MedicineType[intIndex];
                            itemGet.Morning = itemAdd.Morning[intIndex];
                            itemGet.Noon    = itemAdd.Noon[intIndex];
                            itemGet.Night   = itemAdd.Night[intIndex];
                            itemGet.Remark  = itemAdd.Remark[intIndex];
                            itemGet.UsageId = int.Parse(itemAdd.UsageId[intIndex]);
                            itemGet.Status  = (int)MyClinic.Core.Enums.RecordStatus.Active;
                            objPrescription.Add(itemGet);
                        }
                    }

                    /*For Add New Record to LogTable*/
                    logTran.UserId      = this.objProfile.UserId;
                    logTran.ProcessType = "Edit Prescription";
                    logTran.Description = "Edit Prescription value as follow: " + diffString;
                    logTran.LogDate     = DateTime.Now;
                    logRepository.Add(logTran);
                    return(RedirectToAction("Detail", "Prescription", new { id = itemAdd.DiagnosisId }));

                    checkError = false;
                }
                medicineTypeRecords = objMedicineType.Get();
            }
            catch (Exception ex)
            {
                log.Error(ex);
                ModelState.AddModelError("error", Translator.UnexpectedError);
            }
            if (checkError == true)
            {
                viewModel = new PrescriptionModels
                {
                    validAdd            = itemAdd,
                    checkPost           = true,
                    checkError          = checkError,
                    dtoDiagnosis        = dtoDiagnosis,
                    medicineTypeRecords = medicineTypeRecords,
                    medicineRecords     = medicineRecords
                };
                return(View(viewModel));
            }
            else
            {
                return(RedirectToAction("Index", "Diagnosis"));
            }
        }
 public void Delete(Prescription entity)
 {
     _prescriptionRepository.Delete(entity);
 }
예제 #7
0
        public bool DeletePrescription(PrescriptionDTO prescription)
        {
            var entity = _DTOMappers.Map(prescription);

            return(_prescriptionRepository.Delete(entity));
        }