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

RA-1704: Improved Program Status widget state sorting. #299

Merged
merged 41 commits into from
Mar 19, 2020
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0cbb65f
RA-1704 : improved programstatus state sort order - updating angular…
kml27 Mar 5, 2020
9735682
updating shrinkwrap to angular 1.6.1, updating GET mock
kml27 Mar 6, 2020
44aa9ef
changing use of result var to immediate returns per code style prefer…
kml27 Mar 7, 2020
be3f973
reversing order of null check for endDate, provides short circuit and…
kml27 Mar 7, 2020
06d259b
removing quiet flag from `mvn clean install` to debug travis build
kml27 Mar 9, 2020
8f27c56
fixing comparison of two states with null end dates (from different w…
kml27 Mar 9, 2020
737b555
re-enabling mvn quiet mode to minimize build messages
kml27 Mar 9, 2020
f1ccdba
fixing typo in both enddates not null logic and reciprocal case for s…
kml27 Mar 10, 2020
b304590
RA-1719: Program, Program Status and Relationship widgets not properl…
mogoodrich Mar 10, 2020
0c9c44e
RA-1704 : improved programstatus state sort order - updating angular…
kml27 Mar 5, 2020
db5be35
updating shrinkwrap to angular 1.6.1, updating GET mock
kml27 Mar 6, 2020
02737ae
changing use of result var to immediate returns per code style prefer…
kml27 Mar 7, 2020
f63897e
reversing order of null check for endDate, provides short circuit and…
kml27 Mar 7, 2020
96b5b60
removing quiet flag from `mvn clean install` to debug travis build
kml27 Mar 9, 2020
a209fa4
fixing comparison of two states with null end dates (from different w…
kml27 Mar 9, 2020
abf968e
re-enabling mvn quiet mode to minimize build messages
kml27 Mar 9, 2020
5a0a8d9
fixing typo in both enddates not null logic and reciprocal case for s…
kml27 Mar 10, 2020
e9e5861
changing sort order back to repeated `else if` logic with new check f…
kml27 Mar 10, 2020
f1e6e41
merging master
kml27 Mar 10, 2020
8a97e26
RA-1704 : improved programstatus state sort order - updating angular…
kml27 Mar 5, 2020
051ae62
updating shrinkwrap to angular 1.6.1, updating GET mock
kml27 Mar 6, 2020
9b6aef2
changing use of result var to immediate returns per code style prefer…
kml27 Mar 7, 2020
97d3422
reversing order of null check for endDate, provides short circuit and…
kml27 Mar 7, 2020
6c5dba3
removing quiet flag from `mvn clean install` to debug travis build
kml27 Mar 9, 2020
45a7874
fixing comparison of two states with null end dates (from different w…
kml27 Mar 9, 2020
ed8fcae
re-enabling mvn quiet mode to minimize build messages
kml27 Mar 9, 2020
2665939
fixing typo in both enddates not null logic and reciprocal case for s…
kml27 Mar 10, 2020
bfac9fa
changing sort order back to repeated `else if` logic with new check f…
kml27 Mar 10, 2020
660ddd2
removing quiet flag from `mvn clean install` to debug travis build
kml27 Mar 9, 2020
9994fa0
re-enabling mvn quiet mode to minimize build messages
kml27 Mar 9, 2020
f520844
adding additional documentation of logic in sort
kml27 Mar 12, 2020
b7438d8
RA-1724: Fix NPE/undefined error in obsgraph dashboard widget.
Ruhanga Mar 11, 2020
0091919
RA-1725: ObsGraph - Added optional filter encounter type parameter fo…
rrameshbtech-tw Mar 12, 2020
a6a863a
RA-1724: Follow-on commit to fix nul typo (#304)
Ruhanga Mar 12, 2020
12955cf
make dependent on latest version of REST web services
mogoodrich Mar 12, 2020
98df88e
try adding REST web services 1.12 dependency to fix build
mogoodrich Mar 12, 2020
7eff6a6
revert:upgrade to latest version of REST web services
mogoodrich Mar 12, 2020
0fe25e2
HTML-718, gray out retired concepts (#303)
cioan Mar 12, 2020
33c69bb
rebasing on/merging updates to master
kml27 Mar 12, 2020
945c3d9
commiting checkouts from master to clean up commit diff
kml27 Mar 12, 2020
aece07c
after syncing fork master HEAD, commiting checkouts from master to cl…
kml27 Mar 12, 2020
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 .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,9 +55,7 @@ export default class ProgramsController {
}

fetchPrivileges() {
this.openmrsRest.get('session', {
v: 'custom:(privileges:(name))'
}).then((response) => {
this.openmrsRest.get('session').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,18 +66,14 @@ 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() {
this.openmrsRest.get('session', {
v: 'custom:(privileges:(name))'
}).then((response) => {
this.openmrsRest.get('session').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 Expand Up @@ -107,7 +102,7 @@ export default class ProgramStatusController {
// if there is only possible location, set it as the default (this is why loading locations (in activate) needs to happen before patient programs)
else if (this.programLocations && this.programLocations.length == 1) {
this.input.enrollmentLocation = this.programLocations[0].uuid;
}
}
// if we have more than one location, set the current session's location as the default
else if (this.programLocations) {
if (this.sessionLocation) {
Expand Down Expand Up @@ -242,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 @@ -417,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 @@ -466,8 +461,45 @@ 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.patientProgram.states = this.$filter('orderBy')(this.patientProgram.states, null, false, function(state1, state2)
{
//orderBy falls back to index comparison when two states are indicated to be equal
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;
}
kml27 marked this conversation as resolved.
Show resolved Hide resolved

//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