Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAH-700 | Lab Results page sorting issue #19

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions openelis/src/MessageResources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ dataimport.title = Data Import
date.format.formatKey = dd/MM/yyyy
dateTime.format.formatKey = dd/MM/yyyy HH:mm
dateTimeWithSec.format.formatKey = dd/MM/yyyy HH:mm:ss
dateTimeWithMilliSec.format.formatKey = dd/MM/yyyy HH\:mm\:ss.SSS
time.format.formatKey = HH:mm
timeWithMilliSec.format.formatKey = HH:mm:ss.SSS
#-- LIMS common --
date.format.validate = dd/MM/yyyy

Expand Down
2 changes: 2 additions & 0 deletions openelis/src/MessageResources_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ dataimport.title = Data Import(es)
date.format.formatKey = dd/MM/yyyy
dateTime.format.formatKey = dd/MM/yyyy HH:mm
dateTimeWithSec.format.formatKey = dd/MM/yyyy HH:mm:ss
dateTimeWithMilliSec.format.formatKey = dd/MM/yyyy HH\:mm\:ss.SSS
time.format.formatKey = HH:mm
timeWithMilliSec.format.formatKey = HH:mm:ss.SSS
#-- LIMS common --
date.format.validate = dd/MM/yyyy

Expand Down
3,998 changes: 2,000 additions & 1,998 deletions openelis/src/MessageResources_fr.properties

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions openelis/src/MessageResources_pt.properties
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ dataimport.title = Importar Dados
date.format.formatKey = dd/MM/yyyy
dateTime.format.formatKey = dd/MM/yyyy HH\:mm
dateTimeWithSec.format.formatKey = dd/MM/yyyy HH\:mm\:ss
dateTimeWithMilliSec.format.formatKey = dd/MM/yyyy HH\:mm\:ss.SSS
time.format.formatKey = HH\:mm
timeWithMilliSec.format.formatKey = HH:mm:ss.SSS
#-- LIMS common --
date.format.validate = dd/MM/yyyy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class TestUpdateWithAccessionNumberProvider extends BaseQueryProvider {
private SampleDAO sampleDao = new SampleDAOImpl();
Expand All @@ -46,6 +52,7 @@ public void processRequest(HttpServletRequest request, HttpServletResponse respo
Sample sample = sampleDao.getSampleByID(sampleId);
sampleDao.updateData(sample);
sample.setAccessionNumber(accessionNumber);
sample.setCollectionDate(DateUtil.getNowAsTimestamp());
String sysUserId = sample.getSysUserId();

Set includedSampleStatusList = new HashSet<Integer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package us.mn.state.health.lims.common.util;

import org.apache.commons.validator.GenericValidator;
import org.joda.time.DateTime;
import us.mn.state.health.lims.common.exception.LIMSRuntimeException;
import us.mn.state.health.lims.common.log.LogEvent;
import us.mn.state.health.lims.common.util.ConfigurationProperties.Property;
Expand Down Expand Up @@ -624,6 +623,11 @@ public static Timestamp getNowAsTimestamp() {
return new Timestamp(new Date().getTime());
}

public static String getCurrentTimeAsString(){
return new SimpleDateFormat(StringUtil.getMessageForKey("timeWithMilliSec.format.formatKey"))
.format(DateUtil.getNowAsTimestamp());
}

public static String convertTimestampToStringDateAndTime(Timestamp lastTimestamp) {
return new SimpleDateFormat( StringUtil.getMessageForKey("timestamp.format.formatKey")).format(lastTimestamp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
package us.mn.state.health.lims.result.action.util;

import java.sql.Timestamp;

public interface ResultItem{


public String getAccessionNumber();

Expand All @@ -44,4 +45,7 @@ public interface ResultItem{
public String getTestSortOrder();

public String getTestName();

public Timestamp getCollectionDate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@
import us.mn.state.health.lims.sample.valueholder.Sample;
import us.mn.state.health.lims.samplehuman.dao.SampleHumanDAO;
import us.mn.state.health.lims.samplehuman.daoimpl.SampleHumanDAOImpl;
import us.mn.state.health.lims.sampleitem.dao.SampleItemDAO;
import us.mn.state.health.lims.sampleitem.valueholder.SampleItem;
import us.mn.state.health.lims.siteinformation.daoimpl.SiteInformationDAOImpl;
import us.mn.state.health.lims.statusofsample.util.StatusOfSampleUtil;
import us.mn.state.health.lims.statusofsample.util.StatusOfSampleUtil.AnalysisStatus;
import us.mn.state.health.lims.statusofsample.util.StatusOfSampleUtil.OrderStatus;
Expand All @@ -96,7 +94,7 @@
import java.sql.Timestamp;
import java.util.*;

import static us.mn.state.health.lims.common.util.DateUtil.getCurrentDateAsText;
import us.mn.state.health.lims.common.util.DateUtil;

public class ResultsLoadUtility {

Expand Down Expand Up @@ -264,11 +262,7 @@ public List<TestResultItem> getGroupedTestsForAnalysisList(List<Analysis> filter
}
}

if (forwardSort) {
sortByAccessionAndSequence(selectedTestList);
} else {
reverseSortByAccessionAndSequence(selectedTestList);
}
new SortByAccessionNumberAndSequence().sort(selectedTestList, forwardSort);

setSampleGroupingNumbers(selectedTestList);
addUserSelectionReflexes(selectedTestList);
Expand Down Expand Up @@ -316,11 +310,7 @@ public List<TestResultItem> getGroupedTestsForAnalysis(List<PatientAnalysis> fil
}
}

if (forwardSort) {
sortByAccessionAndSequence(selectedTestList);
} else {
reverseSortByAccessionAndSequence(selectedTestList);
}
new SortBySampleCollectionDateAndAccessionNumber().sort(selectedTestList, forwardSort);

setSampleGroupingNumbers(selectedTestList);
addUserSelectionReflexes(selectedTestList);
Expand Down Expand Up @@ -354,52 +344,6 @@ private String getDisplayNameForCurrentPatient(String firstName ,String lastName
return nameBuilder.toString();
}

private void reverseSortByAccessionAndSequence(List<? extends ResultItem> selectedTest) {
Collections.sort(selectedTest, new Comparator<ResultItem>() {
public int compare(ResultItem a, ResultItem b) {
int accessionSort = b.getSequenceAccessionNumber().compareTo(a.getSequenceAccessionNumber());

if (accessionSort == 0) { //only the accession number sorting is reversed
if (!GenericValidator.isBlankOrNull(a.getTestSortOrder()) && !GenericValidator.isBlankOrNull(b.getTestSortOrder())) {
try {
return Integer.parseInt(a.getTestSortOrder()) - Integer.parseInt(b.getTestSortOrder());
} catch (NumberFormatException e) {
return a.getTestName().compareTo(b.getTestName());
}

} else {
return a.getTestName().compareTo(b.getTestName());
}
}

return accessionSort;
}
});
}

public void sortByAccessionAndSequence(List<? extends ResultItem> selectedTest) {
Collections.sort(selectedTest, new Comparator<ResultItem>() {
public int compare(ResultItem a, ResultItem b) {
int accessionSort = a.getSequenceAccessionNumber().compareTo(b.getSequenceAccessionNumber());

if (accessionSort == 0) {
if (!GenericValidator.isBlankOrNull(a.getTestSortOrder()) && !GenericValidator.isBlankOrNull(b.getTestSortOrder())) {
try {
return Integer.parseInt(a.getTestSortOrder()) - Integer.parseInt(b.getTestSortOrder());
} catch (NumberFormatException e) {
return a.getTestName().compareTo(b.getTestName());
}

} else if (!GenericValidator.isBlankOrNull(a.getTestName()) && !GenericValidator.isBlankOrNull(b.getTestName())) {
return a.getTestName().compareTo(b.getTestName());
}
}

return accessionSort;
}
});
}

public void setSampleGroupingNumbers(List<? extends ResultItem> selectedTests) {
int groupingNumber = 1; // the header is always going to be 0

Expand Down Expand Up @@ -560,8 +504,7 @@ private Patient getPatientForSampleItem(SampleItem sampleItem) {
private List<TestResultItem> getGroupedTestsForSamples() {

List<TestResultItem> testList = new ArrayList<>();

TestResultItem[] tests = getSortedTestsFromSamples();
TestResultItem[] tests = getSortedTestsFromSamples(!SORT_FORWARD);

String currentAccessionNumber = "";

Expand Down Expand Up @@ -595,7 +538,7 @@ private Sample getSampleFromAnalysis(Analysis analysis) {
return null;
}

private TestResultItem[] getSortedTestsFromSamples() {
private TestResultItem[] getSortedTestsFromSamples(boolean forwardSort) {

List<TestResultItem> testList = new ArrayList<>();
List<Analysis> analysisList = new ArrayList<>();
Expand All @@ -611,8 +554,7 @@ private TestResultItem[] getSortedTestsFromSamples() {
testList.add(selectedItem);
}
}

reverseSortByAccessionAndSequence(testList);
new SortBySampleCollectionDateAndAccessionNumber().sort(testList, forwardSort);
setSampleGroupingNumbers(testList);
addUserSelectionReflexes(testList);

Expand Down Expand Up @@ -791,7 +733,8 @@ private TestResultItem createTestResultItem(ResultLimit resultLimit, Analysis an
String techSignatureId, String supervisorSignatureId, boolean multiSelectionResult,
String initialSampleConditions, String sampleType, String patientIdentity) {

String receivedDate = currSample == null ? getCurrentDateAsText() : currSample.getReceivedDateForDisplay();
String receivedDate = currSample == null ? DateUtil.getCurrentDateAsText() : currSample.getReceivedDateForDisplay();
Timestamp collectionDate = currSample == null ? DateUtil.getNowAsTimestamp() : currSample.getCollectionDate();
String testMethodName = test.getMethod() != null ? test.getMethod().getMethodName() : null;
List<TestResult> testResults = getPossibleResultsForTest(test);

Expand Down Expand Up @@ -856,7 +799,7 @@ private TestResultItem createTestResultItem(ResultLimit resultLimit, Analysis an
}
}

String testDate = GenericValidator.isBlankOrNull(analysis.getCompletedDateForDisplay()) ? getCurrentDateAsText()
String testDate = GenericValidator.isBlankOrNull(analysis.getCompletedDateForDisplay()) ? DateUtil.getCurrentDateAsText()
: analysis.getCompletedDateForDisplay();

TestResultItem testItem = new TestResultItem();
Expand All @@ -865,6 +808,7 @@ private TestResultItem createTestResultItem(ResultLimit resultLimit, Analysis an
testItem.setAnalysisId(analysis.getId());
testItem.setSequenceNumber(sequenceNumber);
testItem.setReceivedDate(receivedDate);
testItem.setCollectionDate(collectionDate);
testItem.setTestName(displayTestName);
testItem.setTestId(test.getId());
testItem.setResultLimitId(resultLimit.getId());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package us.mn.state.health.lims.result.action.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortByAccessionNumberAndSequence extends SortBySequenceAndSortOrder {

private static final int SAME_ACCESSION_NUMBER = 0;

public void sort(List<? extends ResultItem> selectedTests, boolean forwardSort) {
final boolean isForwardSort = forwardSort;
Collections.sort(selectedTests, new Comparator<ResultItem>() {
public int compare(ResultItem firstResult, ResultItem secondResult) {
int accessionSort = isForwardSort == true ? firstResult.getSequenceAccessionNumber().compareTo(secondResult.getSequenceAccessionNumber()) :
secondResult.getSequenceAccessionNumber().compareTo(firstResult.getSequenceAccessionNumber());
if (accessionSort != SAME_ACCESSION_NUMBER) {
return accessionSort;
}
return sortByTestOrderOrName(accessionSort, firstResult, secondResult);
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package us.mn.state.health.lims.result.action.util;

import java.util.List;
import java.util.Comparator;
import java.util.Collections;

public class SortBySampleCollectionDateAndAccessionNumber extends SortBySequenceAndSortOrder {

private static final int SAME_COLLECTION_DATETIME = 0;

public void sort(List<? extends ResultItem> selectedTests, boolean forwardSort) {
final boolean isForwardSort = forwardSort;
Collections.sort(selectedTests, new Comparator<ResultItem>() {
public int compare(ResultItem firstResult, ResultItem secondResult) {
int collectionDateSort = isForwardSort == true ? firstResult.getCollectionDate()
.compareTo(secondResult.getCollectionDate()) :
secondResult.getCollectionDate().compareTo(firstResult.getCollectionDate());
if (collectionDateSort != SAME_COLLECTION_DATETIME) {
return collectionDateSort;
}
return sortBySequence(firstResult, secondResult);
}
}
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package us.mn.state.health.lims.result.action.util;

import org.apache.commons.validator.GenericValidator;

public abstract class SortBySequenceAndSortOrder implements SortStrategy {

private static final int SAME_SEQUENCE_NUMBER = 0;

protected int sortBySequence(ResultItem firstResult, ResultItem secondResult) {
int sequenceNumberSort = Integer.parseInt(firstResult.getSequenceNumber()) -
Integer.parseInt(secondResult.getSequenceNumber());
if (sequenceNumberSort != SAME_SEQUENCE_NUMBER) {
return sequenceNumberSort;
}
return sortByTestOrderOrName(sequenceNumberSort, firstResult, secondResult);
}

protected int sortByTestOrderOrName(int sequenceNumberSort, ResultItem firstResult, ResultItem secondResult) {
if (!GenericValidator.isBlankOrNull(firstResult.getTestSortOrder()) && !GenericValidator.isBlankOrNull(secondResult.getTestSortOrder())) {
try {
return Integer.parseInt(firstResult.getTestSortOrder()) - Integer.parseInt(secondResult.getTestSortOrder());
} catch (NumberFormatException e) {
return firstResult.getTestName().compareTo(secondResult.getTestName());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling logic in the catch block is a code smell. Please handle main logic part in the try block

}
} else if (!GenericValidator.isBlankOrNull(firstResult.getTestName()) && !GenericValidator.isBlankOrNull(secondResult.getTestName())) {
return firstResult.getTestName().compareTo(secondResult.getTestName());
}
return sequenceNumberSort;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package us.mn.state.health.lims.result.action.util;

import java.util.List;

public interface SortStrategy {
public void sort(List<? extends ResultItem> list, boolean forwardSort);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.sql.Timestamp;

import us.mn.state.health.lims.common.util.IdValuePair;
import us.mn.state.health.lims.result.action.util.ResultItem;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class ResultValidationItem implements ResultItem, Serializable{
private String sampleSource;
private String testDate;
private String receivedDate;
private Timestamp collectionDate;

private String analysisMethod;
private String testName;
Expand Down Expand Up @@ -254,6 +256,9 @@ public void setReceivedDate(String receivedDate) {
public String getReceivedDate() {
return receivedDate;
}
public Timestamp getCollectionDate() {
return collectionDate;
}

public void setResult(Result result) {
if (result == null) {
Expand Down
Loading