Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dob and edd format #615

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
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