Skip to content
This repository was archived by the owner on Sep 18, 2018. It is now read-only.
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
46 changes: 46 additions & 0 deletions app/abTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const $ = require('jquery');
const lookup = require('./lookup');
const abConfig = require('../shared/ab/config');

// don't cache always fetch
const getRunningTests = (randomisationTypeIds, callback) =>
$.getJSON(`/ab/running?randomisationTypeId=${randomisationTypeIds.join('&randomisationTypeId=')}`, tests => callback(tests));

module.exports = {

clearPageGroups: () => {
if (lookup.pageGroups) {
lookup.pageGroups.forEach((test) => {
delete lookup.tests[test];
});
}
},

process: (randomisationTypeIds, callback) => {
if (!lookup.tests) lookup.tests = {};
if (!lookup.pageGroups) lookup.pageGroups = [];
getRunningTests(randomisationTypeIds, (tests) => {
if (tests) {
tests.forEach((test) => {
// assign the user to a group (might be already defined)
test.group = abConfig.assign(test);
// add to the state object
lookup.tests[test.name] = test.group;

// keep track of perPage and perPatientView
if (test.randomisationTypeId === abConfig.randomisationTypes.perPage.id ||
test.randomisationTypeId === abConfig.randomisationTypes.perPatientViewed.id) {
lookup.pageGroups.push(test.name);
}

// if the user is in the feature group execute
abConfig.init($, test);
console.log(`User ${lookup.userName} assigned to the '${test.group}' group for test '${test.name}'`);
});
}
if (callback) callback();
});
},

};

25 changes: 19 additions & 6 deletions app/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const log = {

event(type, url, dataProp, xpath) {
const dataToSend = { event: { type, url, pageId, data: dataProp } };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.event.tests = lookup.tests;
if (xpath && xpath.length > 0) dataToSend.event.xpath = xpath;
$.ajax({
type: 'POST',
Expand Down Expand Up @@ -95,10 +96,12 @@ const log = {

// rwhere
recordIndividualPlan(text, practiceId, patientId, indicatorList, done) {
const dataToSend = { actionText: text, indicatorList, pageId };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.tests = lookup.tests;
$.ajax({
type: 'POST',
url: `/api/action/addIndividual/${practiceId}/${patientId}`,
data: JSON.stringify({ actionText: text, indicatorList, pageId }),
data: JSON.stringify(dataToSend),
success(action) {
notify.showSaved();
data.addOrUpdatePatientAction(patientId, action, () => done(null, action));
Expand All @@ -124,10 +127,12 @@ const log = {

// rwhere
updateIndividualAction(practiceId, patientId, updatedAction, callback) {
const dataToSend = { action: updatedAction, url: window.location.href, pageId };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.tests = lookup.tests;
$.ajax({
type: 'POST',
url: `/api/action/update/individual/${practiceId}/${patientId}`,
data: JSON.stringify({ action: updatedAction, url: window.location.href, pageId }),
data: JSON.stringify(dataToSend),
success(action) {
notify.showSaved();
if (action.agree === true) {
Expand All @@ -143,10 +148,12 @@ const log = {
},

updateTeamAction(practiceId, indicatorId, dataProp, done) {
const dataToSend = { action: dataProp, url: window.location.href, pageId };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.tests = lookup.tests;
$.ajax({
type: 'POST',
url: `/api/action/update/team/${practiceId}/${indicatorId}`,
data: JSON.stringify({ action: dataProp, url: window.location.href, pageId }),
data: JSON.stringify(dataToSend),
success(d) {
if (!done) return notify.showSaved();
return done(null, d);
Expand All @@ -157,10 +164,12 @@ const log = {
},

updateUserDefinedPatientAction(patientId, actionTextId, dataProp, callback) {
const dataToSend = { action: dataProp };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.tests = lookup.tests;
$.ajax({
type: 'POST',
url: `/api/action/update/userdefinedpatient/${patientId}/${actionTextId}`,
data: JSON.stringify({ action: dataProp }),
data: JSON.stringify(dataToSend),
success(action) {
notify.showSaved();
action.oldActionTextId = actionTextId;
Expand All @@ -185,10 +194,12 @@ const log = {
},

updateUserDefinedTeamAction(actionTextId, dataProp, done) {
const dataToSend = { action: dataProp };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.tests = lookup.tests;
$.ajax({
type: 'POST',
url: `/api/action/update/userdefinedteam/${actionTextId}`,
data: JSON.stringify({ action: dataProp }),
data: JSON.stringify(dataToSend),
success(d) {
if (!done) return notify.showSaved();
return done(null, d);
Expand All @@ -200,10 +211,12 @@ const log = {

recordTeamPlan(practiceId, text, indicatorId, done) {
const url = `/api/action/addTeam/${practiceId}/${indicatorId || ''}`;
const dataToSend = { actionText: text, pageId };
if (lookup.tests && Object.keys(lookup.tests).length > 0) dataToSend.tests = lookup.tests;
$.ajax({
type: 'POST',
url,
data: JSON.stringify({ actionText: text, pageId }),
data: JSON.stringify(dataToSend),
success(d) {
notify.showSaved();
return done(null, d);
Expand Down
5 changes: 5 additions & 0 deletions app/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ require('datatables.net-buttons-bs')(window, $);
require('datatables.net-buttons/js/buttons.colVis.js')(window, $);
require('datatables.net-buttons/js/buttons.html5.js')(window, $);

const { randomisationTypes } = require('../shared/ab/config');

/*
* For each disease area there will be 4 stages: Diagnosis, Monitoring, Treatment and Exclusions.
* Each stage gets a single panel on the front screen.
Expand All @@ -21,6 +23,7 @@ const events = require('./events');
const state = require('./state');
const layout = require('./layout');
const tutorial = require('./tutorial');
const abTests = require('./abTests');

// TODO not sure why i did this - was in local variable
// maybe a separate module
Expand Down Expand Up @@ -110,6 +113,8 @@ const App = {

getServerParameters();

abTests.process([randomisationTypes.perUser.id, randomisationTypes.perSession.id]);

main.getInitialData(() => {
gotInitialData = true;
if (gotInitialData && pageIsReady) {
Expand Down
7 changes: 7 additions & 0 deletions app/template.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
const log = require('./log');
const lookup = require('./lookup');
const base = require('./base');
const abTests = require('./abTests');
const layout = require('./layout');
const overview = require('./views/overview');
const indicatorView = require('./views/indicator');
const patientView = require('./views/patient');
const actionPlan = require('./views/actions');
const { randomisationTypes } = require('../shared/ab/config');

const template = {
loadContent(hash, isPoppingState, callback) {
base.hideTooltips();

// Must do this before we log the navigate page event
abTests.clearPageGroups();

log.navigatePage(hash, []);

let patientId;
Expand All @@ -27,6 +32,7 @@ const template = {
$('html').removeClass('scroll-bar');
shouldCallCallback = true;
} else {
abTests.process([randomisationTypes.perPage.id]);
base.hideFooter();
// $('html').addClass('scroll-bar');
const params = {};
Expand Down Expand Up @@ -66,6 +72,7 @@ const template = {
shouldCallCallback = true;
} else if (urlBits[0] === '#patient') {
// create(pathwayId, pathwayStage, standard, patientId)
abTests.process([randomisationTypes.perPatientViewed]);
patientView.create(
urlBits[2],
urlBits[3],
Expand Down
2 changes: 1 addition & 1 deletion brunch-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const routeIndex = require('./server/routes/index');
const debug = require('debug')('passport-mongo:server');
const http = require('http');

const DEBUG = false;
const DEBUG = true;

module.exports = (PORT, PATH, CALLBACK) => {
mongoose.set('debug', DEBUG);
Expand Down
7 changes: 7 additions & 0 deletions docs/AB_TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Create tests with UI

Each test then gets an entry in shared/ab/tests.js. Can be autogenerated with `node shared/ab/generate.js`

Names of tests must be unique

Once code for init and pull down are set and ready to go set the `readyToDeploy` flag to true
Loading