public BillHistoryModel GetByOPDId(Guid id) { try { BillHistoryModel model = new BillHistoryModel(); using (var db = new HMSEntities()) { BillHistory entity = db.BillHistories.Find(id); if (entity != null) { model.Id = entity.Id; model.PatientId = entity.PatientId; model.OPDHistoryId = entity.OPDHistoryId; model.ReceiptNumber = entity.ReceiptNumber; model.PrintCopys = entity.PrintCopys; model.CreatedOn = entity.CreatedOn; model.CreatedBy = entity.CreatedBy; model.LastPrintedOn = entity.LastPrintedOn; model.LastPrintedBy = entity.LastPrintedBy; } } return(model); } catch (Exception ex) { throw ex; } }
private bool IsExist(BillHistoryModel model) { try { Expression <Func <BillHistory, bool> > predicate = null; using (var db = new HMSEntities()) { /* Build Predicate according to Create or Update */ if (!model.Id.HasValue) { predicate = o => o.OPDHistoryId == model.OPDHistoryId;//for Create Record } else { predicate = o => o.OPDHistoryId == model.OPDHistoryId && o.Id != model.Id;//for Update Record Record } /* return is Exist or not */ if (db.BillHistories.Any(predicate)) { return(true); } else { return(false); } } } catch (Exception ex) { throw ex; } }
public bool Create(BillHistoryModel model) { try { bool isSaved = false; if (!IsExist(model)) { using (var db = new HMSEntities()) { BillHistory entity = new BillHistory(); entity.PatientId = model.PatientId; entity.OPDHistoryId = model.OPDHistoryId; entity.PrintCopys = 1; int?recpNumber = db.BillHistories.Select(t => t.ReceiptNumber).DefaultIfEmpty(0).Max(); entity.ReceiptNumber = recpNumber == null ? 1 : recpNumber.Value + 1; entity.CreatedOn = DateTime.Now; entity.CreatedBy = UserDetailSession.Id; db.BillHistories.Add(entity); db.SaveChanges(); isSaved = true; } } return(isSaved); } catch (Exception ex) { throw ex; } }
public bool Create(BillHistoryModel model) { try { BillHistory entity = new BillHistory(); return(entity.Create(model)); } catch (Exception ex) { throw ex; } }
public bool Update(OPDHistoryModel model) { try { bool isSaved = false; List <OPDHistoryUpdateModel> listUpdateModel = new List <OPDHistoryUpdateModel>(); using (var db = new HMSEntities()) { OPDHistory entity = db.OPDHistories.Find(model.Id); listUpdateModel = OPDHistoryModifications(entity, model); entity.PatientId = model.PatientId; entity.InTime = model.InTime; entity.OutTime = model.OutTime; entity.IsCharity = model.IsCharity; entity.IsLabCharity = model.IsLabCharity; entity.IsECG = model.IsECG.HasValue ? model.IsECG : false; entity.IsXRAY = model.IsXRAY.HasValue ? model.IsXRAY : false; entity.ConsultingDoctorId = model.ConsultingDoctorId; entity.StatusId = model.StatusId; entity.Amount = model.Amount; entity.PaidAmount = model.PaidAmount; entity.DueAmount = model.DueAmount; entity.TotalAmount = model.TotalAmount; entity.LabTestingAmount = model.LabTestingAmount; entity.ECGAmount = model.ECGAmount.HasValue ? model.ECGAmount : 0.00M; entity.XRAYAmount = model.XRAYAmount.HasValue ? model.XRAYAmount : 0.00M; entity.NumberofXRAY = model.NumberofXRAY.HasValue ? model.NumberofXRAY : 0; entity.ThirdPartyLabId = model.ThirdPartyLabId; entity.ThirdPartyLabAmoumt = model.ThirdPartyLabAmoumt.HasValue ? model.ThirdPartyLabAmoumt : 0.00M; string status = Status.GetNameById(model.StatusId); if (status == OPD_STATUS.Done.ToString()) { entity.ReceivedBy = UserDetailSession.Id; } else { entity.ReceivedBy = model.ReceivedBy; } entity.Diagnose = model.Diagnose; entity.Madicines = model.Madicines; entity.ModifiedBy = UserDetailSession.Id; db.SaveChanges(); OPDHistoryUpdate opdHistoryUpdate = new OPDHistoryUpdate(); opdHistoryUpdate.Create(listUpdateModel); if (status == OPD_STATUS.Done.ToString()) { BillHistoryModel billModel = new BillHistoryModel(); billModel.PatientId = model.PatientId.Value; billModel.OPDHistoryId = model.Id.Value; new BillHistory().Create(billModel); } isSaved = true; } return(isSaved); } catch (Exception ex) { throw ex; } }