Skip to content

Commit

Permalink
Merge pull request #615 from praekeltfoundation/feature-edd-update
Browse files Browse the repository at this point in the history
Dob and edd format
  • Loading branch information
DevChima authored Oct 24, 2023
2 parents 7ea1a04 + a47d27d commit 7e0f958
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
23 changes: 18 additions & 5 deletions go-app-ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,11 @@ go.app = function() {
});
};

self.dateformat = function(timestamp){
timestamp = (timestamp) ? timestamp.split('T')[0] : timestamp;
return timestamp;
};

self.states.add("state_start", function(name, opts) {
// Reset user answers when restarting the app
self.im.user.answers = {};
Expand Down Expand Up @@ -449,15 +454,23 @@ go.app = function() {

self.add("state_change_info", function(name) {
var contact = self.im.user.answers.contact;
var baby_dob1, baby_dob2, baby_dob3, dates_count, edd, postbirth;
var dates_count, postbirth;
var dates_list = [];
var channel = _.get(contact, "fields.preferred_channel");
var baby_dob1 = _.get(contact, "fields.baby_dob1", null);
var baby_dob2 = _.get(contact, "fields.baby_dob2", null);
var baby_dob3 = _.get(contact, "fields.baby_dob3", null);
var edd = _.get(contact, "fields.edd", null);
baby_dob1 = self.dateformat(baby_dob1);
baby_dob2 = self.dateformat(baby_dob2);
baby_dob3 = self.dateformat(baby_dob3);
edd = self.dateformat(edd);
var context = {
dobs: _.map(_.filter([
new moment(_.get(contact, "fields.edd", null)),
new moment(_.get(contact, "fields.baby_dob1", null)),
new moment(_.get(contact, "fields.baby_dob2", null)),
new moment(_.get(contact, "fields.baby_dob3", null)),
new moment(edd),
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
var dates_entry = Object.values(context);
Expand Down
23 changes: 18 additions & 5 deletions src/ussd_popi_rapidpro.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ go.app = function() {
});
};

self.dateformat = function(timestamp){
timestamp = (timestamp) ? timestamp.split('T')[0] : timestamp;
return timestamp;
};

self.states.add("state_start", function(name, opts) {
// Reset user answers when restarting the app
self.im.user.answers = {};
Expand Down Expand Up @@ -289,15 +294,23 @@ go.app = function() {

self.add("state_change_info", function(name) {
var contact = self.im.user.answers.contact;
var baby_dob1, baby_dob2, baby_dob3, dates_count, edd, postbirth;
var dates_count, postbirth;
var dates_list = [];
var channel = _.get(contact, "fields.preferred_channel");
var baby_dob1 = _.get(contact, "fields.baby_dob1", null);
var baby_dob2 = _.get(contact, "fields.baby_dob2", null);
var baby_dob3 = _.get(contact, "fields.baby_dob3", null);
var edd = _.get(contact, "fields.edd", null);
baby_dob1 = self.dateformat(baby_dob1);
baby_dob2 = self.dateformat(baby_dob2);
baby_dob3 = self.dateformat(baby_dob3);
edd = self.dateformat(edd);
var context = {
dobs: _.map(_.filter([
new moment(_.get(contact, "fields.edd", null)),
new moment(_.get(contact, "fields.baby_dob1", null)),
new moment(_.get(contact, "fields.baby_dob2", null)),
new moment(_.get(contact, "fields.baby_dob3", null)),
new moment(edd),
new moment(baby_dob1),
new moment(baby_dob2),
new moment(baby_dob3),
], _.method("isValid")), _.method("format", "DD-MM-YYYY")).join(", ") || $("None")
};
var dates_entry = Object.values(context);
Expand Down
8 changes: 4 additions & 4 deletions test/ussd_popi_rapidpro.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ describe("ussd_popi_rapidpro app", function() {
return tester
.setup.user.state("state_change_info")
.setup.user.answer("contact", {fields: {preferred_channel: "SMS",
baby_dob1: "2021-03-10",
baby_dob2: "2021-11-11",
baby_dob3: "2022-07-07",
edd: "2020-06-04",
baby_dob1: "2021-03-10T00:00:00.000000Z",
baby_dob2: "2021-11-11T00:00:00.000000Z",
baby_dob3: "2022-07-07T00:00:00.000000Z",
edd: "2020-06-04T00:00:00.000000Z",
}})
.check.interaction({
reply: [
Expand Down

0 comments on commit 7e0f958

Please sign in to comment.