Skip to content

Commit

Permalink
Add system navigation directive
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupert Bedford committed Oct 12, 2016
1 parent 7084353 commit de79050
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 69 deletions.
43 changes: 43 additions & 0 deletions src/app/patients/get-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import _ from 'lodash';

import getPage from './get-page';
import getForm from './get-form';

/** Combine the page and form links for this group. */
function getLinks(group, patient) {
var links = [];

_.forEach(group.pages, function(x) {
// Get this link for this page (returns null if not found)
var link = getPage(x.page, patient, group);

if (!link) {
return;
}

// Add the page to the list of links
links.push({
link: link,
weight: x.weight
});
});

// Create a link for each form
_.forEach(group.forms, function(x) {
// Get the link for this form
var link = getForm(x.form, patient);

links.push({
link: link,
weight: x.weight
});
});

// Sort pages/forms by weight (lower numbers first)
links = _.sortBy(links, 'weight');
links = _.map(links, 'link');

return links;
}

export default getLinks;
43 changes: 1 addition & 42 deletions src/app/patients/navigation/cohort-navigation.directive.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
import _ from 'lodash';

import getPage from '../get-page.js';
import getForm from '../get-form.js';
import getLinks from '../get-links';

import templateUrl from './cohort-navigation.html';

/** Combine the page and form links for this group. */
function getLinks(group, patient) {
var links = [];

_.forEach(group.pages, function(x) {
// Get this link for this page (returns null if not found)
var link = getPage(x.page, patient, group);

if (!link) {
return;
}

// Add the page to the list of links
links.push({
link: link,
weight: x.weight
});
});

// Create a link for each form
_.forEach(group.forms, function(x) {
// Get the link for this form
var link = getForm(x.form, patient);

links.push({
link: link,
weight: x.weight
});
});

// Sort pages/forms by weight (lower numbers first)
links = _.sortBy(links, 'weight');
links = _.map(links, 'link');

return links;
}


function cohortNavigation() {
return {
scope: {
Expand Down
2 changes: 2 additions & 0 deletions src/app/patients/navigation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import angular from 'angular';

import cohortNavigation from './cohort-navigation.directive';
import patientNavigation from './patient-navigation.directive';
import systemNavigation from './system-navigation.directive';

export default angular.module('radar.patients.navigation', [])
.directive('cohortNavigation', cohortNavigation)
.directive('patientNavigation', patientNavigation)
.directive('systemNavigation', systemNavigation)
.name;
9 changes: 9 additions & 0 deletions src/app/patients/navigation/patient-navigation.directive.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

import templateUrl from './patient-navigation.html';

function patientNavigation(sortCohorts) {
Expand All @@ -7,6 +9,13 @@ function patientNavigation(sortCohorts) {
},
templateUrl: templateUrl,
link: function(scope) {
scope.$watchCollection(function() {
return scope.patient.getSystems();
}, function(systems) {
// Sort the systems by name
scope.systems = _.sortBy(systems, 'name');
});

scope.$watchCollection(function() {
// Only show current cohorts in the navigation
return scope.patient.getCurrentCohorts();
Expand Down
32 changes: 5 additions & 27 deletions src/app/patients/navigation/patient-navigation.html
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
<div class="patient-nav">
<ul>
<li class="radar">
RaDaR
</li>

<li ui-sref-active="active">
<a ui-sref="patient.demographics({patientId: patient.id})">Demographics</a>
</li>

<li ui-sref-active="active">
<a ui-sref="patient.consultants({patientId: patient.id})">Consultants</a>
</li>

<li ui-sref-active="active">
<a ui-sref="patient.cohorts({patientId: patient.id})">Cohorts</a>
</li>

<li ui-sref-active="active">
<a ui-sref="patient.hospitals({patientId: patient.id})">Hospitals</a>
</li>

<li ui-sref-active="active">
<a ui-sref="patient.all({patientId: patient.id})">More&hellip;</a>
</li>
</ul>
</div>
<div
ng-repeat="system in systems"
system-navigation
patient="patient"
system="system"></div>

<div
ng-repeat="cohort in cohorts"
Expand Down
18 changes: 18 additions & 0 deletions src/app/patients/navigation/system-navigation.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import getLinks from '../get-links';

import templateUrl from './system-navigation.html';

function systemNavigation() {
return {
scope: {
system: '=',
patient: '='
},
templateUrl: templateUrl,
link: function(scope) {
scope.items = getLinks(scope.system, scope.patient);
}
};
}

export default systemNavigation;
15 changes: 15 additions & 0 deletions src/app/patients/navigation/system-navigation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="patient-nav">
<ul>
<li class="radar">
{{system.shortName}}
</li>

<li ui-sref-active="active" ng-repeat="item in items">
<a ui-sref="{{item.state}}">{{item.name}}</a>
</li>

<li ui-sref-active="active">
<a ui-sref="patient.all({patientId: patient.id})">More&hellip;</a>
</li>
</ul>
</div>
10 changes: 10 additions & 0 deletions src/app/patients/patient-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function patientModelFactory(Model, store) {
return filterGroupPatientsByType(this.groups, 'COHORT');
};

/** Get memberships for system groups. */
PatientModel.prototype.getSystemPatients = function() {
return filterGroupPatientsByType(this.groups, 'SYSTEM');
};

/** Get current memberships (using from and to date) for hospital groups. */
PatientModel.prototype.getCurrentHospitalPatients = function() {
return filterGroupPatientsByCurrent(this.getHospitalPatients());
Expand All @@ -88,6 +93,11 @@ function patientModelFactory(Model, store) {
return uniqueGroups(this.getHospitalPatients());
};

/** Get a list of unique systems. */
PatientModel.prototype.getSystems = function() {
return uniqueGroups(this.getSystemPatients());
};

/** Get a list of unique groups. */
PatientModel.prototype.getGroups = function() {
return uniqueGroups(this.groups);
Expand Down

0 comments on commit de79050

Please sign in to comment.