From 948af162dd3539e77372f0472f0eb7240e6f6fd4 Mon Sep 17 00:00:00 2001 From: Alex Gilleran Date: Mon, 3 Jul 2017 17:04:04 +1000 Subject: [PATCH] Added reminder emails cron job. --- common/questionnaires.js | 2 + email-pics/green_flag.png | Bin 0 -> 17117 bytes email-pics/red_flag.png | Bin 0 -> 16909 bytes lambda/mark-and-send/Results.html | 43 -- lambda/mark-and-send/index.js | 68 --- lambda/mark-and-send/package.json | 9 - lambda/mark-and-send/sample-parameters.json | 77 ---- .../.gitignore | 0 lambda/reminder-cron/.yarnclean | 42 ++ lambda/reminder-cron/Reminder.html | 4 + .../create-archive.sh | 0 lambda/reminder-cron/index.js | 81 ++++ lambda/reminder-cron/package.json | 10 + lambda/reminder-cron/yarn.lock | 417 ++++++++++++++++++ lambda/wmg-email/.yarnclean | 42 ++ lambda/wmg-email/Doctor.html | 55 ++- lambda/wmg-email/Reminder.html | 4 + lambda/wmg-email/Results.html | 15 +- lambda/wmg-email/index.js | 164 ++++--- lambda/wmg-email/package.json | 2 + lambda/wmg-email/yarn.lock | 405 ++++++++++++++++- src/components/pages/result/result.js | 2 +- src/send-results.js | 6 +- 23 files changed, 1151 insertions(+), 297 deletions(-) create mode 100644 email-pics/green_flag.png create mode 100644 email-pics/red_flag.png delete mode 100644 lambda/mark-and-send/Results.html delete mode 100644 lambda/mark-and-send/index.js delete mode 100644 lambda/mark-and-send/package.json delete mode 100644 lambda/mark-and-send/sample-parameters.json rename lambda/{mark-and-send => reminder-cron}/.gitignore (100%) create mode 100644 lambda/reminder-cron/.yarnclean create mode 100644 lambda/reminder-cron/Reminder.html rename lambda/{mark-and-send => reminder-cron}/create-archive.sh (100%) create mode 100644 lambda/reminder-cron/index.js create mode 100644 lambda/reminder-cron/package.json create mode 100644 lambda/reminder-cron/yarn.lock create mode 100644 lambda/wmg-email/.yarnclean create mode 100644 lambda/wmg-email/Reminder.html diff --git a/common/questionnaires.js b/common/questionnaires.js index 2f2f103..3940be1 100644 --- a/common/questionnaires.js +++ b/common/questionnaires.js @@ -517,6 +517,7 @@ module.exports = [ introduction: "INTRODUCTION FOR CDC MATERIAL TO GO HERE", detail_link: "DETAIL LINK TO GO HERE", age_groups: { min: 16, max: 21 }, + remind_at: 18, analysis: { strategy: "cdc", redFlagThreshold: 1, @@ -711,6 +712,7 @@ module.exports = [ introduction: "INTRODUCTION FOR CDC MATERIAL TO GO HERE", detail_link: "DETAIL LINK TO GO HERE", age_groups: { min: 21, max: 27 }, + remind_at: 24, analysis: { strategy: "cdc", redFlagThreshold: 1, diff --git a/email-pics/green_flag.png b/email-pics/green_flag.png new file mode 100644 index 0000000000000000000000000000000000000000..7c525a2592036a23326d36323c9eb425d5e7ec98 GIT binary patch literal 17117 zcmeHucT`i^+J3--BPui3K?YIqjshxm2I)<&I)I2cg7oGfT?o}cAOZENqbN8aBK;~& zq=a5VLO=wDJ_G?FkWd5+B@qY&Nc;8<-f!K%f9rmK{MLfC4rjqRXP0-s`z_D&?nhUz znC#zscrOBh*l%Wf;Ti(5vlL!?c7y-S|GlCYf%r#`*@bh~;pvNG5znaiF|!-k%m#^7 z4BdB(edpP?qRMC8o`@U_JQ=e7xI!~={3w!8kWz5TQ(Jnn(Z+{`=K8cJTI3h3$viLfF=X z?d`B_6aIfTj5g0$z~nn{dbLTnH#20as~Gn6HB*0EX~beI8*e>=J*6hQ$XdelC8eaen5Tnm`>c?=HBdmB!i~qkg+u z&S`a>DrdxEz3OH!_!`$P2V)249<=B)>_a>IB~iu}(N8FpA3?R89cr`Bno;fq>^|1_NJ=r$!&C8;l%5EJUH#O+S z!>b=`8|tP>n5ppI6y1YCT@lwc;*H9e{Nke`rq!YplaiNr??WKI{C$sI<8#*Sd4``X zmXQ`8;76&@dNk$QPncXZVXn6}`=z}=noq8S#_KLLisn7<>#}RocIDkeayePtK9Y2& z=W^m`Le`~t-r#;$-WZMl-Zom%I7!w#SRA;?o1%x*Jt|jGXAHl5AZ;?@EgLXaWJm0X zipo#}>pfAh)byY{buFg`G=J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UBhL1mK6O&oSM_9oKOmGXKslW{ z*2(nXe=)J$<_~}{w}r4Rgl#$v=)krRwuP|GF8|k1 zrVS5>z!qR|Cr<=0x7%x&^*P#TM_CFbbn3#OoK!)h9K$rX;oVmi#fQ05TR6x|kHkM|i~+a#y12#*`Q1Sb{M zPmMwxI}sG$Gn_*^t^T9QSn}A$1pt>Lgm^~cyT_aN>$SV=c)yVKTRZn_ z3=yhxZZr5>M+!hen!;08NA`W1CAv9$V-v52Q33!x0%2z6Q85f5>+fI43&049CTMnz3c zSi5w10Wrs%0wo*@8C4dYHCyLXa!^hsCR*6VKOiW()rybmLR`eXQ@y5pH|3Tzx}H zCH}Z@a^J1*`MbK0=JSC{<4A!Vbr{6hs&o}O8wg-lNN^`ICM6MwMjEJ2H1mf=T51L? zl^XR}HJs7611T3kw!*ZFEQpSgn8F@cy+s{hnh3E8{85`mP9%f}8dAhA6{>VqTyzrdOFAz-@!h(W$89{QiBdE=_ zKwF;Ei)Nvao0~{Oc4IcGb_NcS6C(8ww@bppI|*ZUw+RiNFF6qxJ@%x~C7Kn7G$7z_ zEXAFO1IJ{anG25}0g54h5jztbe`^C556{QA{TNpVpO-kfNK3ZBq-Q}ydq_)-a=Z7PVrhU{4|3qQLE7~eIRhJeLNQi&FxPk_MZXFZ=xBnJD_J3jN;4rt# rIkttcUCyx`m~WSJ{J&W0N`XZ5C5=Nx@eVv_OwBG{xlr;Cx4ZuX#s%N; literal 0 HcmV?d00001 diff --git a/email-pics/red_flag.png b/email-pics/red_flag.png new file mode 100644 index 0000000000000000000000000000000000000000..152f6232751481e87eff4622246c28231ee1d648 GIT binary patch literal 16909 zcmeHu`#+T1`}dT}E=hZrRHAkzr5sAgxx+3wx1EbIc6KSJk<-**M(16WPYEIH${}PV zISpf!un~%woMxOEV`dzNVUEvQ!)HI=f8hDy`M!9)yoP)3d);eY>sr^kuJ`-B9-Ol= zlU=uc9Rh)nH9z~C9RjiH9sK=i4Yda}>I zMqay8b;8CaUgdnfg;VpC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@ilxl$`Id!q&AX@xbd|LIu_0@qi?Froj$Kh9(w9 zxuSFkS;SJOLytmz>XwLEGp+-aDV9LXKwG|rQkT$(p<)GTP(8$Q;!9p(M=FGtJFz2~ zus)L9`CH$fJ5|r)e3-{d#&YFo$xvm(iPt*_RfwPRO~Ui91L}KH4xS>&1u{{Zysos-$QC+>`~u3gAat{;rxoTPn2zIDI|f*beM%mgLw@Ir}y3&Do5K72qU91w2~80{F#5OK8$y6OEgdc_5tKH7w5x8XZ^EIFJifGE%Wdp2m&k|#HDKD_@M8qaBsHO1oD zpmzs>pLFvc*=5`HK6P}xz#_8m=W%iKFCjYVHkb{DG6+;UlWXp2rZUDlc>_%l7+O3Q z1rQK$HX+qvj0lcJP2^`wjzzU|ypoa(gP8DGRLYIg%K!~x06knQSadQH#Fz|@_(m2S zU#t&41h;|#fu&yZ^K#v=TpvMKSS}Kmjj&uK{;w<&`QjB%|NJ%d*zF@QBS4s+w)u^4 I(&N_u0Uv2T&;S4c literal 0 HcmV?d00001 diff --git a/lambda/mark-and-send/Results.html b/lambda/mark-and-send/Results.html deleted file mode 100644 index 80ccdaa..0000000 --- a/lambda/mark-and-send/Results.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - -
Child's Name{{details.name_of_child}}Date of Test{{details.test_date}}
Date of Birth{{details.dob_child}}Age of Child{{details.age_of_child}}
- -

{{resultText}}

-

Detailed Results Below

- -{{allResults}} -

{{questionnaire.title}}

- - - - - - - {{results}} - - - - - - {{if answer.comments}} - - - - - {{/if}} - {{/results}} -
NumberQuestionYour Response
{{##}}{{metadata.text}}{{answer.metadata.text}}
Comment{{answer.comments}}
-
-{{/allResults}} \ No newline at end of file diff --git a/lambda/mark-and-send/index.js b/lambda/mark-and-send/index.js deleted file mode 100644 index bfe57bd..0000000 --- a/lambda/mark-and-send/index.js +++ /dev/null @@ -1,68 +0,0 @@ -//https://hooks.zapier.com/hooks/catch/2318292/9cdxwr/ - -let https = require("https"); -const fetch = require("isomorphic-fetch"); -var dataFunctions = require("wmg-common/data-functions"); -var markupJs = require("markup-js"); -var mark = dataFunctions.mark; -var combineAll = dataFunctions.combineAll; -var strings = require("wmg-common/strings"); -const fs = require('fs'); - -process.env["PATH"] = - process.env["PATH"] + ":" + process.env["LAMBDA_TASK_ROOT"]; - -console.log("Loading function"); - -/* - POST with these parameters: - { - "recipient_email": - "subject": , - "body": - } - */ - -exports.handler = function(event, context) { - console.log("Event: " + JSON.stringify(event)); - - if (!event.details.recipient_email) { - context.fail("Error: Missing parameter."); - } - - fs.readFile(__dirname + "/Results.html", "utf-8", (err, templateBody) => { - if (err) { - // Error - console.log(err, err.stack); - context.fail("Internal Error: Failed to load template."); - } else { - const combinedResults = combineAll(event.results); - const concern = mark(combinedResults); - const resultStrings = concern - ? strings.result.concerns - : strings.result.noConcerns; - - var message = markupJs.up(templateBody, { - details: event.details, - concern: concern, - allResults: combinedResults, - resultText: resultStrings.title + " " + resultStrings.subtitle - }); - - const x = { - results: event.results, - concern: concern, - details: event.details, - message: message - }; - - fetch("https://hooks.zapier.com/hooks/catch/2318292/9cdxwr/", { - method: "POST", - body: JSON.stringify(x), - headers: { - "Content-Type": "application/json" - } - }); - } - }); -}; diff --git a/lambda/mark-and-send/package.json b/lambda/mark-and-send/package.json deleted file mode 100644 index 1019939..0000000 --- a/lambda/mark-and-send/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "wmg-email", - "version": "0.0.1", - "dependencies": { - "isomorphic-fetch": "^2.2.1", - "markup-js": "^1.5.21", - "wmg-common": "../../common" - } -} diff --git a/lambda/mark-and-send/sample-parameters.json b/lambda/mark-and-send/sample-parameters.json deleted file mode 100644 index 3da08ca..0000000 --- a/lambda/mark-and-send/sample-parameters.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "details": { - "recipient_email": "alex@alexgilleran.com", - "test_date": "Friday, July 29th 2016", - "name_of_parent": "aerg", - "name_of_child": "Alex", - "dob_child": "Thursday, January 14th 2016", - "age_of_child": "6 months", - "results_text": "Your child is developing as expected for their age. Based on your answers you have no concerns about how your child is developing." - }, - "results": { - "qchat": { - "lookatyou": { - "value": "always" - }, - "eyecontacteasiness": { - "value": "veryeasy" - }, - "pointwant": { - "value": "manyday" - }, - "pointshareinterest": { - "value": "manyday" - }, - "pretending": { - "value": "manyday" - }, - "followlooking": { - "value": "manyday" - }, - "comfort": { - "value": "always" - }, - "firstwords": { - "value": "verytypical" - }, - "simplegestures": { - "value": "manyday" - }, - "stareatnothing": { - "value": "manyday" - } - }, - "peds": { - "conerncs": { - "value": "no" - }, - "speech_sound": { - "value": "no" - }, - "understand_speech": { - "value": "no" - }, - "using_hand": { - "value": "no" - }, - "using_arm_leg": { - "value": "no" - }, - "behaviour": { - "value": "no" - }, - "getting_along": { - "value": "no" - }, - "learning": { - "value": "no" - }, - "learning_at_preschool": { - "value": "no" - }, - "other_concerns": { - "value": "no" - } - } - } -} diff --git a/lambda/mark-and-send/.gitignore b/lambda/reminder-cron/.gitignore similarity index 100% rename from lambda/mark-and-send/.gitignore rename to lambda/reminder-cron/.gitignore diff --git a/lambda/reminder-cron/.yarnclean b/lambda/reminder-cron/.yarnclean new file mode 100644 index 0000000..25bdd14 --- /dev/null +++ b/lambda/reminder-cron/.yarnclean @@ -0,0 +1,42 @@ +# test directories +__tests__ +test +tests +powered-test + +# asset directories +docs +doc +website +images +assets + +# examples +example +examples + +# code coverage directories +coverage +.nyc_output + +# build scripts +Makefile +Gulpfile.js +Gruntfile.js + +# configs +.tern-project +.gitattributes +.editorconfig +.*ignore +.eslintrc +.jshintrc +.flowconfig +.documentup.json +.yarn-metadata.json +.*.yml +*.yml + +# misc +*.gz +*.md diff --git a/lambda/reminder-cron/Reminder.html b/lambda/reminder-cron/Reminder.html new file mode 100644 index 0000000..182164b --- /dev/null +++ b/lambda/reminder-cron/Reminder.html @@ -0,0 +1,4 @@ +Thank you for previously completing the Watch Me Grow app. It is recommended that you complete this when your child is aged +approximately 12, 18 and 24 months. This is a reminder to complete the Watch Me Grow app for your child again. As before, +these results will be sent via email. These can also be sent to your nominated health professional. Please go to the +Watch Me Grow app. \ No newline at end of file diff --git a/lambda/mark-and-send/create-archive.sh b/lambda/reminder-cron/create-archive.sh similarity index 100% rename from lambda/mark-and-send/create-archive.sh rename to lambda/reminder-cron/create-archive.sh diff --git a/lambda/reminder-cron/index.js b/lambda/reminder-cron/index.js new file mode 100644 index 0000000..8f67f87 --- /dev/null +++ b/lambda/reminder-cron/index.js @@ -0,0 +1,81 @@ +"use strict"; + +let https = require("https"); +var aws = require("aws-sdk"); +const moment = require("moment"); +const mailgunJs = require("mailgun-js"); +var markupJs = require("markup-js"); +var fs = require("fs"); +var strings = require("wmg-common/strings"); +var questionnaires = require("wmg-common/questionnaires"); +const _ = require("lodash"); + +const mailgun = mailgunJs({ + apiKey: process.env.MAILGUN_API_KEY, + domain: "auto.watchmegrow.care" +}); + +process.env["PATH"] = + process.env["PATH"] + ":" + process.env["LAMBDA_TASK_ROOT"]; + +const questionnaireReminderAges = questionnaires + .filter(questionnaire => questionnaire.remind_at) + .map(questionnaire => ({ + id: questionnaire.id, + remindAgeInDays: moment.duration(questionnaire.remind_at, "months").asDays() + })); + +exports.handler = function(event, context, callback) { + console.log(questionnaireReminderAges); + + return mailgun + .lists("reminders@auto.watchmegrow.care") + .members() + .list() + .then(members => { + const children = _.flatMap(members.items, member => { + return Object.keys(member.vars).map(varKey => + Object.assign(member.vars[varKey], { + name: varKey, + email: member.address, + ageInDays: moment().diff(moment(member.vars[varKey].dob), "days") + }) + ); + }); + + console.log(children); + + const toBeReminded = children.filter(child => + questionnaireReminderAges.some( + questionnaire => + !child.completed[questionnaire.id] && + questionnaire.remindAgeInDays === child.ageInDays + ) + ); + + const promises = toBeReminded.map(child => sendReminder(child)); + + return Promise.all(promises); + }) + .then(result => { + console.log(result); + callback(null, "Successfully executed"); + }) + .catch(e => callback(e)); +}; + +const reminderTemplateBody = fs.readFileSync( + __dirname + "/Reminder.html", + "utf-8" +); + +function sendReminder(child) { + var params = { + from: "mail@watchmegrow.care", + to: child.email, + subject: "Watch Me Grow Reminder for " + child.name, + html: reminderTemplateBody + }; + + return mailgun.messages().send(params); +} diff --git a/lambda/reminder-cron/package.json b/lambda/reminder-cron/package.json new file mode 100644 index 0000000..449870f --- /dev/null +++ b/lambda/reminder-cron/package.json @@ -0,0 +1,10 @@ +{ + "name": "wmg-email", + "version": "0.0.1", + "dependencies": { + "lodash": "^4.17.4", + "mailgun-js": "^0.11.2", + "moment": "^2.18.1", + "wmg-common": "file:../../common" + } +} diff --git a/lambda/reminder-cron/yarn.lock b/lambda/reminder-cron/yarn.lock new file mode 100644 index 0000000..a58b057 --- /dev/null +++ b/lambda/reminder-cron/yarn.lock @@ -0,0 +1,417 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +agent-base@2: + version "2.1.1" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-2.1.1.tgz#d6de10d5af6132d5bd692427d46fc538539094c7" + dependencies: + extend "~3.0.0" + semver "~5.0.1" + +amdefine@>=0.0.4: + version "1.0.1" + resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" + +ast-types@0.x.x: + version "0.9.12" + resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.12.tgz#b136300d67026625ae15326982ca9918e5db73c9" + +async@~2.4.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/async/-/async-2.4.1.tgz#62a56b279c98a11d0987096a01cc3eeb8eb7bbd7" + dependencies: + lodash "^4.14.0" + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + +bytes@2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-2.4.0.tgz#7d97196f9d5baf7f6935e25985549edd2a6c2339" + +co@~3.0.6: + version "3.0.6" + resolved "https://registry.yarnpkg.com/co/-/co-3.0.6.tgz#1445f226c5eb956138e68c9ac30167ea7d2e6bda" + +combined-stream@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" + dependencies: + delayed-stream "~1.0.0" + +core-util-is@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" + +data-uri-to-buffer@0: + version "0.0.4" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-0.0.4.tgz#46e13ab9da8e309745c8d01ce547213ebdb2fe3f" + +debug@2, debug@~2.6.0: + version "2.6.8" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc" + dependencies: + ms "2.0.0" + +deep-is@~0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + +degenerator@~1.0.2: + version "1.0.4" + resolved "https://registry.yarnpkg.com/degenerator/-/degenerator-1.0.4.tgz#fcf490a37ece266464d9cc431ab98c5819ced095" + dependencies: + ast-types "0.x.x" + escodegen "1.x.x" + esprima "3.x.x" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + +escodegen@1.x.x: + version "1.8.1" + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018" + dependencies: + esprima "^2.7.1" + estraverse "^1.9.1" + esutils "^2.0.2" + optionator "^0.8.1" + optionalDependencies: + source-map "~0.2.0" + +esprima@3.x.x: + version "3.1.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" + +esprima@^2.7.1: + version "2.7.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" + +estraverse@^1.9.1: + version "1.9.3" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44" + +esutils@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + +extend@3, extend@~3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444" + +fast-levenshtein@~2.0.4: + version "2.0.6" + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + +file-uri-to-path@0: + version "0.0.2" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-0.0.2.tgz#37cdd1b5b905404b3f05e1b23645be694ff70f82" + +form-data@~2.1.1: + version "2.1.4" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1" + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.5" + mime-types "^2.1.12" + +ftp@~0.3.5: + version "0.3.10" + resolved "https://registry.yarnpkg.com/ftp/-/ftp-0.3.10.tgz#9197d861ad8142f3e63d5a83bfe4c59f7330885d" + dependencies: + readable-stream "1.1.x" + xregexp "2.0.0" + +get-uri@2: + version "2.0.0" + resolved "https://registry.yarnpkg.com/get-uri/-/get-uri-2.0.0.tgz#713e47cbcbaeab38f88af1cdfc85fa7f09b00738" + dependencies: + data-uri-to-buffer "0" + debug "2" + extend "3" + file-uri-to-path "0" + ftp "~0.3.5" + readable-stream "2" + +http-proxy-agent@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-1.0.0.tgz#cc1ce38e453bf984a0f7702d2dd59c73d081284a" + dependencies: + agent-base "2" + debug "2" + extend "3" + +https-proxy-agent@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-1.0.0.tgz#35f7da6c48ce4ddbfa264891ac593ee5ff8671e6" + dependencies: + agent-base "2" + debug "2" + extend "3" + +iconv-lite@0.4.15: + version "0.4.15" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.15.tgz#fe265a218ac6a57cfe854927e9d04c19825eddeb" + +inflection@~1.12.0: + version "1.12.0" + resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.12.0.tgz#a200935656d6f5f6bc4dc7502e1aecb703228416" + +inflection@~1.3.0: + version "1.3.8" + resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.3.8.tgz#cbd160da9f75b14c3cc63578d4f396784bf3014e" + +inherits@~2.0.1, inherits@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +ip@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/ip/-/ip-1.0.1.tgz#c7e356cdea225ae71b36d70f2e71a92ba4e42590" + +ip@^1.1.4: + version "1.1.5" + resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a" + +is-stream@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" + +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + +isarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + +levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + +lodash@^4.14.0, lodash@^4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + +lru-cache@~2.6.5: + version "2.6.5" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.6.5.tgz#e56d6354148ede8d7707b58d143220fd08df0fd5" + +mailgun-js@^0.11.2: + version "0.11.2" + resolved "https://registry.yarnpkg.com/mailgun-js/-/mailgun-js-0.11.2.tgz#e88da86d52ab8810f07a8eb09bde84ec8b7cfa29" + dependencies: + async "~2.4.0" + debug "~2.6.0" + form-data "~2.1.1" + inflection "~1.12.0" + is-stream "^1.1.0" + path-proxy "~1.0.0" + promisify-call "^2.0.2" + proxy-agent "~2.0.0" + tsscmp "~1.0.0" + +mime-db@~1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.27.0.tgz#820f572296bbd20ec25ed55e5b5de869e5436eb1" + +mime-types@^2.1.12: + version "2.1.15" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.15.tgz#a4ebf5064094569237b8cf70046776d09fc92aed" + dependencies: + mime-db "~1.27.0" + +moment@^2.18.1: + version "2.18.1" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f" + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +netmask@~1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35" + +optionator@^0.8.1: + version "0.8.2" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.4" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + wordwrap "~1.0.0" + +pac-proxy-agent@1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/pac-proxy-agent/-/pac-proxy-agent-1.1.0.tgz#34a385dfdf61d2f0ecace08858c745d3e791fd4d" + dependencies: + agent-base "2" + debug "2" + extend "3" + get-uri "2" + http-proxy-agent "1" + https-proxy-agent "1" + pac-resolver "~2.0.0" + raw-body "2" + socks-proxy-agent "2" + +pac-resolver@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/pac-resolver/-/pac-resolver-2.0.0.tgz#99b88d2f193fbdeefc1c9a529c1f3260ab5277cd" + dependencies: + co "~3.0.6" + degenerator "~1.0.2" + ip "1.0.1" + netmask "~1.0.4" + thunkify "~2.1.1" + +path-proxy@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/path-proxy/-/path-proxy-1.0.0.tgz#18e8a36859fc9d2f1a53b48dee138543c020de5e" + dependencies: + inflection "~1.3.0" + +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + +process-nextick-args@~1.0.6: + version "1.0.7" + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" + +promisify-call@^2.0.2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/promisify-call/-/promisify-call-2.0.4.tgz#d48c2d45652ccccd52801ddecbd533a6d4bd5fba" + dependencies: + with-callback "^1.0.2" + +proxy-agent@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-2.0.0.tgz#57eb5347aa805d74ec681cb25649dba39c933499" + dependencies: + agent-base "2" + debug "2" + extend "3" + http-proxy-agent "1" + https-proxy-agent "1" + lru-cache "~2.6.5" + pac-proxy-agent "1" + socks-proxy-agent "2" + +raw-body@2: + version "2.2.0" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.2.0.tgz#994976cf6a5096a41162840492f0bdc5d6e7fb96" + dependencies: + bytes "2.4.0" + iconv-lite "0.4.15" + unpipe "1.0.0" + +readable-stream@1.1.x: + version "1.1.14" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +readable-stream@2: + version "2.3.3" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.3" + isarray "~1.0.0" + process-nextick-args "~1.0.6" + safe-buffer "~5.1.1" + string_decoder "~1.0.3" + util-deprecate "~1.0.1" + +safe-buffer@~5.1.0, safe-buffer@~5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" + +semver@~5.0.1: + version "5.0.3" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.0.3.tgz#77466de589cd5d3c95f138aa78bc569a3cb5d27a" + +smart-buffer@^1.0.13: + version "1.1.15" + resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-1.1.15.tgz#7f114b5b65fab3e2a35aa775bb12f0d1c649bf16" + +socks-proxy-agent@2: + version "2.1.1" + resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-2.1.1.tgz#86ebb07193258637870e13b7bd99f26c663df3d3" + dependencies: + agent-base "2" + extend "3" + socks "~1.1.5" + +socks@~1.1.5: + version "1.1.10" + resolved "https://registry.yarnpkg.com/socks/-/socks-1.1.10.tgz#5b8b7fc7c8f341c53ed056e929b7bf4de8ba7b5a" + dependencies: + ip "^1.1.4" + smart-buffer "^1.0.13" + +source-map@~0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d" + dependencies: + amdefine ">=0.0.4" + +string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + +string_decoder@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab" + dependencies: + safe-buffer "~5.1.0" + +thunkify@~2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/thunkify/-/thunkify-2.1.2.tgz#faa0e9d230c51acc95ca13a361ac05ca7e04553d" + +tsscmp@~1.0.0: + version "1.0.5" + resolved "https://registry.yarnpkg.com/tsscmp/-/tsscmp-1.0.5.tgz#7dc4a33af71581ab4337da91d85ca5427ebd9a97" + +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + dependencies: + prelude-ls "~1.1.2" + +unpipe@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + +util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + +with-callback@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/with-callback/-/with-callback-1.0.2.tgz#a09629b9a920028d721404fb435bdcff5c91bc21" + +"wmg-common@file:../../common": + version "0.0.2" + +wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + +xregexp@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-2.0.0.tgz#52a63e56ca0b84a7f3a5f3d61872f126ad7a5943" diff --git a/lambda/wmg-email/.yarnclean b/lambda/wmg-email/.yarnclean new file mode 100644 index 0000000..25bdd14 --- /dev/null +++ b/lambda/wmg-email/.yarnclean @@ -0,0 +1,42 @@ +# test directories +__tests__ +test +tests +powered-test + +# asset directories +docs +doc +website +images +assets + +# examples +example +examples + +# code coverage directories +coverage +.nyc_output + +# build scripts +Makefile +Gulpfile.js +Gruntfile.js + +# configs +.tern-project +.gitattributes +.editorconfig +.*ignore +.eslintrc +.jshintrc +.flowconfig +.documentup.json +.yarn-metadata.json +.*.yml +*.yml + +# misc +*.gz +*.md diff --git a/lambda/wmg-email/Doctor.html b/lambda/wmg-email/Doctor.html index 240a569..f612edf 100644 --- a/lambda/wmg-email/Doctor.html +++ b/lambda/wmg-email/Doctor.html @@ -3,36 +3,56 @@ Hi,

- You're receiving this email because {{details.name_of_parent}} completed the Watch Me Grow app for CHILD’S NAME. The Watch - Me Grow app tracks developmental progress for children aged between approximately 12 to 24 months. It has been designed - to facilitate early identification of developmental problems. + You're receiving this email because {{details.name_of_parent}} completed the Watch Me Grow app for {{details.first_name_of_child}}. + {{details.last_name_of_child}}. The Watch Me Grow app tracks developmental progress for children aged between approximately + 12 to 24 months. It has been designed to facilitate early identification of developmental problems.

+{{if concern}} +
+ +
+

+ + It is highly likely that this child has developmental issues. It is strongly recommended that referral for further assessment + and early intervention through a paediatrician or other child development health professional is done. Also continue to monitor + the child over time. + +

+{{else}} +
+ +
+

+ + Developmental issues in this child are unlikely. No further follow-up necessary at this point. Continue ongoing monitoring + as usual. + +

+{{/if}} + - + - + - +
Child's Name{{details.first_name_of_child}} {{{{details.last_name_of_child}}{{details.first_name_of_child}} {{details.last_name_of_child}} Date of Test{{details.test_date}}{{details.test_date_formatted}}
Date of Birth{{details.dob_child}}{{details.dob_child_formatted}} Age of Child {{details.age_of_child}}
-

{{resultText}}

-

Detailed Results Below

- {{allResults}}

{{questionnaire.title}}

- +
- - - + + + {{results}} @@ -47,12 +67,13 @@

{{questionnaire.title}}

{{/if}} {{/results}}
NumberQuestionYour ResponseNumberQuestionResponse
-
{{/allResults}} +
+{{/allResults}}

- All children grow and develop at their own pace. Please follow this link for more information: Learn the signs - act early. + For further information on child development please go to Learn the signs - act early.

- This was sent because you completed a questionnaire for the Watch Me Grow pilot. -

+ This information has also been provided to the parent. +

\ No newline at end of file diff --git a/lambda/wmg-email/Reminder.html b/lambda/wmg-email/Reminder.html new file mode 100644 index 0000000..182164b --- /dev/null +++ b/lambda/wmg-email/Reminder.html @@ -0,0 +1,4 @@ +Thank you for previously completing the Watch Me Grow app. It is recommended that you complete this when your child is aged +approximately 12, 18 and 24 months. This is a reminder to complete the Watch Me Grow app for your child again. As before, +these results will be sent via email. These can also be sent to your nominated health professional. Please go to the +Watch Me Grow app. \ No newline at end of file diff --git a/lambda/wmg-email/Results.html b/lambda/wmg-email/Results.html index 578b708..16ac1ab 100644 --- a/lambda/wmg-email/Results.html +++ b/lambda/wmg-email/Results.html @@ -11,11 +11,11 @@ Child's Name {{details.first_name_of_child}} {{details.last_name_of_child}} Date of Test - {{details.test_date}} + {{details.test_date_formatted}} Date of Birth - {{details.dob_child}} + {{details.dob_child_formatted}} Age of Child {{details.age_of_child}} @@ -26,11 +26,11 @@ {{allResults}}

{{questionnaire.title}}

- +
- - - + + + {{results}} @@ -45,7 +45,8 @@

{{questionnaire.title}}

{{/if}} {{/results}}
NumberQuestionYour ResponseNumberQuestionResponse
-
{{/allResults}} +
+{{/allResults}}

All children grow and develop at their own pace. Please follow this link for more information: Learn the signs - act early. diff --git a/lambda/wmg-email/index.js b/lambda/wmg-email/index.js index 75e2aee..dd5d5d0 100644 --- a/lambda/wmg-email/index.js +++ b/lambda/wmg-email/index.js @@ -3,7 +3,7 @@ let https = require("https"); var aws = require("aws-sdk"); const moment = require("moment"); -var ses = new aws.SES(); +const mailgunJs = require("mailgun-js"); var markupJs = require("markup-js"); var fs = require("fs"); const fetch = require("isomorphic-fetch"); @@ -11,6 +11,15 @@ var dataFunctions = require("wmg-common/data-functions"); var mark = dataFunctions.mark; var combineAll = dataFunctions.combineAll; var strings = require("wmg-common/strings"); +var questionnaires = require("wmg-common/questionnaires"); +const _ = require("lodash"); + +const FORMAT = "dddd, MMMM Do YYYY"; + +const mailgun = mailgunJs({ + apiKey: process.env.MAILGUN_API_KEY, + domain: "auto.watchmegrow.care" +}); process.env["PATH"] = process.env["PATH"] + ":" + process.env["LAMBDA_TASK_ROOT"]; @@ -26,7 +35,7 @@ console.log("Loading function"); } */ -exports.handler = function(event, context) { +exports.handler = function(event, context, callback) { console.log("Event: " + JSON.stringify(event)); if (!event.details.recipient_email) { @@ -40,17 +49,36 @@ exports.handler = function(event, context) { ? strings.result.concerns : strings.result.noConcerns; - const parentEmailPromise = sendParentEmail(event, concern, combinedResults, resultStrings); - const zapierPromise = sendToZapier(event, concern); - const basePromises = [parentEmailPromise, zapierPromise]; + event.details = Object.assign(event.details, { + test_date_formatted: moment(event.details.test_date).format(FORMAT), + dob_child_formatted: moment(event.details.dob_child).format(FORMAT) + }); + + const parentEmailPromise = sendParentEmail( + //Promise.resolve(); + event, + concern, + combinedResults, + resultStrings + ); + const zapierPromise = sendToZapier(event, concern); //Promise.resolve(); + const basePromises = [ + parentEmailPromise, + zapierPromise, + addToReminderList(event) + ]; const promises = event.details.doctor_email - ? basePromises.concat([sendDoctorEmail(event, concern, combinedResults, resultStrings)]) + ? basePromises.concat([ + sendDoctorEmail(event, concern, combinedResults, resultStrings) + ]) : basePromises; Promise.all(promises) - .then(context.succeed("Successfully executed")) - .catch(e => context.fail("Internal Error: " + e.message)); + .then(result => { + callback(null, result); + }) + .catch(e => callback(e)); }; function sendToZapier(event, concern) { @@ -60,7 +88,7 @@ function sendToZapier(event, concern) { results: event.results, concern: concern, details: Object.assign(event.details, { - ageInDays: moment().diff(moment(event.details.dob_child), 'days') + ageInDays: moment().diff(moment(event.details.dob_child), "days") }) }), headers: { @@ -69,9 +97,9 @@ function sendToZapier(event, concern) { }); } -function sendParentEmail(event, concern, combinedResults, resultStrings) { - const templateBody = fs.readFileSync(__dirname + "/Results.html", "utf-8"); +const templateBody = fs.readFileSync(__dirname + "/Results.html", "utf-8"); +function sendParentEmail(event, concern, combinedResults, resultStrings) { var message = markupJs.up(templateBody, { details: event.details, concern: concern, @@ -80,40 +108,19 @@ function sendParentEmail(event, concern, combinedResults, resultStrings) { }); var params = { - Destination: { - ToAddresses: [event.details.recipient_email], - CcAddresses: ["mail@watchmegrow.care"] - }, - Message: { - Body: { - Html: { - Data: message, - Charset: "UTF-8" - } - }, - Subject: { - Data: "Watch Me Grow Results for " + event.details.first_name_of_child, - Charset: "UTF-8" - } - }, - Source: "mail@watchmegrow.care" //hardcoded verified email source for Amazon SES sandbox + from: "mail@watchmegrow.care", + to: event.details.recipient_email, + cc: "mail@watchmegrow.care", + subject: "Watch Me Grow Results for " + event.details.first_name_of_child, + html: message }; - return new Promise((accept, reject) => - ses.sendEmail(params, function(err, data) { - if (err) { - console.log(err, err.stack); - reject(err); - } else { - accept(data); - } - }) - ); + return mailgun.messages().send(params); } -function sendDoctorEmail(event, concern, combinedResults, resultStrings) { - const doctorTemplateBody = fs.readFileSync(__dirname + "/Doctor.html", "utf-8"); +const doctorTemplateBody = fs.readFileSync(__dirname + "/Doctor.html", "utf-8"); +function sendDoctorEmail(event, concern, combinedResults, resultStrings) { var message = markupJs.up(doctorTemplateBody, { details: event.details, concern: concern, @@ -122,37 +129,54 @@ function sendDoctorEmail(event, concern, combinedResults, resultStrings) { }); var params = { - Destination: { - ToAddresses: [event.details.doctor_email], - CcAddresses: ["mail@watchmegrow.care"] - }, - Message: { - Body: { - Html: { - Data: message, - Charset: "UTF-8" - } - }, - Subject: { - Data: - "Watch Me Grow Results for " + - event.details.first_name_of_child + - " " + - event.details.last_name_of_child, - Charset: "UTF-8" - } - }, - Source: "mail@watchmegrow.care" //hardcoded verified email source for Amazon SES sandbox + from: "mail@watchmegrow.care", + to: event.details.doctor_email, + subject: + "Watch Me Grow Results for " + + event.details.first_name_of_child + + " " + + event.details.last_name_of_child, + html: message + }; + + return mailgun.messages().send(params); +} + +const reminderTemplateBody = fs.readFileSync( + __dirname + "/Reminder.html", + "utf-8" +); + +function addToReminderList(event) { + const completed = Object.keys(event.results).reduce((soFar, current) => { + soFar[current] = true; + return soFar; + }, {}); + + const data = { + completed, + dob: event.details.dob_child }; - return new Promise((accept, reject) => - ses.sendEmail(params, function(err, data) { - if (err) { - console.log(err, err.stack); - reject(err); - } else { - accept(data); - } + const newVars = {}; + newVars[event.details.first_name_of_child] = data; + + const varsPromise = mailgun + .lists("reminders@auto.watchmegrow.care") + .members(event.details.recipient_email) + .info() + .then(memberObj => { + const member = memberObj.member; + return Promise.resolve(member && member.vars ? member.vars : {}); }) - ); + .catch(e => Promise.resolve({})); + + return varsPromise.then(vars => { + return mailgun.lists("reminders@auto.watchmegrow.care").members().create({ + name: event.details.name_of_parent, + address: event.details.recipient_email, + upsert: "true", + vars: _.merge(vars, newVars) + }); + }); } diff --git a/lambda/wmg-email/package.json b/lambda/wmg-email/package.json index 261c619..8292b2e 100644 --- a/lambda/wmg-email/package.json +++ b/lambda/wmg-email/package.json @@ -3,6 +3,8 @@ "version": "0.0.1", "dependencies": { "isomorphic-fetch": "^2.2.1", + "lodash": "^4.17.4", + "mailgun-js": "^0.11.2", "markup-js": "^1.5.21", "moment": "^2.18.1", "wmg-common": "file:../../common" diff --git a/lambda/wmg-email/yarn.lock b/lambda/wmg-email/yarn.lock index 549bd4e..a3718a6 100644 --- a/lambda/wmg-email/yarn.lock +++ b/lambda/wmg-email/yarn.lock @@ -2,20 +2,202 @@ # yarn lockfile v1 +agent-base@2: + version "2.1.1" + resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-2.1.1.tgz#d6de10d5af6132d5bd692427d46fc538539094c7" + dependencies: + extend "~3.0.0" + semver "~5.0.1" + +amdefine@>=0.0.4: + version "1.0.1" + resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" + +ast-types@0.x.x: + version "0.9.12" + resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.12.tgz#b136300d67026625ae15326982ca9918e5db73c9" + +async@~2.4.0: + version "2.4.1" + resolved "https://registry.yarnpkg.com/async/-/async-2.4.1.tgz#62a56b279c98a11d0987096a01cc3eeb8eb7bbd7" + dependencies: + lodash "^4.14.0" + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + +bytes@2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/bytes/-/bytes-2.4.0.tgz#7d97196f9d5baf7f6935e25985549edd2a6c2339" + +co@~3.0.6: + version "3.0.6" + resolved "https://registry.yarnpkg.com/co/-/co-3.0.6.tgz#1445f226c5eb956138e68c9ac30167ea7d2e6bda" + +combined-stream@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" + dependencies: + delayed-stream "~1.0.0" + +core-util-is@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" + +data-uri-to-buffer@0: + version "0.0.4" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-0.0.4.tgz#46e13ab9da8e309745c8d01ce547213ebdb2fe3f" + +debug@2, debug@~2.6.0: + version "2.6.8" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.8.tgz#e731531ca2ede27d188222427da17821d68ff4fc" + dependencies: + ms "2.0.0" + +deep-is@~0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + +degenerator@~1.0.2: + version "1.0.4" + resolved "https://registry.yarnpkg.com/degenerator/-/degenerator-1.0.4.tgz#fcf490a37ece266464d9cc431ab98c5819ced095" + dependencies: + ast-types "0.x.x" + escodegen "1.x.x" + esprima "3.x.x" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + encoding@^0.1.11: version "0.1.12" resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb" dependencies: iconv-lite "~0.4.13" +escodegen@1.x.x: + version "1.8.1" + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018" + dependencies: + esprima "^2.7.1" + estraverse "^1.9.1" + esutils "^2.0.2" + optionator "^0.8.1" + optionalDependencies: + source-map "~0.2.0" + +esprima@3.x.x: + version "3.1.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" + +esprima@^2.7.1: + version "2.7.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" + +estraverse@^1.9.1: + version "1.9.3" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44" + +esutils@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + +extend@3, extend@~3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444" + +fast-levenshtein@~2.0.4: + version "2.0.6" + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + +file-uri-to-path@0: + version "0.0.2" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-0.0.2.tgz#37cdd1b5b905404b3f05e1b23645be694ff70f82" + +form-data@~2.1.1: + version "2.1.4" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1" + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.5" + mime-types "^2.1.12" + +ftp@~0.3.5: + version "0.3.10" + resolved "https://registry.yarnpkg.com/ftp/-/ftp-0.3.10.tgz#9197d861ad8142f3e63d5a83bfe4c59f7330885d" + dependencies: + readable-stream "1.1.x" + xregexp "2.0.0" + +get-uri@2: + version "2.0.0" + resolved "https://registry.yarnpkg.com/get-uri/-/get-uri-2.0.0.tgz#713e47cbcbaeab38f88af1cdfc85fa7f09b00738" + dependencies: + data-uri-to-buffer "0" + debug "2" + extend "3" + file-uri-to-path "0" + ftp "~0.3.5" + readable-stream "2" + +http-proxy-agent@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-1.0.0.tgz#cc1ce38e453bf984a0f7702d2dd59c73d081284a" + dependencies: + agent-base "2" + debug "2" + extend "3" + +https-proxy-agent@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-1.0.0.tgz#35f7da6c48ce4ddbfa264891ac593ee5ff8671e6" + dependencies: + agent-base "2" + debug "2" + extend "3" + +iconv-lite@0.4.15: + version "0.4.15" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.15.tgz#fe265a218ac6a57cfe854927e9d04c19825eddeb" + iconv-lite@~0.4.13: version "0.4.18" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2" -is-stream@^1.0.1: +inflection@~1.12.0: + version "1.12.0" + resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.12.0.tgz#a200935656d6f5f6bc4dc7502e1aecb703228416" + +inflection@~1.3.0: + version "1.3.8" + resolved "https://registry.yarnpkg.com/inflection/-/inflection-1.3.8.tgz#cbd160da9f75b14c3cc63578d4f396784bf3014e" + +inherits@~2.0.1, inherits@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +ip@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/ip/-/ip-1.0.1.tgz#c7e356cdea225ae71b36d70f2e71a92ba4e42590" + +ip@^1.1.4: + version "1.1.5" + resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.5.tgz#bdded70114290828c0a039e72ef25f5aaec4354a" + +is-stream@^1.0.1, is-stream@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" +isarray@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf" + +isarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + isomorphic-fetch@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9" @@ -23,14 +205,61 @@ isomorphic-fetch@^2.2.1: node-fetch "^1.0.1" whatwg-fetch ">=0.10.0" +levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + +lodash@^4.14.0, lodash@^4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + +lru-cache@~2.6.5: + version "2.6.5" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-2.6.5.tgz#e56d6354148ede8d7707b58d143220fd08df0fd5" + +mailgun-js@^0.11.2: + version "0.11.2" + resolved "https://registry.yarnpkg.com/mailgun-js/-/mailgun-js-0.11.2.tgz#e88da86d52ab8810f07a8eb09bde84ec8b7cfa29" + dependencies: + async "~2.4.0" + debug "~2.6.0" + form-data "~2.1.1" + inflection "~1.12.0" + is-stream "^1.1.0" + path-proxy "~1.0.0" + promisify-call "^2.0.2" + proxy-agent "~2.0.0" + tsscmp "~1.0.0" + markup-js@^1.5.21: version "1.5.21" resolved "https://registry.yarnpkg.com/markup-js/-/markup-js-1.5.21.tgz#389128703a565964574d0e357e142add3be46d79" +mime-db@~1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.27.0.tgz#820f572296bbd20ec25ed55e5b5de869e5436eb1" + +mime-types@^2.1.12: + version "2.1.15" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.15.tgz#a4ebf5064094569237b8cf70046776d09fc92aed" + dependencies: + mime-db "~1.27.0" + moment@^2.18.1: version "2.18.1" resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.1.tgz#c36193dd3ce1c2eed2adb7c802dbbc77a81b1c0f" +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +netmask@~1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/netmask/-/netmask-1.0.6.tgz#20297e89d86f6f6400f250d9f4f6b4c1945fcd35" + node-fetch@^1.0.1: version "1.7.1" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5" @@ -38,9 +267,183 @@ node-fetch@^1.0.1: encoding "^0.1.11" is-stream "^1.0.1" +optionator@^0.8.1: + version "0.8.2" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.4" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + wordwrap "~1.0.0" + +pac-proxy-agent@1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/pac-proxy-agent/-/pac-proxy-agent-1.1.0.tgz#34a385dfdf61d2f0ecace08858c745d3e791fd4d" + dependencies: + agent-base "2" + debug "2" + extend "3" + get-uri "2" + http-proxy-agent "1" + https-proxy-agent "1" + pac-resolver "~2.0.0" + raw-body "2" + socks-proxy-agent "2" + +pac-resolver@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/pac-resolver/-/pac-resolver-2.0.0.tgz#99b88d2f193fbdeefc1c9a529c1f3260ab5277cd" + dependencies: + co "~3.0.6" + degenerator "~1.0.2" + ip "1.0.1" + netmask "~1.0.4" + thunkify "~2.1.1" + +path-proxy@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/path-proxy/-/path-proxy-1.0.0.tgz#18e8a36859fc9d2f1a53b48dee138543c020de5e" + dependencies: + inflection "~1.3.0" + +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + +process-nextick-args@~1.0.6: + version "1.0.7" + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" + +promisify-call@^2.0.2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/promisify-call/-/promisify-call-2.0.4.tgz#d48c2d45652ccccd52801ddecbd533a6d4bd5fba" + dependencies: + with-callback "^1.0.2" + +proxy-agent@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-2.0.0.tgz#57eb5347aa805d74ec681cb25649dba39c933499" + dependencies: + agent-base "2" + debug "2" + extend "3" + http-proxy-agent "1" + https-proxy-agent "1" + lru-cache "~2.6.5" + pac-proxy-agent "1" + socks-proxy-agent "2" + +raw-body@2: + version "2.2.0" + resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.2.0.tgz#994976cf6a5096a41162840492f0bdc5d6e7fb96" + dependencies: + bytes "2.4.0" + iconv-lite "0.4.15" + unpipe "1.0.0" + +readable-stream@1.1.x: + version "1.1.14" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + +readable-stream@2: + version "2.3.3" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.3" + isarray "~1.0.0" + process-nextick-args "~1.0.6" + safe-buffer "~5.1.1" + string_decoder "~1.0.3" + util-deprecate "~1.0.1" + +safe-buffer@~5.1.0, safe-buffer@~5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" + +semver@~5.0.1: + version "5.0.3" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.0.3.tgz#77466de589cd5d3c95f138aa78bc569a3cb5d27a" + +smart-buffer@^1.0.13: + version "1.1.15" + resolved "https://registry.yarnpkg.com/smart-buffer/-/smart-buffer-1.1.15.tgz#7f114b5b65fab3e2a35aa775bb12f0d1c649bf16" + +socks-proxy-agent@2: + version "2.1.1" + resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-2.1.1.tgz#86ebb07193258637870e13b7bd99f26c663df3d3" + dependencies: + agent-base "2" + extend "3" + socks "~1.1.5" + +socks@~1.1.5: + version "1.1.10" + resolved "https://registry.yarnpkg.com/socks/-/socks-1.1.10.tgz#5b8b7fc7c8f341c53ed056e929b7bf4de8ba7b5a" + dependencies: + ip "^1.1.4" + smart-buffer "^1.0.13" + +source-map@~0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.2.0.tgz#dab73fbcfc2ba819b4de03bd6f6eaa48164b3f9d" + dependencies: + amdefine ">=0.0.4" + +string_decoder@~0.10.x: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + +string_decoder@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab" + dependencies: + safe-buffer "~5.1.0" + +thunkify@~2.1.1: + version "2.1.2" + resolved "https://registry.yarnpkg.com/thunkify/-/thunkify-2.1.2.tgz#faa0e9d230c51acc95ca13a361ac05ca7e04553d" + +tsscmp@~1.0.0: + version "1.0.5" + resolved "https://registry.yarnpkg.com/tsscmp/-/tsscmp-1.0.5.tgz#7dc4a33af71581ab4337da91d85ca5427ebd9a97" + +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + dependencies: + prelude-ls "~1.1.2" + +unpipe@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec" + +util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + whatwg-fetch@>=0.10.0: version "2.0.3" resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84" +with-callback@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/with-callback/-/with-callback-1.0.2.tgz#a09629b9a920028d721404fb435bdcff5c91bc21" + "wmg-common@file:../../common": version "0.0.2" + +wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + +xregexp@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-2.0.0.tgz#52a63e56ca0b84a7f3a5f3d61872f126ad7a5943" diff --git a/src/components/pages/result/result.js b/src/components/pages/result/result.js index cd34e6c..5764570 100644 --- a/src/components/pages/result/result.js +++ b/src/components/pages/result/result.js @@ -31,7 +31,7 @@ const Result = React.createClass({ eventAction: this.props.results.concern ? "concern" : "no-concern" }); - sendResults(this.props.details, this.props.results); + // sendResults(this.props.details, this.props.results); }, getInitialStage() { diff --git a/src/send-results.js b/src/send-results.js index a77aa91..02cff0c 100644 --- a/src/send-results.js +++ b/src/send-results.js @@ -4,19 +4,17 @@ import strings from "../common/strings"; import questionnaires from "wmg-common/questionnaires"; import { combineQuestionsAndAnswers } from "wmg-common/data-functions"; -const FORMAT = "dddd, MMMM Do YYYY"; - export default function sendResults(details, results) { const ageInMonths = moment().diff(details.babyDob, "months"); const metadata = { recipient_email: details.parentEmail, - test_date: moment().format(FORMAT), + test_date: moment().toISOString, name_of_parent: details.parentName, first_name_of_child: details.babyFirstName, last_name_of_child: details.babyLastName, gender_of_child: details.babyGender, - dob_child: details.babyDob.format(FORMAT), + dob_child: details.babyDob.toISOString(), doctor_email: details.doctorEmail, age_of_child: ageInMonths < 24 ? ageInMonths + " months"