Skip to content

Commit

Permalink
Merge pull request #19 from openhealthcare/pathways-for-contact-tracing
Browse files Browse the repository at this point in the history
these changes should just be a good idea...
  • Loading branch information
davidmiller committed Jul 1, 2016
2 parents d7e42e5 + 1a21aac commit 72b65c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
41 changes: 17 additions & 24 deletions pathway/static/js/pathway/services/multi_stage_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,23 @@ angular.module('opal.services').provider('multistage', function(){
var loadStepControllers = function(scope){
var episode;

if(multistageOptions.clonedEpisode){
episode = multistageOptions.clonedEpisode;
// TODO change this to use item
// but for the moment, remove all circular structures
if(multistageOptions.episode){
episode = multistageOptions.episode;
_.each(episode, function(subrecords, k){
if(_.isArray(subrecords)){
_.each(subrecords, function(subrecord){
_.each(subrecord, function(field, key){
if(field === episode){
delete subrecord[key];
}
});
})
}
})
}

_.each(scope.steps, function(step){
if(step.controller_class){
step.controller = $controller(step.controller_class, {
Expand Down Expand Up @@ -135,28 +149,6 @@ angular.module('opal.services').provider('multistage', function(){
newScope.currentIndex = 0;
newScope.numSteps = multistageOptions.steps.length;
newScope.editing = {};


// We were passed in a patient.
// Let's make sure we can edit every item for the patient.
if(multistageOptions.episode){
var clonedEpisode = {};
_.each(_.keys($rootScope.fields), function(key){
var copies = _.map(
multistageOptions.episode[key],
function(record){
return record.makeCopy();
});
clonedEpisode[key] = copies;
if(copies.length > 0){
newScope.editing[key] = copies[0]
}else{
newScope.editing[key] = {}
}
});
multistageOptions.clonedEpisode = clonedEpisode;
}

newScope.currentStep = newScope.steps[newScope.currentIndex];
newScope.stepIndex = function(step){
return _.findIndex(newScope.steps, function(someStep){
Expand All @@ -174,6 +166,7 @@ angular.module('opal.services').provider('multistage', function(){

var templateAndResolvePromise = getTemplatePromise(multistageOptions);
templateSteps = getStepTemplates(multistageOptions.steps);

$q.all([templateAndResolvePromise, templateSteps]).then(function(loadedHtml){
loadStepControllers(newScope);
var baseTemplate = loadedHtml[0];
Expand Down
5 changes: 4 additions & 1 deletion pathway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def dispatch(self, *args, **kwargs):
return super(SavePathway, self).dispatch(*args, **kwargs)

def create(self, request, **kwargs):
pathway = Pathway.get(self.name)(episode_id=self.episode_id)
pathway = Pathway.get(self.name)(
episode_id=self.episode_id,
patient_id=self.patient_id
)
data = _get_request_data(request)
patient = pathway.save(data, request.user)
redirect = pathway.redirect_url(patient)
Expand Down

0 comments on commit 72b65c6

Please sign in to comment.