Skip to content

Commit

Permalink
RA-1704: Improved Program Status widget state sorting.
Browse files Browse the repository at this point in the history
* RA-1704 : improved programstatus state sort order - updating angular to 1.6.1 to get $httpBackend.flush() fix, changes to use a proper promise chain for test

* updating shrinkwrap to angular 1.6.1, updating GET mock

* changing use of result var to immediate returns per code style preferences

* reversing order of null check for endDate, provides short circuit and avoids ambiguous coercion/eval

* removing quiet flag from `mvn clean install` to debug travis build

* fixing comparison of two states with null end dates (from different workflows in the same program), adding logic for angular fallback orderby index, re-order expected order test states

* re-enabling mvn quiet mode to minimize build messages

* fixing typo in both enddates not null logic and reciprocal case for state1 endDate == null

* RA-1719: Program, Program Status and Relationship widgets not properly retrieving session use (openmrs#300)

* RA-1704 : improved programstatus state sort order - updating angular to 1.6.1 to get $httpBackend.flush() fix, changes to use a proper promise chain for test

* updating shrinkwrap to angular 1.6.1, updating GET mock

* changing use of result var to immediate returns per code style preferences

* reversing order of null check for endDate, provides short circuit and avoids ambiguous coercion/eval

* removing quiet flag from `mvn clean install` to debug travis build

* fixing comparison of two states with null end dates (from different workflows in the same program), adding logic for angular fallback orderby index, re-order expected order test states

* re-enabling mvn quiet mode to minimize build messages

* fixing typo in both enddates not null logic and reciprocal case for state1 endDate == null

* changing sort order back to repeated `else if` logic with new check for not both null and ordering when state1 endDate is null, new order of states in test

* RA-1704 : improved programstatus state sort order - updating angular to 1.6.1 to get $httpBackend.flush() fix, changes to use a proper promise chain for test

* updating shrinkwrap to angular 1.6.1, updating GET mock

* changing use of result var to immediate returns per code style preferences

* reversing order of null check for endDate, provides short circuit and avoids ambiguous coercion/eval

* removing quiet flag from `mvn clean install` to debug travis build

* fixing comparison of two states with null end dates (from different workflows in the same program), adding logic for angular fallback orderby index, re-order expected order test states

* re-enabling mvn quiet mode to minimize build messages

* fixing typo in both enddates not null logic and reciprocal case for state1 endDate == null

* changing sort order back to repeated `else if` logic with new check for not both null and ordering when state1 endDate is null, new order of states in test

* removing quiet flag from `mvn clean install` to debug travis build

* re-enabling mvn quiet mode to minimize build messages

* RA-1724: Fix NPE/undefined error in obsgraph dashboard widget.

* RA-1724 : Fix NPE/undefined error in obsgraph dashboard widget when some concept do not have associated obs

* RA-1724  : Adding null check

* RA-1725: ObsGraph - Added optional filter encounter type parameter for obsgraph.

* Added optional filter encounter type parameter for obsgraph

* Added support for multiple encounter types in obsGraph

* RA-1724: Follow-on commit to fix nul typo (openmrs#304)

* make dependent on latest version of REST web services

* try adding REST web services 1.12 dependency to fix build

* HTML-718, gray out retired concepts (openmrs#303)

* revert:upgrade to latest version of REST web services

* adding additional documentation of logic in sort

* commiting checkouts from master to clean up commit diff

* after syncing fork master HEAD, commiting checkouts from master to clean up commit diff

Co-authored-by: Mark Goodrich <[email protected]>
Co-authored-by: Ruhanga <[email protected]>
Co-authored-by: Ramesh Ramalingam <[email protected]>
Co-authored-by: Cosmin <[email protected]>
  • Loading branch information
5 people authored Mar 19, 2020
1 parent 5c64460 commit 73b2d61
Show file tree
Hide file tree
Showing 7 changed files with 661 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ target

.DS_Store

.vscode

# Package Files #
*.jar
*.war
Expand Down
17 changes: 12 additions & 5 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export default class ProgramsController {
}

fetchPrivileges() {
this.openmrsRest.get('session').then((response) => {
this.openmrsRest.get('session', {
v: 'custom:(privileges:(name))'
}).then((response) => {
if (response && response.user && angular.isArray(response.user.privileges)) {
if (response.user.privileges.some( (p) => { return p.name === 'Task: coreapps.enrollInProgram'; })) {
this.canEnrollInProgram = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class ProgramStatusController {
}

$onInit() {
this.vPatientProgram = 'custom:uuid,program:(uuid),dateEnrolled,dateCompleted,outcome:(display),location:(display,uuid),dateCompleted,outcome,states:(uuid,startDate,endDate,voided,state:(uuid,concept:(display)))';
this.vPatientProgram = 'custom:uuid,program:(uuid),dateEnrolled,dateCompleted,outcome:(display),location:(display,uuid),dateCompleted,outcome,states:(uuid,startDate,endDate,dateCreated,voided,state:(uuid,concept:(display)))';

this.dateFormat = (this.config.dateFormat == '' || angular.isUndefined(this.config.dateFormat))
? 'dd-MMM-yyyy' : this.config.dateFormat;
Expand Down Expand Up @@ -53,11 +53,10 @@ export default class ProgramStatusController {
}

this.resetWindowStates();

this.activate();


let ctrl = this;

return this.activate();
}

activate() {
Expand All @@ -67,12 +66,10 @@ export default class ProgramStatusController {

this.fetchSessionLocation();

this.fetchLocations().then((response) => {
this.fetchProgram().then((response) => {
this.fetchOutcomes();
this.fetchPatientProgram()
});
});
return this.fetchLocations()
.then(this.fetchProgram.bind(this))
.then(this.fetchOutcomes.bind(this))
.then(this.fetchPatientProgram.bind(this));
}

fetchPrivileges() {
Expand Down Expand Up @@ -240,7 +237,6 @@ export default class ProgramStatusController {
return (patientProgram.program.uuid == this.config.program);
});


if (this.patientPrograms.length > 0) {

// sort programs in order
Expand Down Expand Up @@ -415,6 +411,7 @@ export default class ProgramStatusController {

getWorkflowForState(state) {
let result;

angular.forEach(this.program.workflows, (workflow) => {
angular.forEach(workflow.states, (workflowState) => {
if (state.uuid == workflowState.uuid) {
Expand Down Expand Up @@ -464,8 +461,54 @@ export default class ProgramStatusController {
this.patientProgram.states = this.$filter('filter')(this.patientProgram.states, (state) => {
return !state.voided
}, true);
this.patientProgram.states = this.$filter('orderBy')(this.patientProgram.states, (state) => {
return new Date(state.startDate);

//this custom comparator is detailed in the PR at https://github.com/openmrs/openmrs-module-coreapps/pull/299
//the orderBy docs are available at https://docs.angularjs.org/api/ng/filter/orderBy
this.patientProgram.states = this.$filter('orderBy')(this.patientProgram.states, null, false, function(state1, state2)
{
//From the orderBy documentation

//In order to ensure that the sorting will be deterministic across platforms, if none of the specified predicates can
//distinguish between two items, orderBy will automatically introduce a dummy predicate that returns the item's index
//as value. (If you are using a custom comparator, make sure it can handle this predicate as well.)

//i.e. orderBy falls back to index comparison when two states are indicated to be equal (return 0) in a previous comparison
if(state1.type === "number" && state2.type === "number"){
//if index of state1 is 7 and state2 is 8, 7-8 == -1 indicates state1 is first, 8-7 == 1 indicating state2 is first
return state1.value-state2.value;
}

//this sort is done against ALL workflows within a program
//in which case it is possible to have two states with null end dates,
//and that is the exception to when endDate==null indicates sort order clearly
if(!(state1.value.endDate == null && state2.value.endDate == null)) {

//ordered so each criteria is evaluated in order (e.g. not all "prev" crit. before "next" crit. is ever evaluated)

//null end date prioritized over any other sort criteria
if(state2.value.endDate == null){
return -1;
} else if( state1.value.endDate == null){
return 1;
//sort by start date
} else if( state1.value.startDate < state2.value.startDate) {
return -1;
} else if ( state1.value.startDate > state2.value.startDate) {
return 1;
//sort by end date
} else if(state1.value.endDate < state2.value.endDate){
return -1;
} else if (state1.value.endDate > state2.value.endDate) {
return 1;
//sort by date created
} else if(state1.value.dateCreated < state2.value.dateCreated){
return -1;
} else if(state1.value.dateCreated > state2.value.dateCreated){
return 1;
}

}
return 0;
});

angular.forEach(this.patientProgram.states, (patientState) => {
Expand Down
Loading

0 comments on commit 73b2d61

Please sign in to comment.