Exemple #1
0
        /// <summary>
        /// Retrieves the stocktaking report.
        /// </summary>
        /// <returns>a list of package barcode, medication type, expire date and expire status</returns>
        public List <StocktakingViewData> Stocktake()
        {
            List <MedicationPackage>   packages = MedicationPackageDAO.FindInStockPackagesInDistributionCentre(User.DistributionCentreId);
            List <StocktakingViewData> list     = new List <StocktakingViewData>();
            const int warningDays = 7;

            foreach (MedicationPackage package in packages)
            {
                ExpireStatus expireStatus = ExpireStatus.NotExpired;
                if (TimeProvider.Current.Now > package.ExpireDate)
                {
                    expireStatus = ExpireStatus.Expired;
                }
                else if (TimeProvider.Current.Now.AddDays(warningDays) > package.ExpireDate)
                {
                    expireStatus = ExpireStatus.AboutToExpired;
                }
                var row = new StocktakingViewData
                {
                    Barcode      = package.Barcode,
                    Type         = package.Type.Name,
                    ExpireDate   = package.ExpireDate.ToString("d", new CultureInfo("en-au")),
                    ExpireStatus = expireStatus
                };
                list.Add(row);
            }
            return(list);
        }
Exemple #2
0
        /// <summary>
        /// Discards a medication package.
        /// </summary>
        /// <param name="barcode">package barcode</param>
        /// <param name="isTrusted">whether to trust the source of the package</param>
        public void DiscardPackage(string barcode, bool isTrusted = true)
        {
            MedicationPackage package = ScanPackage(barcode);

            CheckMedicationPackageIsValid(package);
            if (!isTrusted)
            {
                CheckMedicationPackageStatus(package, PackageStatus.InStock);
                CheckStockDistributionCentre(package);
            }
            ManipulatePackage(package, PackageStatus.Discarded, User.DistributionCentreId, null, null);
            MedicationPackageDAO.UpdatePackage(package);
        }
Exemple #3
0
        /// <summary>
        /// Receives a medication package.
        /// </summary>
        /// <param name="barcode">package barcode</param>
        /// <param name="isTrusted">whether to trust the source of the package</param>
        public void ReceivePackage(string barcode, bool isTrusted = true)
        {
            MedicationPackage package = ScanPackage(barcode);

            CheckMedicationPackageIsValid(package);
            if (!isTrusted)
            {
                CheckMedicationPackageStatus(package, PackageStatus.InTransit);
                CheckDestinationDistributionCentre(package);
            }
            ManipulatePackage(package, PackageStatus.InStock, User.DistributionCentreId, null, null);
            MedicationPackageDAO.UpdatePackage(package);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        /// <summary>
        /// Identifies lost packages for a given package type.
        /// </summary>
        /// <param name="medicationTypeId">medication type id</param>
        /// <param name="scannedList">scanned barcode list</param>
        /// <returns>a list of the medication packages</returns>
        public List <MedicationPackage> AuditPackages(int medicationTypeId, List <string> scannedList)
        {
            List <MedicationPackage> lostPackages    = new List <MedicationPackage>();
            List <MedicationPackage> inStockPackages = GetInStockList(medicationTypeId);

            foreach (MedicationPackage package in inStockPackages)
            {
                if (!scannedList.Contains(package.Barcode))
                {
                    ManipulatePackage(package, PackageStatus.Lost, User.DistributionCentreId, null, null);
                    lostPackages.Add(package);
                    MedicationPackageDAO.UpdatePackage(package);
                }
            }
            return(lostPackages);
        }
Exemple #6
0
        /// <summary>
        /// Sends a medication package.
        /// </summary>
        /// <param name="barcode">package barcode</param>
        /// <param name="distributionCentreId">distribution centre id</param>
        /// <param name="isTrusted">whether to trust the source of the package</param>
        public void SendPackage(string barcode, int distributionCentreId, bool isTrusted = true)
        {
            DistributionCentre distributionCentre = DistributionCentreDAO.GetDistributionCentreById(distributionCentreId);

            CheckDistributionCentreIsValid(distributionCentre);
            MedicationPackage package = ScanPackage(barcode);

            CheckMedicationPackageIsValid(package);
            if (User.DistributionCentreId == distributionCentreId)
            {
                throw new ENETCareException(Properties.Resources.AnotherDistributionCentre);
            }
            if (!isTrusted)
            {
                CheckMedicationPackageStatus(package, PackageStatus.InStock);
                CheckStockDistributionCentre(package);
            }
            ManipulatePackage(package, PackageStatus.InTransit, null, User.DistributionCentreId, distributionCentreId);
            MedicationPackageDAO.UpdatePackage(package);
        }
Exemple #7
0
        /// <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);
        }
Exemple #8
0
 /// <summary>
 /// Retrieves a medication package by looking up its barcode.
 /// </summary>
 /// <param name="barcode">medication package barcode</param>
 /// <returns>a medication package corresponding to the barcode, or null if no matching medication package was found</returns>
 public MedicationPackage ScanPackage(string barcode)
 {
     return(MedicationPackageDAO.FindPackageByBarcode(barcode));
 }
Exemple #9
0
 public List <MedicationPackage> GetInStockList(int medicationTypeId)
 {
     return(MedicationPackageDAO.FindInStockPackagesInDistributionCentre(User.DistributionCentreId, medicationTypeId));
 }