void CheckMedicationTypeIsValid(MedicationType type) { if (type == null) { throw new ENETCareException(Properties.Resources.MedicationTypeNotFound); } }
/// <summary> /// Helper-method to create a medication type for a row of the database. /// </summary> /// <param name="reader"></param> /// <returns></returns> MedicationType GetMedicationTypeFromDataReader(SqlDataReader reader) { MedicationType type = new MedicationType(); type.ID = reader.GetInt32(0); type.Name = reader.GetString(1); type.Description = reader.GetString(2); type.ShelfLife = reader.GetInt16(3); type.Value = reader.GetDecimal(4); type.IsSensitive = reader.GetBoolean(5); return(type); }
/// <summary> /// Registers a medication package. /// </summary> /// <param name="medicationTypeId">medication type id</param> /// <param name="expireDate">package expire date</param> /// <param name="barcode">package barcode</param> /// <returns>generated barcode number</returns> public string RegisterPackage(int medicationTypeId, string expireDate, string barcode = "") { DateTime parsedExpireDate; if (!DateTime.TryParse(expireDate, out parsedExpireDate)) { throw new ENETCareException(Properties.Resources.InvalidDateFormat); } MedicationType medicationType = MedicationTypeDAO.GetMedicationTypeById(medicationTypeId); CheckMedicationTypeIsValid(medicationType); return(RegisterPackage(medicationType, parsedExpireDate, barcode)); }
string RegisterPackage(MedicationType medicationType, DateTime expireDate, string barcode) { MedicationPackage package = new MedicationPackage(); if (string.IsNullOrEmpty(barcode)) { barcode = BarcodeHelper.GenerateBarcode(); } package.Barcode = barcode; package.TypeId = medicationType.ID; package.ExpireDate = expireDate; ManipulatePackage(package, PackageStatus.InStock, User.DistributionCentreId, null, null); MedicationPackageDAO.InsertPackage(package); return(barcode); }
/// <summary> /// Retrieves all medication types in the database. /// </summary> /// <returns>a list of all the medication types</returns> public List <MedicationType> FindAllMedicationTypes() { List <MedicationType> medicationTypeList = new List <MedicationType>(); using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConnectionString; conn.Open(); string query = @"select ID, Name, ISNULL(Description, ''), ShelfLife, Value, IsSensitive from MedicationType" ; SqlCommand command = new SqlCommand(query, conn); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { MedicationType type = GetMedicationTypeFromDataReader(reader); medicationTypeList.Add(type); } } } return(medicationTypeList); }
/// <summary> /// Check whether a package is unexpected and has its status/location updated /// </summary> /// <param name="medicationTypeId">medication type id</param> /// <param name="barcode">package barcode</param> /// <returns>true if status/location of the package has been updated, or false if not</returns> public bool CheckAndUpdatePackage(int medicationTypeId, string barcode) { bool updated = false; MedicationPackage package = MedicationPackageDAO.FindPackageByBarcode(barcode); if (package == null) { MedicationType medicationType = MedicationTypeDAO.GetMedicationTypeById(medicationTypeId); DateTime expireDate = medicationType.DefaultExpireDate; RegisterPackage(medicationType, expireDate, barcode); updated = true; } else if (package.TypeId != medicationTypeId) { throw new ENETCareException(Properties.Resources.MedicationTypeNotMatched); } else if (package.Status != PackageStatus.InStock || package.StockDCId != User.DistributionCentreId) { ManipulatePackage(package, PackageStatus.InStock, User.DistributionCentreId, null, null); MedicationPackageDAO.UpdatePackage(package); updated = true; } return(updated); }