Skip to content

Commit

Permalink
Merge pull request #32 from openhealthcare/27-add-many-unrolled-pathways
Browse files Browse the repository at this point in the history
adds many unrolled pathways
  • Loading branch information
davidmiller committed Jul 11, 2016
2 parents bb790c3 + 9ffef30 commit 4f21667
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 48 deletions.
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ A pathway is made up of 1-n `Steps`. These are defined on the pathway class usin
In the simplest case, we can simply add OPAL `Subrecords` to this tuple, and the Pathway
will use the default form from `Subrecord.get_form_template`.


For instance, to create a simple wizard style pathway with three steps to record a
patient's allergies, treatment and past medical history, we could use the following:

Expand All @@ -56,11 +57,28 @@ class SimplePathway(pathways.Pathway):

You could access this pathway from e.g. `http:\\localhost:8000\pathway\#\simples\`.


Sometimes we may want to add multiple instances of a subrecord at the same time, for example when we're recording multiple allergies. To add a multiple step simply use a MultiSaveStep, for example:

```python
from pathway import pathways
from myapp import models

class SimplePathway(pathways.Pathway):
display_name = 'A simple pathway'
slug = 'simples'
steps = (
pathways.MultiSaveStep(model=models.Allergies),
models.Treatment,
models.PastMedicalHistory
)
```

### Success redirects

Often, after succesfully saving a pathway, we want to redirect the user to a different
Often, after successfully saving a pathway, we want to redirect the user to a different
url - we do this by overriding the `redirect_url` method on the pathway. For example -
to create a pathway that always logged the user out after a successfull save:
to create a pathway that always logged the user out after a successful save:

```python
class LogoutPathway(pathways.Pathway):
Expand Down Expand Up @@ -104,7 +122,7 @@ time.

### ModalPathway

A pathway typwe for use inside OPAL modals.
A pathway type for use inside OPAL modals.

# Reference

Expand Down
58 changes: 25 additions & 33 deletions pathway/static/js/pathway/controllers/multi_save.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
angular.module('opal.controllers').controller('MultiSaveCtrl',
function(Options, $controller, step, scope, episode) {
"use strict";
var vm = this;
var key = step.api_name;

var parentCtrl = $controller("MultistageDefault");
_.extend(vm, parentCtrl);
scope.step = step;

vm.step = step;
vm.multipleModels = [];

vm.cleanModel = function(editing_field){
_.each(_.keys(editing_field), function(a){
editing_field[a] = undefined;
});
scope.addAnother = function(){
scope.allEditing.push({key: undefined});
};

if(episode && episode[step.api_name].length > 1){
vm.multipleModels = angular.copy(episode[step.api_name]);
var editing_field = scope.editing[step.api_name];
vm.cleanModel(editing_field);
}

vm.isClean = function(editing_field){
return !_.some(_.values(editing_field));
};
scope.instanceName = step.title;

vm.addAnother = function(){
var editing_field = scope.editing[step.api_name];
scope.init = function(){
scope.allEditing = _.map(episode[key], function(row){
var editing = {}
editing[key] = row;
return editing;
});

if(!vm.isClean(editing_field)){
vm.multipleModels.push(angular.copy(editing_field));
vm.cleanModel(editing_field);
}
// add a blank row to the bottom
scope.addAnother();
};

vm.remove = function($index){
vm.multipleModels.splice($index, 1);
scope.remove = function($index){
scope.allEditing.splice($index, 1);
};

vm.preSave = function(editing){
var all_models = angular.copy(vm.multipleModels);
if(!vm.isClean(editing[step.api_name])){
all_models.push(editing[step.api_name]);
}
editing[step.api_name] = all_models;
scope.preSave = function(editing){
var all_models = angular.copy(scope.allEditing);

var result = _.reduce(all_models, function(memo, row){
return memo.concat(_.values(row));
}, [])

editing[step.api_name] = result;
};

scope.init();
});
4 changes: 2 additions & 2 deletions pathway/static/js/pathway/services/multi_stage_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ angular.module('opal.services').provider('multistage', function(){
var editing = angular.copy(createdScope.editing);

_.each(steps, function(step){
if(step.controller.preSave){
step.controller.preSave(editing);
if(step.scope.preSave){
step.scope.preSave(editing);
}
});

Expand Down
15 changes: 5 additions & 10 deletions pathway/templates/pathway/multi_save.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
<div class="well" ng-repeat="item in currentStep.controller.multipleModels">
<div class="row">
<div class="col-md-10">
<div ng-include src="currentStep.record_url"></div>
</div>
<div class="col-md-2">
<btn class=" pointer" type="button" ng-click="currentStep.controller.remove($index)"><i class="fa fa-minus"></i></btn>
</div>
<div ng-repeat="editing in allEditing">
<div class="col-md-10 col-md-push-1 content-offset-below-10">
<h4>[[ instanceName ]] [[ $index + 1 ]] <a ng-click="remove($index)"><i class="fa fa-times-circle"></i></a></h4>
</div>
<span ng-include src="currentStep.model_form_url"></span>
</div>
<span ng-include src="currentStep.model_form_url"></span>
<div class="row">
<div class="col-sm-11">
<a ng-click="currentStep.controller.addAnother()" class="pull-right btn btn-primary">Add Another</a>
<a ng-click="addAnother()" class="pull-right btn btn-primary">Add Another</a>
</div>
</div>

0 comments on commit 4f21667

Please sign in to comment.