protected void btnEdit_Click(object sender, EventArgs e) { try { if (Page.IsValid) { int id = -1; string _id = Request.QueryString["id"].ToString(); int.TryParse(_id, out id); int userId = CurrentEnvironment.LoggedUser.Id; Uom o = Uom.GetUomById(id); o.Name = txtName.Text.Replace("'", @"''"); o.Notes = txtNotes.Text.Replace("'", @"''"); int i = Uom.Update(o); if (i > 0) { lblSuccess.Visible = true; lblWarning.Visible = false; lblError.Visible = false; gvUom.DataSource = Uom.GetUomList(); gvUom.DataBind(); ClearControls(this); } else { lblSuccess.Visible = false; lblWarning.Visible = true; lblError.Visible = false; } } } catch (Exception ex) { lblSuccess.Visible = false; lblWarning.Visible = false; lblError.Visible = true; } }
public void SuccessfulCompleteOrderManagementFlowTest() { try { // Order logic OrderManagementLogic orderLogic = new OrderManagementLogic(); HealthFacility from = HealthFacility.GetHealthFacilityByCode("HF888"); HealthFacility to = HealthFacility.GetHealthFacilityByCode("HF999"); DateTime orderDate = DateTime.Now; // Step 1 : Create an Order var orderHeader = orderLogic.RequestOrder(from, to, orderDate, 1); // Assert that Step 1 actually creates the Order Header Assert.IsNotNull(orderHeader.OrderNum); Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id); Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id); Assert.AreEqual(orderDate, orderHeader.OrderSchedReplenishDate); Assert.AreEqual((int)OrderStatusType.Requested, orderHeader.OrderStatus); // Step 2 : Create order line items var orderLine = orderLogic.AddOrderLine(orderHeader, TestData.GTIN_UNDER_TEST, null, 100, Uom.GetUomById(1), 1); // Assert line item was created with most recent lot # Assert.AreEqual(orderHeader.OrderNum, orderLine.OrderNum); Assert.AreEqual(TestData.GTIN_UNDER_TEST, orderLine.OrderGtin); Assert.AreEqual(TestData.GTIN_LOT_USE_FIRST, orderLine.OrderGtinLotnum); Assert.AreEqual((int)OrderStatusType.Requested, orderLine.OrderDetailStatus); // Step 3 : Release the order orderHeader = orderLogic.ReleaseOrder(orderHeader, 1); // Assert header is updated Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id); Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id); Assert.AreEqual((int)OrderStatusType.Released, orderHeader.OrderStatus); // Assert lines are updated orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0]; Assert.AreEqual((int)OrderStatusType.Released, orderHeader.OrderStatus); // Assert that there was a stock transaction for allocation var txAllocate = TransactionType.GetTransactionTypeList().First(o => o.Name == "Allocation"); Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" && o.Gtin == TestData.GTIN_UNDER_TEST && o.GtinLot == TestData.GTIN_LOT_USE_FIRST && o.TransactionTypeId == txAllocate.Id && o.RefId == orderHeader.OrderNum.ToString() && o.RefIdNum == orderLine.OrderDetailNum && o.TransactionQtyInBaseUom == 100), "No allocation could be found"); // Step 4: Pack the order orderHeader = orderLogic.PackOrder(orderHeader, 1); Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id); Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id); Assert.AreEqual((int)OrderStatusType.Packed, orderHeader.OrderStatus); // Assert lines are updated orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0]; Assert.AreEqual((int)OrderStatusType.Packed, orderHeader.OrderStatus); // Step 5: Ship the order orderHeader = orderLogic.ShipOrder(orderHeader, 1); Assert.AreEqual(from.Id, orderHeader.OrderFacilityFromObject.Id); Assert.AreEqual(to.Id, orderHeader.OrderFacilityToObject.Id); Assert.AreEqual((int)OrderStatusType.Shipped, orderHeader.OrderStatus); // Assert lines are updated orderLine = TransferOrderDetail.GetTransferOrderDetailByOrderNum(orderHeader.OrderNum)[0]; Assert.AreEqual((int)OrderStatusType.Shipped, orderHeader.OrderStatus); // Assert allocations are made var txTrasnfer = TransactionType.GetTransactionTypeList().First(o => o.Name == "Transfer"); Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" && o.Gtin == TestData.GTIN_UNDER_TEST && o.GtinLot == TestData.GTIN_LOT_USE_FIRST && o.TransactionTypeId == txAllocate.Id && o.RefId == orderHeader.OrderNum.ToString() && o.RefIdNum == orderLine.OrderDetailNum && o.TransactionQtyInBaseUom == -100), "No de-allocation could be found"); Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF888" && o.Gtin == TestData.GTIN_UNDER_TEST && o.GtinLot == TestData.GTIN_LOT_USE_FIRST && o.TransactionTypeId == txTrasnfer.Id && o.RefId == orderHeader.OrderNum.ToString() && o.RefIdNum == orderLine.OrderDetailNum && o.TransactionQtyInBaseUom == -100), "No transfer out could be found"); Assert.IsTrue(ItemTransaction.GetItemTransactionList().Exists(o => o.HealthFacilityCode == "HF999" && o.Gtin == TestData.GTIN_UNDER_TEST && o.GtinLot == TestData.GTIN_LOT_USE_FIRST && o.TransactionTypeId == txTrasnfer.Id && o.RefId == orderHeader.OrderNum.ToString() && o.RefIdNum == orderLine.OrderDetailNum && o.TransactionQtyInBaseUom == 100), "No transfer in could be found"); } catch (Exception e) { Assert.Fail(e.ToString()); } }
/// <summary> /// Initialize the test data /// </summary> public static void InitializeTestDataset() { /// Transaction type 999 = ID var transactionTypes = TransactionType.GetTransactionTypeList(); if (!transactionTypes.Exists(o => o.Name == "Allocation")) { TransactionType.Insert(new TransactionType() { Name = "Allocation" }); } if (!transactionTypes.Exists(o => o.Name == "Transfer")) { TransactionType.Insert(new TransactionType() { Name = "Transfer" }); } // GTIN 12345 - PHARMACO OPV if (ItemManufacturer.GetItemManufacturerByGtin(GTIN_UNDER_TEST) == null) { // Item Category 999 = Vaccine if (ItemCategory.GetItemCategoryById(VACCINE_CATEGORY_ID) == null) { VACCINE_CATEGORY_ID = ItemCategory.Insert(new ItemCategory() { Id = VACCINE_CATEGORY_ID, Code = "VACCINE", IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "Vaccine" }); } // Item 999 - OPV if (Item.GetItemById(OPV_ITEM_ID) == null) { OPV_ITEM_ID = Item.Insert(new Item() { Code = "OPV", EntryDate = DateTime.Now, Id = OPV_ITEM_ID, ItemCategoryId = VACCINE_CATEGORY_ID, IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "OPV" }); } // Unit of Measure if (Uom.GetUomById(DOSE_UOM_ID) == null) { DOSE_UOM_ID = Uom.Insert(new Uom() { Id = DOSE_UOM_ID, Name = "DOSE" }); } // Manufacturer 999 - PHARMACO if (Manufacturer.GetManufacturerById(PHARMACO_MANUFACTURER_ID) == null) { PHARMACO_MANUFACTURER_ID = Manufacturer.Insert(new Manufacturer() { Id = PHARMACO_MANUFACTURER_ID, Code = "PHX", IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "PHARMACO INC." }); } ItemManufacturer.Insert(new ItemManufacturer() { Alt1QtyPer = 20, BaseUom = "DOSE", BaseUomChildPerBaseUomParent = 10, Gtin = GTIN_UNDER_TEST, IsActive = true, ItemId = OPV_ITEM_ID, ManufacturerId = PHARMACO_MANUFACTURER_ID, ModifiedBy = 1, ModifiedOn = DateTime.Now, Price = 9.99, StorageSpace = 1, Alt1Uom = "DOSE", Alt2QtyPer = 30, Alt2Uom = "DOSE" }); } if (ItemLot.GetItemLotByGtin(GTIN_UNDER_TEST) == null) { // Item 999 - OPV if (Item.GetItemById(OPV_ITEM_ID) == null) { OPV_ITEM_ID = Item.Insert(new Item() { Code = "OPV", EntryDate = DateTime.Now, Id = OPV_ITEM_ID, ItemCategoryId = VACCINE_CATEGORY_ID, IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "OPV" }); } ItemLot.Insert(new ItemLot() { ExpireDate = DateTime.Now.AddDays(10), Gtin = GTIN_UNDER_TEST, ItemId = OPV_ITEM_ID, LotNumber = GTIN_LOT_USE_FIRST }); // Item Lot 2 - Will be more stock and expires later ItemLot.Insert(new ItemLot() { ExpireDate = DateTime.Now.AddDays(40), Gtin = GTIN_UNDER_TEST, ItemId = OPV_ITEM_ID, LotNumber = GTIN_LOT_USE_LAST }); // Item Lot 3 - Will trigger low stock ItemLot.Insert(new ItemLot() { ExpireDate = DateTime.Now.AddDays(80), Gtin = GTIN_UNDER_TEST, ItemId = OPV_ITEM_ID, LotNumber = GTIN_LOT_LOW_BAL }); } // Type 3 = DISTRICT if (HealthFacilityType.GetHealthFacilityTypeById(6) == null) { HealthFacilityType.Insert(new HealthFacilityType() { Id = 3, Code = "DISTRICT", IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "DISTRICT LEVEL" }); } // Type 6 = SDP if (HealthFacilityType.GetHealthFacilityTypeById(6) == null) { HealthFacilityType.Insert(new HealthFacilityType() { Id = 6, Code = "SDP", IsActive = true, ModifiedBy = 1, ModifiedOn = DateTime.Now, Name = "SDP" }); } // HF888 = DISTRICT if (HealthFacility.GetHealthFacilityByCode("HF888") == null) { HealthFacility.Insert(new HealthFacility() { Id = 888, Code = "HF888", ColdStorageCapacity = 1000, IsActive = true, Leaf = false, ParentId = HealthFacility.GetHealthFacilityByParentId(0)[0].Id, TopLevel = false, TypeId = 3, VaccinationPoint = false, VaccineStore = true, ModifiedBy = 1, ModifiedOn = DateTime.Now }); } // GIVE HEALTH FACILITY SOME BALANCE var hf888Balances = HealthFacilityBalance.GetHealthFacilityBalanceByHealthFacilityCode("HF888"); HealthFacilityBalance useFirst = hf888Balances.Find(o => o.Gtin == GTIN_UNDER_TEST && o.LotNumber == GTIN_LOT_USE_FIRST), useLast = hf888Balances.Find(o => o.Gtin == GTIN_UNDER_TEST && o.LotNumber == GTIN_LOT_USE_LAST), lowStock = hf888Balances.Find(o => o.Gtin == GTIN_UNDER_TEST && o.LotNumber == GTIN_LOT_LOW_BAL); if (useFirst == null) { useFirst = new HealthFacilityBalance() { Allocated = 0, Balance = 500, Distributed = 0, Gtin = GTIN_UNDER_TEST, HealthFacilityCode = "HF888", LotNumber = GTIN_LOT_USE_FIRST, Received = 0, StockCount = 500, Used = 0, Wasted = 0 }; hf888Balances.Add(useFirst); HealthFacilityBalance.Insert(useFirst); } else { useFirst.Balance = 500; useFirst.StockCount = 500; HealthFacilityBalance.Update(useFirst); } if (useLast == null) { useLast = new HealthFacilityBalance() { Allocated = 0, Balance = 1000, Distributed = 0, Gtin = GTIN_UNDER_TEST, HealthFacilityCode = "HF888", LotNumber = GTIN_LOT_USE_LAST, Received = 0, StockCount = 1000, Used = 0, Wasted = 0 }; hf888Balances.Add(useLast); HealthFacilityBalance.Insert(useLast); } else { useLast.Balance = 1000; useLast.StockCount = 1000; HealthFacilityBalance.Update(useLast); } if (lowStock == null) { lowStock = new HealthFacilityBalance() { Allocated = 0, Balance = 10, Distributed = 0, Gtin = GTIN_UNDER_TEST, HealthFacilityCode = "HF888", LotNumber = GTIN_LOT_LOW_BAL, Received = 0, StockCount = 10, Used = 0, Wasted = 0 }; hf888Balances.Add(lowStock); HealthFacilityBalance.Insert(lowStock); } else { useLast.Balance = 10; useLast.StockCount = 10; HealthFacilityBalance.Update(lowStock); } // HF999 = SDP if (HealthFacility.GetHealthFacilityByCode("HF999") == null) { HealthFacility.Insert(new HealthFacility() { Id = 999, Code = "HF999", ColdStorageCapacity = 100, IsActive = true, Leaf = true, ParentId = HealthFacility.GetHealthFacilityByCode("HF888").Id, TopLevel = false, TypeId = 6, VaccinationPoint = true, VaccineStore = true, ModifiedOn = DateTime.Now, ModifiedBy = 1 }); } }
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { List <string> actionList = null; string sessionNameAction = ""; if (CurrentEnvironment.LoggedUser != null) { sessionNameAction = "__GIS_actionList_" + CurrentEnvironment.LoggedUser.Id; actionList = (List <string>)Session[sessionNameAction]; } if ((actionList != null) && actionList.Contains("ViewUom") && (CurrentEnvironment.LoggedUser != null)) { int userId = CurrentEnvironment.LoggedUser.Id; string language = CurrentEnvironment.Language; int languageId = int.Parse(language); Dictionary <string, string> wtList = (Dictionary <string, string>)HttpContext.Current.Cache["Uom-dictionary" + language]; if (wtList == null) { List <WordTranslate> wordTranslateList = WordTranslate.GetWordByLanguage(languageId, "Uom"); wtList = new Dictionary <string, string>(); foreach (WordTranslate vwt in wordTranslateList) { wtList.Add(vwt.Code, vwt.Name); } HttpContext.Current.Cache.Insert("Uom-dictionary" + language, wtList); } //controls this.lblName.Text = wtList["UomName"]; this.lblNotes.Text = wtList["UomNotes"]; //grid header text gvUom.Columns[1].HeaderText = wtList["UomName"]; gvUom.Columns[2].HeaderText = wtList["UomNotes"]; //actions this.btnAdd.Visible = actionList.Contains("AddUom"); this.btnEdit.Visible = actionList.Contains("EditUom"); this.btnRemove.Visible = actionList.Contains("RemoveUom"); //buttons this.btnAdd.Text = wtList["UomAddButton"]; this.btnEdit.Text = wtList["UomEditButton"]; this.btnRemove.Text = wtList["UomRemoveButton"]; //message this.lblSuccess.Text = wtList["UomSuccessText"]; this.lblWarning.Text = wtList["UomWarningText"]; this.lblError.Text = wtList["UomErrorText"]; //Page Title this.lblTitle.Text = wtList["UomPageTitle"]; //selected object int id = -1; string _id = Request.QueryString["id"]; if (!String.IsNullOrEmpty(_id)) { int.TryParse(_id, out id); Uom o = Uom.GetUomById(id); if (o != null) { txtName.Text = o.Name; txtNotes.Text = o.Notes; } btnAdd.Visible = false; } else { btnEdit.Visible = false; btnRemove.Visible = false; } gvUom.DataSource = Uom.GetUomList(); gvUom.DataBind(); } else { Response.Redirect("Default.aspx"); } } }