public LabResponse CreateOrEdit(LabRequest request) { int result = 0; var response = new LabResponse { }; var _getDataLabPoli = _unitOfWork.LabItemRepository.Get(x => x.RowStatus == 0); #region ::DELETE FIRST:: var _deleteFormExamineLab = _unitOfWork.FormExamineLabRepository.Get(x => x.FormMedicalID == request.Data.FormMedicalID && x.LabType == Constants.NameConstant.Laboratorium); foreach (var item1 in _deleteFormExamineLab) { _unitOfWork.FormExamineLabRepository.Delete(item1.ID); } var poliId = PoliHandler.GetPoliIDBasedOnName(Constants.NameConstant.Laboratorium); var _deleteFormExamine = _unitOfWork.FormExamineRepository.GetFirstOrDefault(x => x.FormMedicalID == request.Data.FormMedicalID && x.PoliID == poliId); if (_deleteFormExamine != null) { _unitOfWork.FormExamineRepository.Delete(_deleteFormExamine.ID); } int deleteResult = _unitOfWork.Save(); #endregion //insert to Form Examine try { var _formExamine = new FormExamine { FormMedicalID = request.Data.FormMedicalID, PoliID = PoliHandler.GetPoliIDBasedOnName(Constants.NameConstant.Laboratorium), TransDate = DateTime.Now, CreatedBy = request.Data.Account.UserName, CreatedDate = DateTime.Now }; _unitOfWork.FormExamineRepository.Insert(_formExamine); foreach (var _id in request.Data.LabItemsId) { var _formExamineLabEntity = new FormExamineLab { FormMedicalID = request.Data.FormMedicalID, LabType = _getDataLabPoli.Where(x => x.ID == _id).FirstOrDefault().LabItemCategory.LabType, LabItemID = (Int32)_id, CreatedBy = request.Data.Account.UserName, CreatedDate = DateTime.Now }; _unitOfWork.FormExamineLabRepository.Insert(_formExamineLabEntity); } result = _unitOfWork.Save(); if (result > 0) { var _editQueuePoli = _unitOfWork.RegistrationRepository.GetById(request.Data.LoketData.Id); if (_editQueuePoli != null) { _editQueuePoli.Status = (int)RegistrationStatusEnum.Hold; _editQueuePoli.ModifiedBy = request.Data.Account.UserName; _editQueuePoli.ModifiedDate = DateTime.Now; _unitOfWork.RegistrationRepository.Update(_editQueuePoli); _unitOfWork.Save(); } } response.Status = true; response.Message = string.Format(Messages.LabItemAdded, result, request.Data.FormMedicalID); } catch (Exception ex) { response.Status = false; response.Message = Messages.GeneralError; } return(response); }
public ActionResult FormExamine() { var id = Request.QueryString["id"]; if (id == null) { return(View("Index", "Home", null)); } var request = new LoketRequest { Data = new LoketModel { Id = long.Parse(id.ToString()) } }; LoketResponse resp = new LoketHandler(_unitOfWork).GetDetail(request); PoliExamineModel model = new PoliExamineModel(); try { model.LoketData = resp.Entity; model.PatientAge = CommonUtils.GetPatientAge(model.LoketData.PatientBirthDateStr); var necessityTypeList = GetGeneralMasterByType(Constants.MasterType.NECESSITY_TYPE); var paymentTypeList = GetGeneralMasterByType(Constants.MasterType.PAYMENT_TYPE); model.NecessityTypeStr = necessityTypeList.FirstOrDefault(x => x.Value == model.LoketData.NecessityType.ToString()).Text; model.PaymentTypeStr = paymentTypeList.FirstOrDefault(x => x.Value == model.LoketData.PaymentType.ToString()).Text; // get default services List <PoliService> poliServicelist = _unitOfWork.PoliServicesRepository.Get(x => x.PoliID == model.LoketData.PoliToID && x.RowStatus == 0).ToList(); foreach (var item in poliServicelist) { ServiceModel servModel = Mapper.Map <Service, ServiceModel>(item.Service); model.DefaultServiceList.Add(servModel); } // get form examine if any FormPreExamine formPreExamine = _unitOfWork.FormPreExamineRepository.GetFirstOrDefault(x => x.FormMedicalID == model.LoketData.FormMedicalID); if (formPreExamine != null) { model.PreExamineData = Mapper.Map <FormPreExamine, PreExamineModel>(formPreExamine); } // get form examine if any FormExamine formExamine = _unitOfWork.FormExamineRepository.GetFirstOrDefault(x => x.FormMedicalID == model.LoketData.FormMedicalID); if (formExamine != null) { model.ExamineData = Mapper.Map <FormExamine, FormExamineModel>(formExamine); if (model.ExamineData.ICDInformation != null) { string[] arrIcds = model.ExamineData.ICDInformation.Split('|'); if (arrIcds.Length > 0) { model.ICDInformation1 = arrIcds[0]; model.ICDInformation2 = arrIcds[1]; model.ICDInformation3 = arrIcds[2]; } } // get form examine medicine if any List <FormExamineMedicine> formExamineMedicines = _unitOfWork.FormExamineMedicineRepository.Get(x => x.FormExamineID == formExamine.ID); foreach (var formExamineMedicine in formExamineMedicines) { if (formExamineMedicine.TypeID == ((int)MedicineTypeEnum.Medicine).ToString() || formExamineMedicine.TypeID == ((int)MedicineTypeEnum.Concoction).ToString()) { model.MedicineDataList.Add(Mapper.Map <FormExamineMedicine, FormExamineMedicineModel>(formExamineMedicine)); } else if (formExamineMedicine.TypeID == ((int)MedicineTypeEnum.Injection).ToString()) { model.InjectionDataList.Add(Mapper.Map <FormExamineMedicine, FormExamineMedicineModel>(formExamineMedicine)); } //else if (formExamineMedicine.TypeID == ((int)MedicineTypeEnum.Concoction).ToString()) // model.ConcoctionMedicine = formExamineMedicine.ConcoctionMedicine; } // get form examine lab and radiology if any List <FormExamineLab> formExamineLabs = _unitOfWork.FormExamineLabRepository.Get(x => x.FormMedicalID == formExamine.FormMedicalID); foreach (var formExamineLab in formExamineLabs) { if (formExamineLab.LabType == ((int)LabTypeEnum.Laboratorium).ToString()) { model.LabDataList.Add(Mapper.Map <FormExamineLab, FormExamineLabModel>(formExamineLab)); } else if (formExamineLab.LabType == ((int)LabTypeEnum.Radiology).ToString()) { model.RadiologyDataList.Add(Mapper.Map <FormExamineLab, FormExamineLabModel>(formExamineLab)); } } // get form examine service if any List <FormExamineService> formExamineServices = _unitOfWork.FormExamineServiceRepository.Get(x => x.FormExamineID == formExamine.ID); foreach (var formExamineService in formExamineServices) { if (!model.DefaultServiceList.Any(x => x.Id == formExamineService.ServiceID)) { model.ServiceDataList.Add(Mapper.Map <FormExamineService, FormExamineServiceModel>(formExamineService)); } } } else { model.ExamineData.DoctorID = model.LoketData.DoctorID; model.ExamineData.PoliID = model.LoketData.PoliToID; } var tempPoliList = BindDropDownPoliList(model.LoketData.PoliToID); ViewBag.PoliList = tempPoliList; ViewBag.DoctorList = BindDropDownDoctorList(int.Parse(tempPoliList[0].Value)); ViewBag.FinalStateList = BindDropDownFinalStateList(); ViewBag.ICDInfo = BindDropDownICDInfo(); } catch { return(BadRequestResponse); } return(View(model)); }
/// <summary> /// Create or edit PoliFormExamine /// </summary> /// <param name="request"></param> /// <returns></returns> public FormExamineResponse CreateOrEdit(FormExamineRequest request) { FormExamineResponse response = new FormExamineResponse(); if (request.Data.Id > 0) { try { var qry = _unitOfWork.FormExamineRepository.GetById(request.Data.Id); if (qry != null) { // save the old data var _oldentity = Mapper.Map <FormExamine, FormExamineModel>(qry); // update data _unitOfWork.FormExamineRepository.Update(qry); int resultAffected = _unitOfWork.Save(); if (resultAffected > 0) { response.Message = string.Format(Messages.ObjectHasBeenUpdated2, "PoliFormExamine", qry.ID); CommandLog(true, ClinicEnums.Module.FORM_EXAMINE, Constants.Command.EDIT_FORM_EXAMINE, request.Data.Account, request.Data, _oldentity); } else { response.Status = false; response.Message = string.Format(Messages.UpdateObjectFailed, "PoliFormExamine"); CommandLog(false, ClinicEnums.Module.FORM_EXAMINE, Constants.Command.EDIT_FORM_EXAMINE, request.Data.Account, request.Data, _oldentity); } } else { response.Status = false; response.Message = string.Format(Messages.UpdateObjectFailed, "PoliFormExamine"); CommandLog(false, ClinicEnums.Module.FORM_EXAMINE, Constants.Command.EDIT_FORM_EXAMINE, request.Data.Account, request.Data); } } catch (Exception ex) { response.Status = false; response.Message = Messages.GeneralError; if (request.Data != null && request.Data.Id > 0) { ErrorLog(ClinicEnums.Module.FORM_EXAMINE, Constants.Command.EDIT_FORM_EXAMINE, request.Data.Account, ex); } else { ErrorLog(ClinicEnums.Module.FORM_EXAMINE, Constants.Command.ADD_FORM_EXAMINE, request.Data.Account, ex); } } } else { using (var transaction = _context.Database.BeginTransaction()) { try { List <FormExamineMedicine> formExamineMedicine = new List <FormExamineMedicine>(); foreach (var item in request.Data.MedicineDataList) { var medicine = Mapper.Map <FormExamineMedicineModel, FormExamineMedicine>(item); medicine.CreatedBy = request.Data.Account.UserCode; medicine.CreatedDate = DateTime.Now; formExamineMedicine.Add(medicine); } foreach (var item in request.Data.LabDataList) { var lab = Mapper.Map <FormExamineLabModel, FormExamineLab>(item); lab.FormMedicalID = request.Data.LoketData.FormMedicalID; lab.CreatedBy = request.Data.Account.UserCode; lab.CreatedDate = DateTime.Now; _context.FormExamineLabs.Add(lab); _context.SaveChanges(); } List <FormExamineService> formExamineService = new List <FormExamineService>(); foreach (var item in request.Data.ServiceDataList) { var service = Mapper.Map <FormExamineServiceModel, FormExamineService>(item); service.CreatedBy = request.Data.Account.UserCode; service.CreatedDate = DateTime.Now; formExamineService.Add(service); } // update status the old registration to process QueuePoli oldRegistration = _context.QueuePolis.FirstOrDefault(x => x.ID == request.Data.LoketData.Id); oldRegistration.Status = (int)RegistrationStatusEnum.Process; _context.SaveChanges(); // create a new registration QueuePoli queue = Mapper.Map <LoketModel, QueuePoli>(request.Data.LoketData); queue.ID = 0; // reset queue.DoctorID = request.Data.DoctorToID == 0 ? (int?)null : request.Data.DoctorToID; queue.PoliFrom = queue.PoliTo; queue.PoliTo = request.Data.PoliToID; queue.CreatedBy = request.Data.Account.UserCode; queue.CreatedDate = DateTime.Now; queue.TransactionDate = DateTime.Now; queue.Status = (int)RegistrationStatusEnum.New; queue.SortNumber = GenerateSortNumber(request.Data.PoliToID, request.Data.DoctorToID); _context.QueuePolis.Add(queue); _context.SaveChanges(); FormExamine formExamine = Mapper.Map <FormExamineModel, FormExamine>(request.Data.ExamineData); formExamine.CreatedBy = request.Data.Account.UserCode; formExamine.CreatedDate = DateTime.Now; formExamine.FormExamineMedicines = formExamineMedicine; formExamine.FormExamineServices = formExamineService; // save the form examine data _context.FormExamines.Add(formExamine); _context.SaveChanges(); transaction.Commit(); response.Message = Messages.DataSaved; } catch (Exception ex) { transaction.Rollback(); response.Status = false; response.Message = Messages.GeneralError; if (request.Data != null && request.Data.Id > 0) { ErrorLog(ClinicEnums.Module.FORM_EXAMINE, Constants.Command.EDIT_FORM_EXAMINE, request.Data.Account, ex); } else { ErrorLog(ClinicEnums.Module.FORM_EXAMINE, Constants.Command.ADD_FORM_EXAMINE, request.Data.Account, ex); } } } } return(response); }