diff --git a/ehr/test/src/org/labkey/test/tests/ehr/EHRSetupHelper.java b/ehr/test/src/org/labkey/test/tests/ehr/EHRSetupHelper.java index 69a9c40cd..4becf11dc 100644 --- a/ehr/test/src/org/labkey/test/tests/ehr/EHRSetupHelper.java +++ b/ehr/test/src/org/labkey/test/tests/ehr/EHRSetupHelper.java @@ -47,10 +47,8 @@ public void loadEHRTableDefinitions() _test.clickFolder(_folderName); else _test.clickFolder(_projectName); - if (_projectName.equalsIgnoreCase("CNPRC")) - _test.beginAt(_test.getCurrentContainerPath() + "/cnprc_ehr-ehrSettings.view?"); - else - _test.beginAt(_test.getCurrentContainerPath() + "/tnprc_ehr-ehrSettings.view?"); + + _test.beginAt(_test.getCurrentContainerPath() + "/tnprc_ehr-ehrSettings.view?"); _test.clickButton("Load EHR table definitions", 0); _test.waitForElement(Locator.tagWithClass("span", "x4-window-header-text").withText("Success")); _test.assertExt4MsgBox("EHR tables updated successfully.", "OK"); diff --git a/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_BillingTest.java b/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_BillingTest.java index ba0f4febc..0a3b0f710 100644 --- a/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_BillingTest.java +++ b/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_BillingTest.java @@ -24,10 +24,13 @@ import org.labkey.test.WebTestHelper; import org.labkey.test.categories.EHR; import org.labkey.test.categories.ONPRC; +import org.labkey.test.util.DataRegionTable; import org.labkey.test.util.Ext4Helper; import org.labkey.test.util.LogMethod; +import org.labkey.test.util.PortalHelper; import org.labkey.test.util.ext4cmp.Ext4FieldRef; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -35,9 +38,19 @@ @BaseWebDriverTest.ClassTimeout(minutes = 10) public class ONPRC_BillingTest extends AbstractONPRC_EHRTest { - protected String PROJECT_NAME = "ONPRC_Billing_TestProject"; + protected static String PROJECT_NAME = "ONPRC_Billing_TestProject"; + private static final String BILLING_FOLDER_PATH = "/" + PROJECT_NAME + "/" + BILLING_FOLDER; + private static final String EHR_FOLDER_PATH = "/" + PROJECT_NAME + "/" + FOLDER_NAME; private String ANIMAL_HISTORY_URL = "/ehr/" + getProjectName() + "/animalHistory.view?"; + @BeforeClass + @LogMethod + public static void setupProject() throws Exception + { + ONPRC_BillingTest initTest = (ONPRC_BillingTest)getCurrentTest(); + initTest.doSetUp(); + } + @Override protected String getProjectName() { @@ -50,12 +63,16 @@ protected String getModuleDirectory() return "onprc_ehr"; } - @BeforeClass - @LogMethod - public static void doSetup() throws Exception + private void doSetUp() throws Exception { - ONPRC_BillingTest initTest = (ONPRC_BillingTest)getCurrentTest(); - initTest.initProject(); + initProject(); + _containerHelper.createSubfolder(getProjectName(), getProjectName(), BILLING_FOLDER, "Collaboration", null); + clickFolder(BILLING_FOLDER); + _containerHelper.enableModules(Arrays.asList("ONPRC_EHR", "EHR_Billing", "ONPRC_Billing", "ONPRC_BillingPublic")); + + PortalHelper _portalHelper = new PortalHelper(getDriver()); + _portalHelper.addWebPart("ONPRC Finance"); + } @Test @@ -125,6 +142,46 @@ public void miscChargesFormTest() } + /* + Test coverage for https://www.labkey.org/ONPRC/Support%20Tickets/issues-details.view?issueId=41146 + */ + + @Test + public void testProtocolProjectCreation() + { + String protocolTitle = "Test Protocol"; + String projectName = "Test Project"; + navigateToFolder(PROJECT_NAME, BILLING_FOLDER); + + clickAndWait(Locator.linkWithText("IACUC Protocols")); + DataRegionTable protocolTable = new DataRegionTable("query", getDriver()); + protocolTable.clickHeaderMenu("More Actions", false, "Edit Records"); + protocolTable.clickImportBulkData(); + + setFormElement(Locator.textarea("title"), protocolTitle); + clickButton("Submit"); + + protocolTable.setFilter("title", "Equals", protocolTitle); + String protocolId = protocolTable.getDataAsText(0, "protocol"); + + checker().verifyEquals("Adding new protocol was not successful", 1, protocolTable.getDataRowCount()); + + navigateToFolder(PROJECT_NAME, BILLING_FOLDER); + clickAndWait(Locator.linkWithText("ONPRC Projects")); + + DataRegionTable projectTable = new DataRegionTable("query", getDriver()); + projectTable.clickHeaderMenu("More Actions", false, "Edit Records"); + projectTable.clickImportBulkData(); + + setFormElement(Locator.name("name"), projectName); + setFormElement(Locator.name("protocol"), protocolId); + clickButton("Submit"); + + projectTable.setFilter("name", "Equals", projectName); + checker().verifyEquals("Adding new project was not successful", 1, projectTable.getDataRowCount()); + } + + @Override public void validateQueries(boolean validateSubfolders) { diff --git a/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java b/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java index d67915e50..f72e7d4bc 100644 --- a/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java +++ b/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest.java @@ -47,7 +47,6 @@ import org.labkey.test.util.Maps; import org.labkey.test.util.PasswordUtil; import org.labkey.test.util.RReportHelper; -import org.labkey.test.util.SchemaHelper; import org.labkey.test.util.ehr.EHRClientAPIHelper; import org.labkey.test.util.ext4cmp.Ext4CmpRef; import org.labkey.test.util.ext4cmp.Ext4ComboRef; @@ -61,7 +60,6 @@ import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -74,6 +72,7 @@ import java.util.Set; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; @Category({CustomModules.class, EHR.class, ONPRC.class}) @BaseWebDriverTest.ClassTimeout(minutes = 60) @@ -464,7 +463,7 @@ public void testArrivalApi() throws Exception ), getExtraContext()); //expect to find demographics record. - Assert.assertTrue("demographics row was not created for arrival", getApiHelper().doesRowExist("study", "demographics", new Filter("Id", arrivalId1, Filter.Operator.EQUAL))); + assertTrue("demographics row was not created for arrival", getApiHelper().doesRowExist("study", "demographics", new Filter("Id", arrivalId1, Filter.Operator.EQUAL))); //and birth SelectRowsCommand birthSelect = new SelectRowsCommand("study", "birth"); @@ -669,7 +668,7 @@ public void testPedigreeReport() throws Exception waitForElement(Locator.tagContainingText("span", "Pedigree Plot - " + id), WAIT_FOR_JAVASCRIPT * 3); assertTextNotPresent("Error executing command"); - Assert.assertTrue(isTextPresent("Console output")); + assertTrue(isTextPresent("Console output")); } @Test @@ -1220,6 +1219,28 @@ public void testGeneticsPipeline() throws Exception waitAndClickAndWait(Ext4Helper.Locators.ext4Button("Run Now")); waitAndClickAndWait(Locator.lkButton("OK")); waitForPipelineJobsToComplete(2, "genetics pipeline", false); + + /* + Test coverage for : https://www.labkey.org/ONPRC/Support%20Tickets/issues-details.view?issueId=41231 + */ + + goToProjectHome(); + beginAtAnimalHistoryTab(); + AnimalHistoryPage animalHistoryPage = new AnimalHistoryPage(getDriver()); + animalHistoryPage.searchSingleAnimal("99991,99991011,99991041,99991080,99998"); + animalHistoryPage.refreshReport(); + animalHistoryPage.clickCategoryTab("Genetics") + .clickReportTab("Kinship"); + + assertTrue(isElementPresent(Locator.linkWithText("CLICK HERE TO LIMIT TO ANIMALS IN SELECTION"))); + + DataRegionTable kinshipTable = animalHistoryPage.getActiveReportDataRegion(); + assertEquals("Incorrect number of rows before limiting animal selection", 3, kinshipTable.getDataRowCount()); + + kinshipTable.doAndWaitForUpdate(() -> Locator.linkWithText("CLICK HERE TO LIMIT TO ANIMALS IN SELECTION").findElement(getDriver()).click()); + + kinshipTable = animalHistoryPage.getActiveReportDataRegion(); + assertEquals("Incorrect number of rows after limiting animal selection", 2, kinshipTable.getDataRowCount()); } @Test @@ -1373,7 +1394,7 @@ public void testPathology() final String caseNoBase = "2013A00"; waitFor(() -> Ext4FieldRef.getForLabel(ONPRC_EHRTest.this, "Case Number").getValue().toString().startsWith(caseNoBase), "Case Number field was not set", WAIT_FOR_JAVASCRIPT); - Assert.assertTrue(Ext4FieldRef.getForLabel(this, "Case Number").getValue().toString().startsWith(caseNoBase)); + assertTrue(Ext4FieldRef.getForLabel(this, "Case Number").getValue().toString().startsWith(caseNoBase)); String caseNo = Ext4FieldRef.getForLabel(this, "Case Number").getValue().toString(); // apply form template @@ -1427,14 +1448,14 @@ public void testPathology() visible.get(0).sendKeys(Keys.ENTER); String code2 = "APEX OF HEART (T-32040)"; waitForElement(Locator.tagContainingText("div", "2: " + code2),20000); - Assert.assertTrue(isTextBefore(code1, code2)); + assertTrue(isTextBefore(code1, code2)); visible.get(0).sendKeys("disease"); sleep(2000); visible.get(0).sendKeys(Keys.ENTER); String code3 = "ALEUTIAN DISEASE (D-03550)"; waitForElement(Locator.tagContainingText("div", "3: " + code3),20000); - Assert.assertTrue(isTextBefore(code2, code3)); + assertTrue(isTextBefore(code2, code3)); //move first code down click(Locator.id(_ext4Helper.componentQuery("button[testLocator=snomedDownArrow]", Ext4CmpRef.class).get(0).getId())); @@ -1459,7 +1480,7 @@ public void testPathology() waitAndClick(Ext4Helper.Locators.window("Manage SNOMED Codes").append(Ext4Helper.Locators.ext4Button("Submit"))); Assert.assertEquals("1<>D-03550;2<>E-70590", histologyGrid.getFieldValue(1, "codesRaw").toString()); - Assert.assertTrue(isTextBefore("1: " + code3, "2: " + code1)); + assertTrue(isTextBefore("1: " + code3, "2: " + code1)); //enter death waitAndClick(Ext4Helper.Locators.ext4ButtonEnabled("Enter/Manage Death")); @@ -1649,7 +1670,6 @@ public void testSurgeryForm() waitForElementToDisappear(caseWindow); waitForElement(Ext4Helper.Locators.window("Success").append(Locator.tagWithText("div", "Surgical cases opened"))); waitAndClick(Ext4Helper.Locators.window("Success").append(Ext4Helper.Locators.ext4ButtonEnabled("OK"))); - _helper.discardForm(); } @@ -1782,9 +1802,9 @@ public void testNecropsyRequestFlow() throws IOException, CommandException String tissue = "AMNION (T-88300)"; // Insert a row so we can select a charge unit in the form - InsertRowsCommand protocolCommand = new InsertRowsCommand("onprc_billing", "chargeUnits"); - protocolCommand.addRow(Maps.of("chargetype", "ChargeUnit1", "servicecenter", "ServiceCenter1", "shownInProcedures", true, "active", true)); - protocolCommand.execute(getApiHelper().getConnection(), getContainerPath()); + InsertRowsCommand chargeUnitCommand = new InsertRowsCommand("onprc_billing", "chargeUnits"); + chargeUnitCommand.addRow(Maps.of("chargetype", "ChargeUnit1", "servicecenter", "ServiceCenter1", "shownInProcedures", true, "active", true)); + chargeUnitCommand.execute(getApiHelper().getConnection(), getContainerPath()); log("Begin the test with entry data page"); EnterDataPage enterData = EnterDataPage.beginAt(this, getContainerPath()); diff --git a/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest2.java b/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest2.java index 850f880b3..0b7cb16d5 100644 --- a/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest2.java +++ b/ehr/test/src/org/labkey/test/tests/onprc_ehr/ONPRC_EHRTest2.java @@ -20,6 +20,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.experimental.categories.Category; +import org.labkey.remoteapi.CommandException; import org.labkey.remoteapi.PostCommand; import org.labkey.remoteapi.query.ExecuteSqlCommand; import org.labkey.remoteapi.query.Filter; @@ -27,22 +28,30 @@ import org.labkey.remoteapi.query.SaveRowsResponse; import org.labkey.remoteapi.query.SelectRowsCommand; import org.labkey.remoteapi.query.SelectRowsResponse; +import org.labkey.test.BaseWebDriverTest; import org.labkey.test.Locator; import org.labkey.test.TestProperties; import org.labkey.test.categories.CustomModules; import org.labkey.test.categories.EHR; import org.labkey.test.categories.ONPRC; import org.labkey.test.pages.ehr.AnimalHistoryPage; +import org.labkey.test.tests.di.ETLHelper; +import org.labkey.test.util.APIContainerHelper; +import org.labkey.test.util.AbstractContainerHelper; +import org.labkey.test.util.DataRegionTable; import org.labkey.test.util.Ext4Helper; import org.labkey.test.util.LogMethod; import org.labkey.test.util.Maps; import org.labkey.test.util.PasswordUtil; -import org.labkey.test.util.SchemaHelper; import org.labkey.test.util.ext4cmp.Ext4CmpRef; import org.labkey.test.util.ext4cmp.Ext4ComboRef; import org.labkey.test.util.ext4cmp.Ext4FieldRef; import org.labkey.test.util.ext4cmp.Ext4GridRef; +import org.openqa.selenium.support.ui.ExpectedConditions; +import java.io.IOException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; @@ -54,10 +63,24 @@ import java.util.regex.Pattern; @Category({CustomModules.class, EHR.class, ONPRC.class}) +@BaseWebDriverTest.ClassTimeout(minutes = 18) public class ONPRC_EHRTest2 extends AbstractONPRC_EHRTest { + public AbstractContainerHelper _containerHelper = new APIContainerHelper(this); private String PROJECT_NAME = "ONPRC_EHR_TestProject2"; + public ETLHelper _etlHelper = new ETLHelper(this, getProjectName()); private String ANIMAL_HISTORY_URL = "/ehr/" + getProjectName() + "/animalHistory.view?"; + + @BeforeClass + @LogMethod + public static void setupProject() throws Exception + { + ONPRC_EHRTest2 initTest = new ONPRC_EHRTest2(); + initTest.doCleanup(false); + + initTest.doSetUp(); + } + @Override protected String getModuleDirectory() { @@ -70,15 +93,13 @@ protected String getProjectName() return PROJECT_NAME; } - @BeforeClass - @LogMethod - public static void doSetup() throws Exception + private void doSetUp() throws Exception { - ONPRC_EHRTest2 initTest = new ONPRC_EHRTest2(); - initTest.doCleanup(false); + initProject(); + createTestSubjects(); - initTest.initProject(); - initTest.createTestSubjects(); + //treatmentToDrug ETL is part of this module. + _containerHelper.enableModule("TreatmentETL"); } @Override @@ -124,16 +145,17 @@ public void testBirthStatusApi() throws Exception //update to completed, expect to find demographics record. SelectRowsCommand select1 = new SelectRowsCommand("study", "birth"); select1.addFilter(new Filter("Id", damId1, Filter.Operator.EQUAL)); - final String damLsid = (String)select1.execute(getApiHelper().getConnection(), getContainerPath()).getRows().get(0).get("lsid"); + final String damLsid = (String) select1.execute(getApiHelper().getConnection(), getContainerPath()).getRows().get(0).get("lsid"); getApiHelper().updateRow("study", "birth", new HashMap() {{ - put("lsid", damLsid); - put("QCStateLabel", "Completed"); - }}, false); + put("lsid", damLsid); + put("QCStateLabel", "Completed"); + }}, false); org.junit.Assert.assertTrue("demographics row was not created for dam1", getApiHelper().doesRowExist("study", "demographics", new Filter("Id", damId1, Filter.Operator.EQUAL))); //update record to get a geographic_origin, which we expect to get entered into demographics - getApiHelper().updateRow("study", "birth", new HashMap(){ + getApiHelper().updateRow("study", "birth", new HashMap() + { { put("lsid", damLsid); put("geographic_origin", INDIAN); @@ -152,7 +174,8 @@ public void testBirthStatusApi() throws Exception String spfStatus = "SPF 9"; final String spfFlag = getOrCreateSpfFlag(spfStatus); InsertRowsCommand insertRowsCommand = new InsertRowsCommand("study", "flags"); - insertRowsCommand.addRow(new HashMap(){ + insertRowsCommand.addRow(new HashMap() + { { put("Id", damId1); put("date", dam1Birth); @@ -164,7 +187,8 @@ public void testBirthStatusApi() throws Exception String groupName = "TestGroup1"; final Integer groupId = getOrCreateGroup(groupName); InsertRowsCommand insertRowsCommand2 = new InsertRowsCommand("study", "animal_group_members"); - insertRowsCommand2.addRow(new HashMap(){ + insertRowsCommand2.addRow(new HashMap() + { { put("Id", damId1); put("date", dam1Birth); @@ -214,7 +238,7 @@ public void testBirthStatusApi() throws Exception final Map lsidMap = new HashMap<>(); for (Map row : insertRowsResp.getRows()) { - lsidMap.put((String)row.get("Id"), (String)row.get("lsid")); + lsidMap.put((String) row.get("Id"), (String) row.get("lsid")); } testBirthRecordStatus(offspringId1); @@ -320,14 +344,14 @@ private void testBirthRecordStatus(String offspringId, boolean birthWasChanged) org.junit.Assert.assertEquals("Birth record not created: " + offspringId, 1, resp.getRowCount().intValue()); - boolean isPublic = (Boolean)resp.getRows().get(0).get("QCState/PublicData"); - String damId = (String)resp.getRows().get(0).get("dam"); - boolean isAlive = resp.getRows().get(0).get("birth_condition/alive") == null ? true : (Boolean)resp.getRows().get(0).get("birth_condition/alive"); - String room = (String)resp.getRows().get(0).get("room"); - String cage = (String)resp.getRows().get(0).get("cage"); - Double weight = (Double)resp.getRows().get(0).get("weight"); - Date weightDate = (Date)resp.getRows().get(0).get("wdate"); - Date birthDate = (Date)resp.getRows().get(0).get("date"); + boolean isPublic = (Boolean) resp.getRows().get(0).get("QCState/PublicData"); + String damId = (String) resp.getRows().get(0).get("dam"); + boolean isAlive = resp.getRows().get(0).get("birth_condition/alive") == null ? true : (Boolean) resp.getRows().get(0).get("birth_condition/alive"); + String room = (String) resp.getRows().get(0).get("room"); + String cage = (String) resp.getRows().get(0).get("cage"); + Double weight = (Double) resp.getRows().get(0).get("weight"); + Date weightDate = (Date) resp.getRows().get(0).get("wdate"); + Date birthDate = (Date) resp.getRows().get(0).get("date"); SelectRowsCommand select2 = new SelectRowsCommand("study", "demographics"); select2.addFilter(new Filter("Id", offspringId, Filter.Operator.EQUAL)); @@ -449,7 +473,8 @@ public void testFlagsApi() throws Exception final Date date = new Date(); InsertRowsCommand insertRowsCommand = new InsertRowsCommand("study", "flags"); - insertRowsCommand.addRow(new HashMap(){ + insertRowsCommand.addRow(new HashMap() + { { put("Id", SUBJECTS[0]); put("date", prepareDate(date, -10, 0)); @@ -460,7 +485,8 @@ public void testFlagsApi() throws Exception //expect success InsertRowsCommand insertRowsCommand2 = new InsertRowsCommand("study", "flags"); - insertRowsCommand2.addRow(new HashMap(){ + insertRowsCommand2.addRow(new HashMap() + { { put("Id", SUBJECTS[0]); put("date", prepareDate(date, -9, 0)); @@ -482,7 +508,7 @@ public void testFlagsApi() throws Exception {SUBJECTS[0], prepareDate(date, -5, 0), flag1, generateGUID(), "recordID"} }, Maps.of( "flag", Arrays.asList( - "ERROR: Cannot change condition to a lower code. Animal is already: 202" + "ERROR: Cannot change condition to a lower code. Animal is already: 202" ) )); @@ -567,7 +593,7 @@ public void testArrivalForm() throws Exception waitAndClick(Ext4Helper.Locators.window("Set Values").append(Ext4Helper.Locators.ext4Button("Yes"))); waitForElementToDisappear(Ext4Helper.Locators.window("Bulk Edit")); - for (int i = 1;i<=3;i++) + for (int i = 1; i <= 3; i++) { Assert.assertEquals("bos", grid.getFieldValue(i, "source")); Assert.assertEquals("f", grid.getFieldValue(i, "gender")); @@ -973,22 +999,135 @@ public void bulkUploadsTest() //TODO: weight form, bulk upload } - //TODO: @Test - public void bloodRequestTest() + @Test + public void testTreatmentToDrugETL() { - // make request + LocalDateTime beginDate = LocalDateTime.now().withHour(0).withMinute(0); + LocalDateTime endDate = LocalDateTime.now().withHour(0).withMinute(0).plusDays(2); + String animalId = "12345"; + + log("Creating the Treatment order request"); + goToProjectHome(); + clickAndWait(Locator.linkWithText("Enter Data / Task Review")); + clickAndWait(Locator.linkWithText("Medications/Diet")); + + addTreatmentOrder(animalId, beginDate, endDate, "640991", "ACETAMINOPHEN (80mg) (E-77510)", + "BID - AM/Night", "PO", "tablet(s)", 10, "mg"); + + shortWait().until(ExpectedConditions.elementToBeClickable(Locator.tagWithText("span", "Submit Final"))); + clickButton("Submit Final", 0); + _billingHelper.checkMessageWindow("Finalize Form", "You are about to finalize this form. Do you want to do this?", "Yes"); + waitForElement(Locator.linkWithText("Medications/Diet")); + + log("Verifying request was created"); + goToSchemaBrowser(); + DataRegionTable table = viewQueryData("study", "treatment_order"); + table.setFilter("Id", "Equals", animalId); + checker().verifyEquals("Treatment order is not placed", 1, table.getDataRowCount()); + + log("Running the treatment to drug ETL"); + goToModule("DataIntegration"); + _etlHelper.runETL("{ONPRC_EHR}/TreatmentToDrug"); + + log("Verifying the drug table was populated"); + goToSchemaBrowser(); + table = viewQueryData("study", "drug"); + table.setFilter("Id", "Equals", animalId); + checker().verifyEquals("ETL did not populate the study.drug", 2, table.getDataRowCount()); + } + + @Test + public void bloodRequestTest() throws IOException, CommandException + { + LocalDateTime now = LocalDateTime.now(); + String animalId = "12345"; + + log("Inserting the charge unit necessary for blood draw request"); + InsertRowsCommand chargeUnitCommand = new InsertRowsCommand("onprc_billing", "chargeUnits"); + chargeUnitCommand.addRow(Map.of("chargetype", "ChargeUnit2", "servicecenter", "ServiceCenter2", "shownInBlood", true, "active", true)); + chargeUnitCommand.execute(getApiHelper().getConnection(), getContainerPath()); + + log("Inserting the data in available blood volume"); + goToSchemaBrowser(); + DataRegionTable ABVTable = viewQueryData("onprc_ehr", "AvailableBloodVolume"); + ABVTable.clickInsertNewRow(); + setFormElement(Locator.name("quf_datecreated"), now.toString()); + setFormElement(Locator.name("quf_id"), animalId); + setFormElement(Locator.name("quf_ABV"), "10"); + setFormElement(Locator.name("quf_dsrowid"), "1"); + clickButton("Submit"); + + + log("Creating the blood draw request"); + goToProjectHome(); + clickAndWait(Locator.linkWithText("Manage Requests")); + waitAndClickAndWait(Locator.linkWithText("ASB SERVICES REQUEST")); + addBloodDrawRequest(animalId, now, "795644", "ChargeUnit2", "Heparin", 12); + + checker().withScreenshot("Blood request").verifyTrue("Expected error is not present", isAnyTextPresent( + "Row 1, # of Tubes: ERROR: The quantity requested, 12.0ml exceeds the available blood volume, 8.0ml for AnimalId: 12345")); + + //Updating the total volume below the the available blood volume. + updateTotalVolume(8); + + shortWait().until(ExpectedConditions.elementToBeClickable(Locator.tagWithText("span", "Request"))).click(); + clickButton("Request","My Pending Requests"); - // check queue + DataRegionTable table = new DataRegionTable("study|blood", getDriver()); + checker().verifyEquals("New blood draw request is not created", 1, table.getDataRowCount()); - // create task, save + } - // open, delete record. + private void addBloodDrawRequest(String animalId, LocalDateTime date, String project, String charge_type, String tube_type, Integer quantity) + { + Ext4GridRef bloodDraw = _helper.getExt4GridForFormSection("Blood Draws"); + _helper.addRecordToGrid(bloodDraw); + scrollIntoView(Locator.tagWithText("span", "Blood Draws")); + int index = bloodDraw.getRowCount(); + + bloodDraw.setGridCellJS(index, "date", date.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT_STRING))); + bloodDraw.setGridCell(index, "Id", animalId); + + bloodDraw.setGridCell(index, "quantity", quantity.toString()); + bloodDraw.setGridCell(index, "chargetype", charge_type); + bloodDraw.setGridCell(index, "tube_type", tube_type); + addProjectToTheRow(bloodDraw, index, project); + } - // save. make sure deleted record back in queue + private void addTreatmentOrder(String animalId, LocalDateTime beginDate, LocalDateTime endDate, String project, String treatment, String frequency, String route, + String volUnits, Integer amount, String amountUnits) + { + Ext4GridRef treatmentOrder = _helper.getExt4GridForFormSection("Medication/Treatment Orders"); + _helper.addRecordToGrid(treatmentOrder); + scrollIntoView(Locator.tagWithText("span", "Medication/Treatment Orders")); + int index = treatmentOrder.getRowCount(); + + treatmentOrder.setGridCell(index, "Id", animalId); + treatmentOrder.setGridCellJS(index, "date", beginDate.toString()); + treatmentOrder.setGridCellJS(index, "enddate", endDate.toString()); + addProjectToTheRow(treatmentOrder, index, project); + treatmentOrder.setGridCell(index, "code", treatment); + treatmentOrder.setGridCell(index, "frequency", frequency); + treatmentOrder.setGridCell(index, "route", route); + treatmentOrder.setGridCell(index, "vol_units", volUnits); + treatmentOrder.setGridCell(index, "amount", amount.toString()); + treatmentOrder.setGridCell(index, "amount_units", amountUnits); + } - // use copy previous request + private void updateTotalVolume(Integer quantity) + { + Ext4GridRef bloodDraw = _helper.getExt4GridForFormSection("Blood Draws"); + int index = bloodDraw.getRowCount(); + bloodDraw.setGridCell(index, "quantity", quantity.toString()); + } - // test repeat selected helper, including save + private void addProjectToTheRow(Ext4GridRef gridRef, int index, String project) + { + gridRef.clickDownArrowOnGrid(index, "project"); + waitAndClick(Locator.tag("li").append(Locator.tagContainingText("span", "Other"))); + waitForElement(Ext4Helper.Locators.window("Choose Project")); + _ext4Helper.queryOne("window[title=Choose Project] [fieldLabel='Project']", Ext4ComboRef.class).setComboByDisplayValue(project); + waitAndClick(Ext4Helper.Locators.window("Choose Project").append(Ext4Helper.Locators.ext4ButtonEnabled("Submit"))); } //TODO: @Test