Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ehr/test/src/org/labkey/test/tests/ehr/AbstractEHRTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ protected String getExpectedAnimalIDCasing(String id)
return id.toLowerCase();
}

protected String[] getWeightFields()
{
return weightFields;
}

protected Object[] getWeightData1()
{
return weightData1;
}

@LogMethod
protected void createTestSubjects() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,23 @@ public void testWeightValidation()
"WARN: Weight above the allowable value of 20.0 kg for Cynomolgus",
"INFO: Weight gain of >10%. Last weight 12 kg")
);
getApiHelper().testValidationMessage(DATA_ADMIN.getEmail(), "study", "weight", weightFields, data, expected);
getApiHelper().testValidationMessage(DATA_ADMIN.getEmail(), "study", "weight", getWeightFields(), data, expected);

//expect INFO for +10% diff
data = new Object[][]{
{SUBJECTS[3], new Date(), null, null, 20, EHRQCState.IN_PROGRESS.label, null, null, "recordID"}
};
expected = new HashMap<>();
expected.put("weight", Collections.singletonList("INFO: Weight gain of >10%. Last weight 12 kg"));
getApiHelper().testValidationMessage(DATA_ADMIN.getEmail(), "study", "weight", weightFields, data, expected);
getApiHelper().testValidationMessage(DATA_ADMIN.getEmail(), "study", "weight", getWeightFields(), data, expected);

//expect INFO for -10% diff
data = new Object[][]{
{SUBJECTS[3], new Date(), null, null, 5, EHRQCState.IN_PROGRESS.label, null, null, "recordID"}
};
expected = new HashMap<>();
expected.put("weight", Collections.singletonList("INFO: Weight drop of >10%. Last weight 12 kg"));
getApiHelper().testValidationMessage(DATA_ADMIN.getEmail(), "study", "weight", weightFields, data, expected);
getApiHelper().testValidationMessage(DATA_ADMIN.getEmail(), "study", "weight", getWeightFields(), data, expected);

//TODO: test error threshold
}
Expand Down Expand Up @@ -245,10 +245,10 @@ private void testUserAgainstAllStates(@LoggedParam EHRUser user)
_saveRowsTimes = new ArrayList<>();

//test insert
Object[][] insertData = {weightData1};
insertData[0][Arrays.asList(weightFields).indexOf(FIELD_OBJECTID)] = null;
insertData[0][Arrays.asList(weightFields).indexOf(FIELD_LSID)] = null;
SimplePostCommand insertCommand = getApiHelper().prepareInsertCommand("study", "Weight", FIELD_LSID, weightFields, insertData);
Object[][] insertData = {getWeightData1()};
insertData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_OBJECTID)] = null;
insertData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_LSID)] = null;
SimplePostCommand insertCommand = getApiHelper().prepareInsertCommand("study", "Weight", FIELD_LSID, getWeightFields(), insertData);

for (EHRQCState qc : EHRQCState.values())
{
Expand All @@ -268,34 +268,34 @@ private void testUserAgainstAllStates(@LoggedParam EHRUser user)
{
// first create an initial row as a data admin
UUID objectId = UUID.randomUUID();
Object[][] originalData = {weightData1};
originalData[0][Arrays.asList(weightFields).indexOf(FIELD_QCSTATELABEL)] = originalQc.label;
Object[][] originalData = {getWeightData1()};
originalData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_QCSTATELABEL)] = originalQc.label;
extraContext.put("targetQC", originalQc.label);
originalData[0][Arrays.asList(weightFields).indexOf(FIELD_OBJECTID)] = objectId.toString();
SimplePostCommand initialInsertCommand = getApiHelper().prepareInsertCommand("study", "Weight", FIELD_LSID, weightFields, originalData);
originalData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_OBJECTID)] = objectId.toString();
SimplePostCommand initialInsertCommand = getApiHelper().prepareInsertCommand("study", "Weight", FIELD_LSID, getWeightFields(), originalData);
log("Inserting initial record for update test, with initial QCState of: " + originalQc.label);
response = getApiHelper().doSaveRows(DATA_ADMIN.getEmail(), initialInsertCommand, extraContext);

String lsid = getLsidFromResponse(response);
originalData[0][Arrays.asList(weightFields).indexOf(FIELD_LSID)] = lsid;
originalData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_LSID)] = lsid;

//then try to update to all other QCStates
for (EHRQCState qc : EHRQCState.values())
{
boolean successExpected = originalQc.equals(qc) ? successExpected(user.getRole(), originalQc, "update") : successExpected(user.getRole(), originalQc, "update") && successExpected(user.getRole(), qc, "insert");
log("Testing role: " + user.getRole().name() + " with update from QCState " + originalQc.label + " to: " + qc.label);
originalData[0][Arrays.asList(weightFields).indexOf(FIELD_QCSTATELABEL)] = qc.label;
SimplePostCommand updateCommand = getApiHelper().prepareUpdateCommand("study", "Weight", FIELD_LSID, weightFields, originalData, null);
originalData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_QCSTATELABEL)] = qc.label;
SimplePostCommand updateCommand = getApiHelper().prepareUpdateCommand("study", "Weight", FIELD_LSID, getWeightFields(), originalData, null);
extraContext.put("targetQC", qc.label);
if (!successExpected)
getApiHelper().doSaveRowsExpectingError(user.getEmail(), updateCommand, extraContext);
else
{
getApiHelper().doSaveRows(user.getEmail(), updateCommand, extraContext);
log("Resetting QCState of record to: " + originalQc.label);
originalData[0][Arrays.asList(weightFields).indexOf(FIELD_QCSTATELABEL)] = originalQc.label;
originalData[0][Arrays.asList(getWeightFields()).indexOf(FIELD_QCSTATELABEL)] = originalQc.label;
extraContext.put("targetQC", originalQc.label);
updateCommand = getApiHelper().prepareUpdateCommand("study", "Weight", FIELD_LSID, weightFields, originalData, null);
updateCommand = getApiHelper().prepareUpdateCommand("study", "Weight", FIELD_LSID, getWeightFields(), originalData, null);
getApiHelper().doSaveRows(DATA_ADMIN.getEmail(), updateCommand, extraContext);
}
}
Expand Down