From 0878336f445e0431a0825b936c78317a199c0e6e Mon Sep 17 00:00:00 2001 From: Tom Wier Date: Thu, 18 Jun 2026 15:43:58 +0300 Subject: [PATCH 1/3] feat(#10748): remove docs_by_lineage view --- .../services/lineage-model-generator.spec.js | 99 +++++---- config/default/app_settings.json | 4 +- .../views/docs_by_id_lineage/map.js | 20 -- .../cht-datasource/src/local/libs/lineage.ts | 33 ++- .../test/local/libs/doc.spec.ts | 12 +- .../test/local/libs/lineage.spec.ts | 22 +- shared-libs/lineage/src/hydration.js | 27 ++- shared-libs/lineage/test/hydration.spec.js | 19 +- tests/integration/api/server.spec.js | 9 +- .../lineage-model-generator.service.spec.ts | 124 +++++------ .../unit/views/docs_by_id_lineage.spec.js | 198 ------------------ 11 files changed, 209 insertions(+), 358 deletions(-) delete mode 100644 ddocs/medic-db/medic-client/views/docs_by_id_lineage/map.js delete mode 100644 webapp/tests/mocha/unit/views/docs_by_id_lineage.spec.js diff --git a/admin/tests/unit/services/lineage-model-generator.spec.js b/admin/tests/unit/services/lineage-model-generator.spec.js index dd308a15294..fd1178822a6 100644 --- a/admin/tests/unit/services/lineage-model-generator.spec.js +++ b/admin/tests/unit/services/lineage-model-generator.spec.js @@ -5,14 +5,16 @@ describe('LineageModelGenerator service', () => { let service; let dbQuery; let dbAllDocs; + let dbGet; beforeEach(() => { module('adminApp'); module($provide => { dbQuery = sinon.stub(); dbAllDocs = sinon.stub(); + dbGet = sinon.stub(); $provide.value('$q', Q); // bypass $q so we don't have to digest - $provide.factory('DB', KarmaUtils.mockDB({ query: dbQuery, allDocs: dbAllDocs })); + $provide.factory('DB', KarmaUtils.mockDB({ query: dbQuery, allDocs: dbAllDocs, get: dbGet })); }); inject(_LineageModelGenerator_ => service = _LineageModelGenerator_); }); @@ -20,7 +22,7 @@ describe('LineageModelGenerator service', () => { describe('contact', () => { it('handles not found', done => { - dbQuery.returns(Promise.resolve({ rows: [] })); + dbGet.returns(Promise.reject({ status: 404 })); service.contact('a') .then(() => { done(new Error('expected error to be thrown')); @@ -34,9 +36,7 @@ describe('LineageModelGenerator service', () => { it('handles no lineage', () => { const contact = { _id: 'a', _rev: '1' }; - dbQuery.returns(Promise.resolve({ rows: [ - { doc: contact } - ] })); + dbGet.returns(Promise.resolve(contact)); return service.contact('a').then(model => { chai.expect(model._id).to.equal('a'); chai.expect(model.doc).to.deep.equal(contact); @@ -44,22 +44,21 @@ describe('LineageModelGenerator service', () => { }); it('binds lineage', () => { - const contact = { _id: 'a', _rev: '1' }; - const parent = { _id: 'b', _rev: '1' }; + const contact = { _id: 'a', _rev: '1', parent: { _id: 'b', parent: { _id: 'c' } } }; + const parent = { _id: 'b', _rev: '1', parent: { _id: 'c' } }; const grandparent = { _id: 'c', _rev: '1' }; - dbQuery.returns(Promise.resolve({ rows: [ - { doc: contact }, + dbGet.withArgs('a').returns(Promise.resolve(contact)); + dbAllDocs.withArgs(sinon.match({ + keys: sinon.match.array.deepEquals(['b', 'c']), + include_docs: true + })).returns(Promise.resolve({ rows: [ { doc: parent }, { doc: grandparent } ] })); return service.contact('a').then(model => { - chai.expect(dbQuery.callCount).to.equal(1); - chai.expect(dbQuery.args[0][0]).to.equal('medic-client/docs_by_id_lineage'); - chai.expect(dbQuery.args[0][1]).to.deep.equal({ - startkey: [ 'a' ], - endkey: [ 'a', {} ], - include_docs: true - }); + chai.expect(dbGet.callCount).to.equal(1); + chai.expect(dbAllDocs.callCount).to.equal(1); + chai.expect(dbAllDocs.args[0][0].keys).to.deep.equal(['b', 'c']); chai.expect(model._id).to.equal('a'); chai.expect(model.doc).to.deep.equal(contact); chai.expect(model.lineage).to.deep.equal([ parent, grandparent ]); @@ -67,17 +66,23 @@ describe('LineageModelGenerator service', () => { }); it('binds contacts', () => { - const contact = { _id: 'a', _rev: '1', contact: { _id: 'd' } }; + const contact = { _id: 'a', _rev: '1', contact: { _id: 'd' }, parent: { _id: 'b', parent: { _id: 'c' } } }; const contactsContact = { _id: 'd', name: 'dave' }; - const parent = { _id: 'b', _rev: '1', contact: { _id: 'e' } }; + const parent = { _id: 'b', _rev: '1', contact: { _id: 'e' }, parent: { _id: 'c' } }; const parentsContact = { _id: 'e', name: 'eliza' }; const grandparent = { _id: 'c', _rev: '1' }; - dbQuery.returns(Promise.resolve({ rows: [ - { doc: contact }, + dbGet.returns(Promise.resolve(contact)); + dbAllDocs.withArgs(sinon.match({ + keys: sinon.match.array.deepEquals(['b', 'c']), + include_docs: true + })).returns(Promise.resolve({ rows: [ { doc: parent }, { doc: grandparent } ] })); - dbAllDocs.returns(Promise.resolve({ rows: [ + dbAllDocs.withArgs({ + keys: sinon.match.array.deepEquals(['d', 'e']), + include_docs: true + }).returns(Promise.resolve({ rows: [ { doc: contactsContact }, { doc: parentsContact } ] })); @@ -89,23 +94,35 @@ describe('LineageModelGenerator service', () => { }); it('hydrates lineage contacts - #3812', () => { - const contact = { _id: 'a', _rev: '1', contact: { _id: 'x' } }; - const parent = { _id: 'b', _rev: '1', contact: { _id: 'd' } }; + const contact = { _id: 'a', _rev: '1', contact: { _id: 'x' }, parent: { _id: 'b', parent: { _id: 'c' } } }; + const parent = { _id: 'b', _rev: '1', contact: { _id: 'd' }, parent: { _id: 'c' } }; const grandparent = { _id: 'c', _rev: '1', contact: { _id: 'e' } }; const parentContact = { _id: 'd', name: 'donny' }; const grandparentContact = { _id: 'e', name: 'erica' }; - dbQuery.returns(Promise.resolve({ rows: [ - { doc: contact }, + const xContact = { _id: 'x', name: 'xavier' }; + dbGet.returns(Promise.resolve(contact)); + dbAllDocs.withArgs(sinon.match({ + keys: sinon.match.array.deepEquals(['b', 'c']), + include_docs: true + })).returns(Promise.resolve({ rows: [ { doc: parent }, { doc: grandparent } ] })); - dbAllDocs.returns(Promise.resolve({ rows: [ + dbAllDocs.withArgs({ + keys: sinon.match.array.deepEquals(['x', 'd', 'e']), + include_docs: true + }).returns(Promise.resolve({ rows: [ + { doc: xContact }, { doc: parentContact }, { doc: grandparentContact } ] })); return service.contact('a').then(model => { - chai.expect(dbAllDocs.callCount).to.equal(1); + chai.expect(dbAllDocs.callCount).to.equal(2); chai.expect(dbAllDocs.args[0][0]).to.deep.equal({ + keys: [ 'b', 'c' ], + include_docs: true + }); + chai.expect(dbAllDocs.args[1][0]).to.deep.equal({ keys: [ 'x', 'd', 'e' ], include_docs: true }); @@ -116,7 +133,7 @@ describe('LineageModelGenerator service', () => { it('merges lineage when merge passed', () => { const contact = { _id: 'a', name: '1', parent: { _id: 'b', parent: { _id: 'c' } } }; - const parent = { _id: 'b', name: '2' }; + const parent = { _id: 'b', name: '2', parent: { _id: 'c' } }; const grandparent = { _id: 'c', name: '3' }; const expected = { _id: 'a', @@ -147,8 +164,11 @@ describe('LineageModelGenerator service', () => { } ] }; - dbQuery.returns(Promise.resolve({ rows: [ - { doc: contact }, + dbGet.returns(Promise.resolve(contact)); + dbAllDocs.withArgs(sinon.match({ + keys: sinon.match.array.deepEquals(['b', 'c']), + include_docs: true + })).returns(Promise.resolve({ rows: [ { doc: parent }, { doc: grandparent } ] })); @@ -160,8 +180,9 @@ describe('LineageModelGenerator service', () => { it('should merge lineage with undefined members', () => { const contact = { _id: 'a', name: '1', parent: { _id: 'b', parent: { _id: 'c', parent: { _id: 'd' } } } }; const parent = { _id: 'b', name: '2', parent: { _id: 'c', parent: { _id: 'd' } } }; - dbQuery.resolves({ rows: - [{ doc: contact, key: ['a', 0] }, { doc: parent, key: ['a', 1] }, { key: ['a', 2] }, { key: ['a', 3] }] + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: + [{ doc: parent, id: 'b' }, { id: 'c' }, { id: 'd' }] }); const expected = { _id: 'a', @@ -180,11 +201,11 @@ describe('LineageModelGenerator service', () => { it('should merge lineage with undefined members v2', () => { const contact = { _id: 'a', name: '1', parent: { _id: 'b', parent: { _id: 'c', parent: { _id: 'd' } } } }; const parent = { _id: 'b', name: '2', parent: { _id: 'c', parent: { _id: 'd' } } }; - dbQuery.resolves({ rows: [ - { doc: contact, key: ['a', 0] }, - { doc: parent, key: ['a', 1] }, - { key: ['a', 2] }, - { key: ['a', 3], doc: { _id: 'd', name: '4' } } + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: [ + { doc: parent, id: 'b' }, + { id: 'c' }, + { id: 'd', doc: { _id: 'd', name: '4' } } ] }); const expected = { _id: 'a', @@ -229,8 +250,8 @@ describe('LineageModelGenerator service', () => { } ] }; - dbQuery.returns(Promise.resolve({ rows: [ - { doc: contact }, + dbGet.returns(Promise.resolve(contact)); + dbAllDocs.returns(Promise.resolve({ rows: [ { doc: parent }, { doc: grandparent } ] })); diff --git a/config/default/app_settings.json b/config/default/app_settings.json index 1d91b088dbb..01117c717ed 100644 --- a/config/default/app_settings.json +++ b/config/default/app_settings.json @@ -365,9 +365,9 @@ "person": true } ], - "contact_summary": "var ContactSummary = {}; /*! For license information please see contact-summary.js.LICENSE.txt */\n!function(e,t){if('object'==typeof exports&&'object'==typeof module)module.exports=t();else if('function'==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)('object'==typeof exports?exports:e)[r]=n[r]}}(ContactSummary,(()=>(()=>{var e={344:(e,t,n)=>{var r=n(972),i=n(597);e.exports=i(r,contact,reports)},420:function(e,t,n){(e=n.nmd(e)).exports=function(){'use strict';var t,n;function r(){return t.apply(null,arguments)}function i(e){t=e}function s(e){return e instanceof Array||'[object Array]'===Object.prototype.toString.call(e)}function a(e){return null!=e&&'[object Object]'===Object.prototype.toString.call(e)}function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){if(Object.getOwnPropertyNames)return 0===Object.getOwnPropertyNames(e).length;var t;for(t in e)if(o(e,t))return!1;return!0}function u(e){return void 0===e}function d(e){return'number'==typeof e||'[object Number]'===Object.prototype.toString.call(e)}function c(e){return e instanceof Date||'[object Date]'===Object.prototype.toString.call(e)}function h(e,t){var n,r=[],i=e.length;for(n=0;n>>0;for(t=0;t0)for(n=0;n=0?n?'+':'':'-')+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}var U=/(\\[[^\\[]*\\])|(\\\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,H=/(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})/g,A={},E={};function L(e,t,n,r){var i=r;'string'==typeof r&&(i=function(){return this[r]()}),e&&(E[e]=i),t&&(E[t[0]]=function(){return F(i.apply(this,arguments),t[1],t[2])}),n&&(E[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function V(e){return e.match(/\\[[\\s\\S]/)?e.replace(/^\\[|\\]$/g,''):e.replace(/\\\\/g,'')}function I(e){var t,n,r=e.match(U);for(t=0,n=r.length;t=0&&H.test(e);)e=e.replace(H,r),H.lastIndex=0,n-=1;return e}var Z={LTS:'h:mm:ss A',LT:'h:mm A',L:'MM/DD/YYYY',LL:'MMMM D, YYYY',LLL:'MMMM D, YYYY h:mm A',LLLL:'dddd, MMMM D, YYYY h:mm A'};function z(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.match(U).map((function(e){return'MMMM'===e||'MM'===e||'DD'===e||'dddd'===e?e.slice(1):e})).join(''),this._longDateFormat[e])}var q='Invalid date';function $(){return this._invalidDate}var B='%d',J=/\\d{1,2}/;function Q(e){return this._ordinal.replace('%d',e)}var X={future:'in %s',past:'%s ago',s:'a few seconds',ss:'%d seconds',m:'a minute',mm:'%d minutes',h:'an hour',hh:'%d hours',d:'a day',dd:'%d days',w:'a week',ww:'%d weeks',M:'a month',MM:'%d months',y:'a year',yy:'%d years'};function K(e,t,n,r){var i=this._relativeTime[n];return x(i)?i(e,t,n,r):i.replace(/%d/i,e)}function ee(e,t){var n=this._relativeTime[e>0?'future':'past'];return x(n)?n(t):n.replace(/%s/i,t)}var te={D:'date',dates:'date',date:'date',d:'day',days:'day',day:'day',e:'weekday',weekdays:'weekday',weekday:'weekday',E:'isoWeekday',isoweekdays:'isoWeekday',isoweekday:'isoWeekday',DDD:'dayOfYear',dayofyears:'dayOfYear',dayofyear:'dayOfYear',h:'hour',hours:'hour',hour:'hour',ms:'millisecond',milliseconds:'millisecond',millisecond:'millisecond',m:'minute',minutes:'minute',minute:'minute',M:'month',months:'month',month:'month',Q:'quarter',quarters:'quarter',quarter:'quarter',s:'second',seconds:'second',second:'second',gg:'weekYear',weekyears:'weekYear',weekyear:'weekYear',GG:'isoWeekYear',isoweekyears:'isoWeekYear',isoweekyear:'isoWeekYear',w:'week',weeks:'week',week:'week',W:'isoWeek',isoweeks:'isoWeek',isoweek:'isoWeek',y:'year',years:'year',year:'year'};function ne(e){return'string'==typeof e?te[e]||te[e.toLowerCase()]:void 0}function re(e){var t,n,r={};for(n in e)o(e,n)&&(t=ne(n))&&(r[t]=e[n]);return r}var ie={date:9,day:11,weekday:11,isoWeekday:11,dayOfYear:4,hour:13,millisecond:16,minute:14,month:8,quarter:7,second:15,weekYear:1,isoWeekYear:1,week:5,isoWeek:5,year:1};function se(e){var t,n=[];for(t in e)o(e,t)&&n.push({unit:t,priority:ie[t]});return n.sort((function(e,t){return e.priority-t.priority})),n}var ae,oe=/\\d/,le=/\\d\\d/,ue=/\\d{3}/,de=/\\d{4}/,ce=/[+-]?\\d{6}/,he=/\\d\\d?/,fe=/\\d\\d\\d\\d?/,_e=/\\d\\d\\d\\d\\d\\d?/,me=/\\d{1,3}/,pe=/\\d{1,4}/,ye=/[+-]?\\d{1,6}/,ge=/\\d+/,ve=/[+-]?\\d+/,we=/Z|[+-]\\d\\d:?\\d\\d/gi,ke=/Z|[+-]\\d\\d(?::?\\d\\d)?/gi,De=/[+-]?\\d+(\\.\\d{1,3})?/,Me=/[0-9]{0,256}['a-z\\u00A0-\\u05FF\\u0700-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFF07\\uFF10-\\uFFEF]{1,256}|[\\u0600-\\u06FF\\/]{1,256}(\\s*?[\\u0600-\\u06FF]{1,256}){1,2}/i,Se=/^[1-9]\\d?/,Ye=/^([1-9]\\d|\\d)/;function be(e,t,n){ae[e]=x(t)?t:function(e,r){return e&&n?n:t}}function Oe(e,t){return o(ae,e)?ae[e](t._strict,t._locale):new RegExp(Te(e))}function Te(e){return xe(e.replace('\\\\','').replace(/\\\\(\\[)|\\\\(\\])|\\[([^\\]\\[]*)\\]|\\\\(.)/g,(function(e,t,n,r,i){return t||n||r||i})))}function xe(e){return e.replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g,'\\\\$&')}function Ne(e){return e<0?Math.ceil(e)||0:Math.floor(e)}function Pe(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=Ne(t)),n}ae={};var Re={};function Ce(e,t){var n,r,i=t;for('string'==typeof e&&(e=[e]),d(t)&&(i=function(e,n){n[t]=Pe(e)}),r=e.length,n=0;n68?1900:2e3)};var qe,$e=Je('FullYear',!0);function Be(){return Ue(this.year())}function Je(e,t){return function(n){return null!=n?(Xe(this,e,n),r.updateOffset(this,t),this):Qe(this,e)}}function Qe(e,t){if(!e.isValid())return NaN;var n=e._d,r=e._isUTC;switch(t){case'Milliseconds':return r?n.getUTCMilliseconds():n.getMilliseconds();case'Seconds':return r?n.getUTCSeconds():n.getSeconds();case'Minutes':return r?n.getUTCMinutes():n.getMinutes();case'Hours':return r?n.getUTCHours():n.getHours();case'Date':return r?n.getUTCDate():n.getDate();case'Day':return r?n.getUTCDay():n.getDay();case'Month':return r?n.getUTCMonth():n.getMonth();case'FullYear':return r?n.getUTCFullYear():n.getFullYear();default:return NaN}}function Xe(e,t,n){var r,i,s,a,o;if(e.isValid()&&!isNaN(n)){switch(r=e._d,i=e._isUTC,t){case'Milliseconds':return void(i?r.setUTCMilliseconds(n):r.setMilliseconds(n));case'Seconds':return void(i?r.setUTCSeconds(n):r.setSeconds(n));case'Minutes':return void(i?r.setUTCMinutes(n):r.setMinutes(n));case'Hours':return void(i?r.setUTCHours(n):r.setHours(n));case'Date':return void(i?r.setUTCDate(n):r.setDate(n));case'FullYear':break;default:return}s=n,a=e.month(),o=29!==(o=e.date())||1!==a||Ue(s)?o:28,i?r.setUTCFullYear(s,a,o):r.setFullYear(s,a,o)}}function Ke(e){return x(this[e=ne(e)])?this[e]():this}function et(e,t){if('object'==typeof e){var n,r=se(e=re(e)),i=r.length;for(n=0;n=0?(o=new Date(e+400,t,n,r,i,s,a),isFinite(o.getFullYear())&&o.setFullYear(e)):o=new Date(e,t,n,r,i,s,a),o}function vt(e){var t,n;return e<100&&e>=0?((n=Array.prototype.slice.call(arguments))[0]=e+400,t=new Date(Date.UTC.apply(null,n)),isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e)):t=new Date(Date.UTC.apply(null,arguments)),t}function wt(e,t,n){var r=7+t-n;return-(7+vt(e,0,r).getUTCDay()-t)%7+r-1}function kt(e,t,n,r,i){var s,a,o=1+7*(t-1)+(7+n-r)%7+wt(e,r,i);return o<=0?a=ze(s=e-1)+o:o>ze(e)?(s=e+1,a=o-ze(e)):(s=e,a=o),{year:s,dayOfYear:a}}function Dt(e,t,n){var r,i,s=wt(e.year(),t,n),a=Math.floor((e.dayOfYear()-s-1)/7)+1;return a<1?r=a+Mt(i=e.year()-1,t,n):a>Mt(e.year(),t,n)?(r=a-Mt(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function Mt(e,t,n){var r=wt(e,t,n),i=wt(e+1,t,n);return(ze(e)-r+i)/7}function St(e){return Dt(e,this._week.dow,this._week.doy).week}L('w',['ww',2],'wo','week'),L('W',['WW',2],'Wo','isoWeek'),be('w',he,Se),be('ww',he,le),be('W',he,Se),be('WW',he,le),We(['w','ww','W','WW'],(function(e,t,n,r){t[r.substr(0,1)]=Pe(e)}));var Yt={dow:0,doy:6};function bt(){return this._week.dow}function Ot(){return this._week.doy}function Tt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),'d')}function xt(e){var t=Dt(this,1,4).week;return null==e?t:this.add(7*(e-t),'d')}function Nt(e,t){return'string'!=typeof e?e:isNaN(e)?'number'==typeof(e=t.weekdaysParse(e))?e:null:parseInt(e,10)}function Pt(e,t){return'string'==typeof e?t.weekdaysParse(e)%7||7:isNaN(e)?null:e}function Rt(e,t){return e.slice(t,7).concat(e.slice(0,t))}L('d',0,'do','day'),L('dd',0,0,(function(e){return this.localeData().weekdaysMin(this,e)})),L('ddd',0,0,(function(e){return this.localeData().weekdaysShort(this,e)})),L('dddd',0,0,(function(e){return this.localeData().weekdays(this,e)})),L('e',0,0,'weekday'),L('E',0,0,'isoWeekday'),be('d',he),be('e',he),be('E',he),be('dd',(function(e,t){return t.weekdaysMinRegex(e)})),be('ddd',(function(e,t){return t.weekdaysShortRegex(e)})),be('dddd',(function(e,t){return t.weekdaysRegex(e)})),We(['dd','ddd','dddd'],(function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:p(n).invalidWeekday=e})),We(['d','e','E'],(function(e,t,n,r){t[r]=Pe(e)}));var Ct='Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),Wt='Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),Ft='Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),Ut=Me,Ht=Me,At=Me;function Et(e,t){var n=s(this._weekdays)?this._weekdays:this._weekdays[e&&!0!==e&&this._weekdays.isFormat.test(t)?'format':'standalone'];return!0===e?Rt(n,this._week.dow):e?n[e.day()]:n}function Lt(e){return!0===e?Rt(this._weekdaysShort,this._week.dow):e?this._weekdaysShort[e.day()]:this._weekdaysShort}function Vt(e){return!0===e?Rt(this._weekdaysMin,this._week.dow):e?this._weekdaysMin[e.day()]:this._weekdaysMin}function It(e,t,n){var r,i,s,a=e.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],r=0;r<7;++r)s=_([2e3,1]).day(r),this._minWeekdaysParse[r]=this.weekdaysMin(s,'').toLocaleLowerCase(),this._shortWeekdaysParse[r]=this.weekdaysShort(s,'').toLocaleLowerCase(),this._weekdaysParse[r]=this.weekdays(s,'').toLocaleLowerCase();return n?'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null}function Gt(e,t,n){var r,i,s;if(this._weekdaysParseExact)return It.call(this,e,t,n);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;r<7;r++){if(i=_([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp('^'+this.weekdays(i,'').replace('.','\\\\.?')+'$','i'),this._shortWeekdaysParse[r]=new RegExp('^'+this.weekdaysShort(i,'').replace('.','\\\\.?')+'$','i'),this._minWeekdaysParse[r]=new RegExp('^'+this.weekdaysMin(i,'').replace('.','\\\\.?')+'$','i')),this._weekdaysParse[r]||(s='^'+this.weekdays(i,'')+'|^'+this.weekdaysShort(i,'')+'|^'+this.weekdaysMin(i,''),this._weekdaysParse[r]=new RegExp(s.replace('.',''),'i')),n&&'dddd'===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&'ddd'===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&'dd'===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function jt(e){if(!this.isValid())return null!=e?this:NaN;var t=Qe(this,'Day');return null!=e?(e=Nt(e,this.localeData()),this.add(e-t,'d')):t}function Zt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,'d')}function zt(e){if(!this.isValid())return null!=e?this:NaN;if(null!=e){var t=Pt(e,this.localeData());return this.day(this.day()%7?t:t-7)}return this.day()||7}function qt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysStrictRegex:this._weekdaysRegex):(o(this,'_weekdaysRegex')||(this._weekdaysRegex=Ut),this._weekdaysStrictRegex&&e?this._weekdaysStrictRegex:this._weekdaysRegex)}function $t(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(o(this,'_weekdaysShortRegex')||(this._weekdaysShortRegex=Ht),this._weekdaysShortStrictRegex&&e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function Bt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(o(this,'_weekdaysMinRegex')||(this._weekdaysMinRegex=At),this._weekdaysMinStrictRegex&&e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function Jt(){function e(e,t){return t.length-e.length}var t,n,r,i,s,a=[],o=[],l=[],u=[];for(t=0;t<7;t++)n=_([2e3,1]).day(t),r=xe(this.weekdaysMin(n,'')),i=xe(this.weekdaysShort(n,'')),s=xe(this.weekdays(n,'')),a.push(r),o.push(i),l.push(s),u.push(r),u.push(i),u.push(s);a.sort(e),o.sort(e),l.sort(e),u.sort(e),this._weekdaysRegex=new RegExp('^('+u.join('|')+')','i'),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp('^('+l.join('|')+')','i'),this._weekdaysShortStrictRegex=new RegExp('^('+o.join('|')+')','i'),this._weekdaysMinStrictRegex=new RegExp('^('+a.join('|')+')','i')}function Qt(){return this.hours()%12||12}function Xt(){return this.hours()||24}function Kt(e,t){L(e,0,0,(function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)}))}function en(e,t){return t._meridiemParse}function tn(e){return'p'===(e+'').toLowerCase().charAt(0)}L('H',['HH',2],0,'hour'),L('h',['hh',2],0,Qt),L('k',['kk',2],0,Xt),L('hmm',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)})),L('hmmss',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)+F(this.seconds(),2)})),L('Hmm',0,0,(function(){return''+this.hours()+F(this.minutes(),2)})),L('Hmmss',0,0,(function(){return''+this.hours()+F(this.minutes(),2)+F(this.seconds(),2)})),Kt('a',!0),Kt('A',!1),be('a',en),be('A',en),be('H',he,Ye),be('h',he,Se),be('k',he,Se),be('HH',he,le),be('hh',he,le),be('kk',he,le),be('hmm',fe),be('hmmss',_e),be('Hmm',fe),be('Hmmss',_e),Ce(['H','HH'],Le),Ce(['k','kk'],(function(e,t,n){var r=Pe(e);t[Le]=24===r?0:r})),Ce(['a','A'],(function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e})),Ce(['h','hh'],(function(e,t,n){t[Le]=Pe(e),p(n).bigHour=!0})),Ce('hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r)),p(n).bigHour=!0})),Ce('hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i)),p(n).bigHour=!0})),Ce('Hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r))})),Ce('Hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i))}));var nn=/[ap]\\.?m?\\.?/i,rn=Je('Hours',!0);function sn(e,t,n){return e>11?n?'pm':'PM':n?'am':'AM'}var an,on={calendar:C,longDateFormat:Z,invalidDate:q,ordinal:B,dayOfMonthOrdinalParse:J,relativeTime:X,months:rt,monthsShort:it,week:Yt,weekdays:Ct,weekdaysMin:Ft,weekdaysShort:Wt,meridiemParse:nn},ln={},un={};function dn(e,t){var n,r=Math.min(e.length,t.length);for(n=0;n0;){if(r=_n(i.slice(0,t).join('-')))return r;if(n&&n.length>=t&&dn(i,n)>=t-1)break;t--}s++}return an}function fn(e){return!(!e||!e.match('^[^/\\\\\\\\]*$'))}function _n(t){var n=null;if(void 0===ln[t]&&e&&e.exports&&fn(t))try{n=an._abbr,Object(function(){var e=new Error('Cannot find module \\'undefined\\'');throw e.code='MODULE_NOT_FOUND',e}()),mn(n)}catch(e){ln[t]=null}return ln[t]}function mn(e,t){var n;return e&&((n=u(t)?gn(e):pn(e,t))?an=n:'undefined'!=typeof console&&console.warn&&console.warn('Locale '+e+' not found. Did you forget to load it?')),an._abbr}function pn(e,t){if(null!==t){var n,r=on;if(t.abbr=e,null!=ln[e])T('defineLocaleOverride','use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'),r=ln[e]._config;else if(null!=t.parentLocale)if(null!=ln[t.parentLocale])r=ln[t.parentLocale]._config;else{if(null==(n=_n(t.parentLocale)))return un[t.parentLocale]||(un[t.parentLocale]=[]),un[t.parentLocale].push({name:e,config:t}),null;r=n._config}return ln[e]=new R(P(r,t)),un[e]&&un[e].forEach((function(e){pn(e.name,e.config)})),mn(e),ln[e]}return delete ln[e],null}function yn(e,t){if(null!=t){var n,r,i=on;null!=ln[e]&&null!=ln[e].parentLocale?ln[e].set(P(ln[e]._config,t)):(null!=(r=_n(e))&&(i=r._config),t=P(i,t),null==r&&(t.abbr=e),(n=new R(t)).parentLocale=ln[e],ln[e]=n),mn(e)}else null!=ln[e]&&(null!=ln[e].parentLocale?(ln[e]=ln[e].parentLocale,e===mn()&&mn(e)):null!=ln[e]&&delete ln[e]);return ln[e]}function gn(e){var t;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return an;if(!s(e)){if(t=_n(e))return t;e=[e]}return hn(e)}function vn(){return b(ln)}function wn(e){var t,n=e._a;return n&&-2===p(e).overflow&&(t=n[Ae]<0||n[Ae]>11?Ae:n[Ee]<1||n[Ee]>nt(n[He],n[Ae])?Ee:n[Le]<0||n[Le]>24||24===n[Le]&&(0!==n[Ve]||0!==n[Ie]||0!==n[Ge])?Le:n[Ve]<0||n[Ve]>59?Ve:n[Ie]<0||n[Ie]>59?Ie:n[Ge]<0||n[Ge]>999?Ge:-1,p(e)._overflowDayOfYear&&(tEe)&&(t=Ee),p(e)._overflowWeeks&&-1===t&&(t=je),p(e)._overflowWeekday&&-1===t&&(t=Ze),p(e).overflow=t),e}var kn=/^\\s*((?:[+-]\\d{6}|\\d{4})-(?:\\d\\d-\\d\\d|W\\d\\d-\\d|W\\d\\d|\\d\\d\\d|\\d\\d))(?:(T| )(\\d\\d(?::\\d\\d(?::\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Dn=/^\\s*((?:[+-]\\d{6}|\\d{4})(?:\\d\\d\\d\\d|W\\d\\d\\d|W\\d\\d|\\d\\d\\d|\\d\\d|))(?:(T| )(\\d\\d(?:\\d\\d(?:\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Mn=/Z|[+-]\\d\\d(?::?\\d\\d)?/,Sn=[['YYYYYY-MM-DD',/[+-]\\d{6}-\\d\\d-\\d\\d/],['YYYY-MM-DD',/\\d{4}-\\d\\d-\\d\\d/],['GGGG-[W]WW-E',/\\d{4}-W\\d\\d-\\d/],['GGGG-[W]WW',/\\d{4}-W\\d\\d/,!1],['YYYY-DDD',/\\d{4}-\\d{3}/],['YYYY-MM',/\\d{4}-\\d\\d/,!1],['YYYYYYMMDD',/[+-]\\d{10}/],['YYYYMMDD',/\\d{8}/],['GGGG[W]WWE',/\\d{4}W\\d{3}/],['GGGG[W]WW',/\\d{4}W\\d{2}/,!1],['YYYYDDD',/\\d{7}/],['YYYYMM',/\\d{6}/,!1],['YYYY',/\\d{4}/,!1]],Yn=[['HH:mm:ss.SSSS',/\\d\\d:\\d\\d:\\d\\d\\.\\d+/],['HH:mm:ss,SSSS',/\\d\\d:\\d\\d:\\d\\d,\\d+/],['HH:mm:ss',/\\d\\d:\\d\\d:\\d\\d/],['HH:mm',/\\d\\d:\\d\\d/],['HHmmss.SSSS',/\\d\\d\\d\\d\\d\\d\\.\\d+/],['HHmmss,SSSS',/\\d\\d\\d\\d\\d\\d,\\d+/],['HHmmss',/\\d\\d\\d\\d\\d\\d/],['HHmm',/\\d\\d\\d\\d/],['HH',/\\d\\d/]],bn=/^\\/?Date\\((-?\\d+)/i,On=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\\s)?(\\d{1,2})\\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s(\\d{2,4})\\s(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\\d{4}))$/,Tn={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function xn(e){var t,n,r,i,s,a,o=e._i,l=kn.exec(o)||Dn.exec(o),u=Sn.length,d=Yn.length;if(l){for(p(e).iso=!0,t=0,n=u;tze(s)||0===e._dayOfYear)&&(p(e)._overflowDayOfYear=!0),n=vt(s,0,e._dayOfYear),e._a[Ae]=n.getUTCMonth(),e._a[Ee]=n.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=a[t]=r[t];for(;t<7;t++)e._a[t]=a[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[Le]&&0===e._a[Ve]&&0===e._a[Ie]&&0===e._a[Ge]&&(e._nextDay=!0,e._a[Le]=0),e._d=(e._useUTC?vt:gt).apply(null,a),i=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[Le]=24),e._w&&void 0!==e._w.d&&e._w.d!==i&&(p(e).weekdayMismatch=!0)}}function Ln(e){var t,n,r,i,s,a,o,l,u;null!=(t=e._w).GG||null!=t.W||null!=t.E?(s=1,a=4,n=Hn(t.GG,e._a[He],Dt(Bn(),1,4).year),r=Hn(t.W,1),((i=Hn(t.E,1))<1||i>7)&&(l=!0)):(s=e._locale._week.dow,a=e._locale._week.doy,u=Dt(Bn(),s,a),n=Hn(t.gg,e._a[He],u.year),r=Hn(t.w,u.week),null!=t.d?((i=t.d)<0||i>6)&&(l=!0):null!=t.e?(i=t.e+s,(t.e<0||t.e>6)&&(l=!0)):i=s),r<1||r>Mt(n,s,a)?p(e)._overflowWeeks=!0:null!=l?p(e)._overflowWeekday=!0:(o=kt(n,r,i,s,a),e._a[He]=o.year,e._dayOfYear=o.dayOfYear)}function Vn(e){if(e._f!==r.ISO_8601)if(e._f!==r.RFC_2822){e._a=[],p(e).empty=!0;var t,n,i,s,a,o,l,u=''+e._i,d=u.length,c=0;for(l=(i=j(e._f,e._locale).match(U)||[]).length,t=0;t0&&p(e).unusedInput.push(a),u=u.slice(u.indexOf(n)+n.length),c+=n.length),E[s]?(n?p(e).empty=!1:p(e).unusedTokens.push(s),Fe(s,n,e)):e._strict&&!n&&p(e).unusedTokens.push(s);p(e).charsLeftOver=d-c,u.length>0&&p(e).unusedInput.push(u),e._a[Le]<=12&&!0===p(e).bigHour&&e._a[Le]>0&&(p(e).bigHour=void 0),p(e).parsedDateParts=e._a.slice(0),p(e).meridiem=e._meridiem,e._a[Le]=In(e._locale,e._a[Le],e._meridiem),null!==(o=p(e).era)&&(e._a[He]=e._locale.erasConvertYear(o,e._a[He])),En(e),wn(e)}else Fn(e);else xn(e)}function In(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?((r=e.isPM(n))&&t<12&&(t+=12),r||12!==t||(t=0),t):t}function Gn(e){var t,n,r,i,s,a,o=!1,l=e._f.length;if(0===l)return p(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ithis?this:e:g()}));function Xn(e,t){var n,r;if(1===t.length&&s(t[0])&&(t=t[0]),!t.length)return Bn();for(n=t[0],r=1;rthis.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Dr(){if(!u(this._isDSTShifted))return this._isDSTShifted;var e,t={};return k(t,this),(t=zn(t))._a?(e=t._isUTC?_(t._a):Bn(t._a),this._isDSTShifted=this.isValid()&&ur(t._a,e.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function Mr(){return!!this.isValid()&&!this._isUTC}function Sr(){return!!this.isValid()&&this._isUTC}function Yr(){return!!this.isValid()&&this._isUTC&&0===this._offset}r.updateOffset=function(){};var br=/^(-|\\+)?(?:(\\d*)[. ])?(\\d+):(\\d+)(?::(\\d+)(\\.\\d*)?)?$/,Or=/^(-|\\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function Tr(e,t){var n,r,i,s=e,a=null;return or(e)?s={ms:e._milliseconds,d:e._days,M:e._months}:d(e)||!isNaN(+e)?(s={},t?s[t]=+e:s.milliseconds=+e):(a=br.exec(e))?(n='-'===a[1]?-1:1,s={y:0,d:Pe(a[Ee])*n,h:Pe(a[Le])*n,m:Pe(a[Ve])*n,s:Pe(a[Ie])*n,ms:Pe(lr(1e3*a[Ge]))*n}):(a=Or.exec(e))?(n='-'===a[1]?-1:1,s={y:xr(a[2],n),M:xr(a[3],n),w:xr(a[4],n),d:xr(a[5],n),h:xr(a[6],n),m:xr(a[7],n),s:xr(a[8],n)}):null==s?s={}:'object'==typeof s&&('from'in s||'to'in s)&&(i=Pr(Bn(s.from),Bn(s.to)),(s={}).ms=i.milliseconds,s.M=i.months),r=new ar(s),or(e)&&o(e,'_locale')&&(r._locale=e._locale),or(e)&&o(e,'_isValid')&&(r._isValid=e._isValid),r}function xr(e,t){var n=e&&parseFloat(e.replace(',','.'));return(isNaN(n)?0:n)*t}function Nr(e,t){var n={};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,'M').isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,'M'),n}function Pr(e,t){var n;return e.isValid()&&t.isValid()?(t=fr(t,e),e.isBefore(t)?n=Nr(e,t):((n=Nr(t,e)).milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function Rr(e,t){return function(n,r){var i;return null===r||isNaN(+r)||(T(t,'moment().'+t+'(period, number) is deprecated. Please use moment().'+t+'(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'),i=n,n=r,r=i),Cr(this,Tr(n,r),e),this}}function Cr(e,t,n,i){var s=t._milliseconds,a=lr(t._days),o=lr(t._months);e.isValid()&&(i=null==i||i,o&&ht(e,Qe(e,'Month')+o*n),a&&Xe(e,'Date',Qe(e,'Date')+a*n),s&&e._d.setTime(e._d.valueOf()+s*n),i&&r.updateOffset(e,a||o))}Tr.fn=ar.prototype,Tr.invalid=sr;var Wr=Rr(1,'add'),Fr=Rr(-1,'subtract');function Ur(e){return'string'==typeof e||e instanceof String}function Hr(e){return M(e)||c(e)||Ur(e)||d(e)||Er(e)||Ar(e)||null==e}function Ar(e){var t,n,r=a(e)&&!l(e),i=!1,s=['years','year','y','months','month','M','days','day','d','dates','date','D','hours','hour','h','minutes','minute','m','seconds','second','s','milliseconds','millisecond','ms'],u=s.length;for(t=0;tn.valueOf():n.valueOf()9999?G(n,t?'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'):x(Date.prototype.toISOString)?t?this.toDate().toISOString():new Date(this.valueOf()+60*this.utcOffset()*1e3).toISOString().replace('Z',G(n,'Z')):G(n,t?'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYY-MM-DD[T]HH:mm:ss.SSSZ')}function ei(){if(!this.isValid())return'moment.invalid(/* '+this._i+' */)';var e,t,n,r,i='moment',s='';return this.isLocal()||(i=0===this.utcOffset()?'moment.utc':'moment.parseZone',s='Z'),e='['+i+'(\"]',t=0<=this.year()&&this.year()<=9999?'YYYY':'YYYYYY',n='-MM-DD[T]HH:mm:ss.SSS',r=s+'[\")]',this.format(e+t+n+r)}function ti(e){e||(e=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var t=G(this,e);return this.localeData().postformat(t)}function ni(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({to:this,from:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function ri(e){return this.from(Bn(),e)}function ii(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({from:this,to:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function si(e){return this.to(Bn(),e)}function ai(e){var t;return void 0===e?this._locale._abbr:(null!=(t=gn(e))&&(this._locale=t),this)}r.defaultFormat='YYYY-MM-DDTHH:mm:ssZ',r.defaultFormatUtc='YYYY-MM-DDTHH:mm:ss[Z]';var oi=Y('moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',(function(e){return void 0===e?this.localeData():this.locale(e)}));function li(){return this._locale}var ui=1e3,di=60*ui,ci=60*di,hi=3506328*ci;function fi(e,t){return(e%t+t)%t}function _i(e,t,n){return e<100&&e>=0?new Date(e+400,t,n)-hi:new Date(e,t,n).valueOf()}function mi(e,t,n){return e<100&&e>=0?Date.UTC(e+400,t,n)-hi:Date.UTC(e,t,n)}function pi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year(),0,1);break;case'quarter':t=n(this.year(),this.month()-this.month()%3,1);break;case'month':t=n(this.year(),this.month(),1);break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday());break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case'day':case'date':t=n(this.year(),this.month(),this.date());break;case'hour':t=this._d.valueOf(),t-=fi(t+(this._isUTC?0:this.utcOffset()*di),ci);break;case'minute':t=this._d.valueOf(),t-=fi(t,di);break;case'second':t=this._d.valueOf(),t-=fi(t,ui)}return this._d.setTime(t),r.updateOffset(this,!0),this}function yi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year()+1,0,1)-1;break;case'quarter':t=n(this.year(),this.month()-this.month()%3+3,1)-1;break;case'month':t=n(this.year(),this.month()+1,1)-1;break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case'day':case'date':t=n(this.year(),this.month(),this.date()+1)-1;break;case'hour':t=this._d.valueOf(),t+=ci-fi(t+(this._isUTC?0:this.utcOffset()*di),ci)-1;break;case'minute':t=this._d.valueOf(),t+=di-fi(t,di)-1;break;case'second':t=this._d.valueOf(),t+=ui-fi(t,ui)-1}return this._d.setTime(t),r.updateOffset(this,!0),this}function gi(){return this._d.valueOf()-6e4*(this._offset||0)}function vi(){return Math.floor(this.valueOf()/1e3)}function wi(){return new Date(this.valueOf())}function ki(){var e=this;return[e.year(),e.month(),e.date(),e.hour(),e.minute(),e.second(),e.millisecond()]}function Di(){var e=this;return{years:e.year(),months:e.month(),date:e.date(),hours:e.hours(),minutes:e.minutes(),seconds:e.seconds(),milliseconds:e.milliseconds()}}function Mi(){return this.isValid()?this.toISOString():null}function Si(){return y(this)}function Yi(){return f({},p(this))}function bi(){return p(this).overflow}function Oi(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}function Ti(e,t){var n,i,s,a=this._eras||gn('en')._eras;for(n=0,i=a.length;n=0)return l[r]}function Ni(e,t){var n=e.since<=e.until?1:-1;return void 0===t?r(e.since).year():r(e.since).year()+(t-e.offset)*n}function Pi(){var e,t,n,r=this.localeData().eras();for(e=0,t=r.length;e(s=Mt(e,r,i))&&(t=s),Qi.call(this,e,t,n,r,i))}function Qi(e,t,n,r,i){var s=kt(e,t,n,r,i),a=vt(s.year,0,s.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()),this.date(a.getUTCDate()),this}function Xi(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}L('N',0,0,'eraAbbr'),L('NN',0,0,'eraAbbr'),L('NNN',0,0,'eraAbbr'),L('NNNN',0,0,'eraName'),L('NNNNN',0,0,'eraNarrow'),L('y',['y',1],'yo','eraYear'),L('y',['yy',2],0,'eraYear'),L('y',['yyy',3],0,'eraYear'),L('y',['yyyy',4],0,'eraYear'),be('N',Ai),be('NN',Ai),be('NNN',Ai),be('NNNN',Ei),be('NNNNN',Li),Ce(['N','NN','NNN','NNNN','NNNNN'],(function(e,t,n,r){var i=n._locale.erasParse(e,r,n._strict);i?p(n).era=i:p(n).invalidEra=e})),be('y',ge),be('yy',ge),be('yyy',ge),be('yyyy',ge),be('yo',Vi),Ce(['y','yy','yyy','yyyy'],He),Ce(['yo'],(function(e,t,n,r){var i;n._locale._eraYearOrdinalRegex&&(i=e.match(n._locale._eraYearOrdinalRegex)),n._locale.eraYearOrdinalParse?t[He]=n._locale.eraYearOrdinalParse(e,i):t[He]=parseInt(e,10)})),L(0,['gg',2],0,(function(){return this.weekYear()%100})),L(0,['GG',2],0,(function(){return this.isoWeekYear()%100})),Gi('gggg','weekYear'),Gi('ggggg','weekYear'),Gi('GGGG','isoWeekYear'),Gi('GGGGG','isoWeekYear'),be('G',ve),be('g',ve),be('GG',he,le),be('gg',he,le),be('GGGG',pe,de),be('gggg',pe,de),be('GGGGG',ye,ce),be('ggggg',ye,ce),We(['gggg','ggggg','GGGG','GGGGG'],(function(e,t,n,r){t[r.substr(0,2)]=Pe(e)})),We(['gg','GG'],(function(e,t,n,i){t[i]=r.parseTwoDigitYear(e)})),L('Q',0,'Qo','quarter'),be('Q',oe),Ce('Q',(function(e,t){t[Ae]=3*(Pe(e)-1)})),L('D',['DD',2],'Do','date'),be('D',he,Se),be('DD',he,le),be('Do',(function(e,t){return e?t._dayOfMonthOrdinalParse||t._ordinalParse:t._dayOfMonthOrdinalParseLenient})),Ce(['D','DD'],Ee),Ce('Do',(function(e,t){t[Ee]=Pe(e.match(he)[0])}));var Ki=Je('Date',!0);function es(e){var t=Math.round((this.clone().startOf('day')-this.clone().startOf('year'))/864e5)+1;return null==e?t:this.add(e-t,'d')}L('DDD',['DDDD',3],'DDDo','dayOfYear'),be('DDD',me),be('DDDD',ue),Ce(['DDD','DDDD'],(function(e,t,n){n._dayOfYear=Pe(e)})),L('m',['mm',2],0,'minute'),be('m',he,Ye),be('mm',he,le),Ce(['m','mm'],Ve);var ts=Je('Minutes',!1);L('s',['ss',2],0,'second'),be('s',he,Ye),be('ss',he,le),Ce(['s','ss'],Ie);var ns,rs,is=Je('Seconds',!1);for(L('S',0,0,(function(){return~~(this.millisecond()/100)})),L(0,['SS',2],0,(function(){return~~(this.millisecond()/10)})),L(0,['SSS',3],0,'millisecond'),L(0,['SSSS',4],0,(function(){return 10*this.millisecond()})),L(0,['SSSSS',5],0,(function(){return 100*this.millisecond()})),L(0,['SSSSSS',6],0,(function(){return 1e3*this.millisecond()})),L(0,['SSSSSSS',7],0,(function(){return 1e4*this.millisecond()})),L(0,['SSSSSSSS',8],0,(function(){return 1e5*this.millisecond()})),L(0,['SSSSSSSSS',9],0,(function(){return 1e6*this.millisecond()})),be('S',me,oe),be('SS',me,le),be('SSS',me,ue),ns='SSSS';ns.length<=9;ns+='S')be(ns,ge);function ss(e,t){t[Ge]=Pe(1e3*('0.'+e))}for(ns='S';ns.length<=9;ns+='S')Ce(ns,ss);function as(){return this._isUTC?'UTC':''}function os(){return this._isUTC?'Coordinated Universal Time':''}rs=Je('Milliseconds',!1),L('z',0,0,'zoneAbbr'),L('zz',0,0,'zoneName');var ls=D.prototype;function us(e){return Bn(1e3*e)}function ds(){return Bn.apply(null,arguments).parseZone()}function cs(e){return e}ls.add=Wr,ls.calendar=Ir,ls.clone=Gr,ls.diff=Jr,ls.endOf=yi,ls.format=ti,ls.from=ni,ls.fromNow=ri,ls.to=ii,ls.toNow=si,ls.get=Ke,ls.invalidAt=bi,ls.isAfter=jr,ls.isBefore=Zr,ls.isBetween=zr,ls.isSame=qr,ls.isSameOrAfter=$r,ls.isSameOrBefore=Br,ls.isValid=Si,ls.lang=oi,ls.locale=ai,ls.localeData=li,ls.max=Qn,ls.min=Jn,ls.parsingFlags=Yi,ls.set=et,ls.startOf=pi,ls.subtract=Fr,ls.toArray=ki,ls.toObject=Di,ls.toDate=wi,ls.toISOString=Kr,ls.inspect=ei,'undefined'!=typeof Symbol&&null!=Symbol.for&&(ls[Symbol.for('nodejs.util.inspect.custom')]=function(){return'Moment<'+this.format()+'>'}),ls.toJSON=Mi,ls.toString=Xr,ls.unix=vi,ls.valueOf=gi,ls.creationData=Oi,ls.eraName=Pi,ls.eraNarrow=Ri,ls.eraAbbr=Ci,ls.eraYear=Wi,ls.year=$e,ls.isLeapYear=Be,ls.weekYear=ji,ls.isoWeekYear=Zi,ls.quarter=ls.quarters=Xi,ls.month=ft,ls.daysInMonth=_t,ls.week=ls.weeks=Tt,ls.isoWeek=ls.isoWeeks=xt,ls.weeksInYear=$i,ls.weeksInWeekYear=Bi,ls.isoWeeksInYear=zi,ls.isoWeeksInISOWeekYear=qi,ls.date=Ki,ls.day=ls.days=jt,ls.weekday=Zt,ls.isoWeekday=zt,ls.dayOfYear=es,ls.hour=ls.hours=rn,ls.minute=ls.minutes=ts,ls.second=ls.seconds=is,ls.millisecond=ls.milliseconds=rs,ls.utcOffset=mr,ls.utc=yr,ls.local=gr,ls.parseZone=vr,ls.hasAlignedHourOffset=wr,ls.isDST=kr,ls.isLocal=Mr,ls.isUtcOffset=Sr,ls.isUtc=Yr,ls.isUTC=Yr,ls.zoneAbbr=as,ls.zoneName=os,ls.dates=Y('dates accessor is deprecated. Use date instead.',Ki),ls.months=Y('months accessor is deprecated. Use month instead',ft),ls.years=Y('years accessor is deprecated. Use year instead',$e),ls.zone=Y('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',pr),ls.isDSTShifted=Y('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',Dr);var hs=R.prototype;function fs(e,t,n,r){var i=gn(),s=_().set(r,t);return i[n](s,e)}function _s(e,t,n){if(d(e)&&(t=e,e=void 0),e=e||'',null!=t)return fs(e,t,n,'month');var r,i=[];for(r=0;r<12;r++)i[r]=fs(e,r,n,'month');return i}function ms(e,t,n,r){'boolean'==typeof e?(d(t)&&(n=t,t=void 0),t=t||''):(n=t=e,e=!1,d(t)&&(n=t,t=void 0),t=t||'');var i,s=gn(),a=e?s._week.dow:0,o=[];if(null!=n)return fs(t,(n+a)%7,r,'day');for(i=0;i<7;i++)o[i]=fs(t,(i+a)%7,r,'day');return o}function ps(e,t){return _s(e,t,'months')}function ys(e,t){return _s(e,t,'monthsShort')}function gs(e,t,n){return ms(e,t,n,'weekdays')}function vs(e,t,n){return ms(e,t,n,'weekdaysShort')}function ws(e,t,n){return ms(e,t,n,'weekdaysMin')}hs.calendar=W,hs.longDateFormat=z,hs.invalidDate=$,hs.ordinal=Q,hs.preparse=cs,hs.postformat=cs,hs.relativeTime=K,hs.pastFuture=ee,hs.set=N,hs.eras=Ti,hs.erasParse=xi,hs.erasConvertYear=Ni,hs.erasAbbrRegex=Ui,hs.erasNameRegex=Fi,hs.erasNarrowRegex=Hi,hs.months=lt,hs.monthsShort=ut,hs.monthsParse=ct,hs.monthsRegex=pt,hs.monthsShortRegex=mt,hs.week=St,hs.firstDayOfYear=Ot,hs.firstDayOfWeek=bt,hs.weekdays=Et,hs.weekdaysMin=Vt,hs.weekdaysShort=Lt,hs.weekdaysParse=Gt,hs.weekdaysRegex=qt,hs.weekdaysShortRegex=$t,hs.weekdaysMinRegex=Bt,hs.isPM=tn,hs.meridiem=sn,mn('en',{eras:[{since:'0001-01-01',until:1/0,offset:1,name:'Anno Domini',narrow:'AD',abbr:'AD'},{since:'0000-12-31',until:-1/0,offset:1,name:'Before Christ',narrow:'BC',abbr:'BC'}],dayOfMonthOrdinalParse:/\\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===Pe(e%100/10)?'th':1===t?'st':2===t?'nd':3===t?'rd':'th')}}),r.lang=Y('moment.lang is deprecated. Use moment.locale instead.',mn),r.langData=Y('moment.langData is deprecated. Use moment.localeData instead.',gn);var ks=Math.abs;function Ds(){var e=this._data;return this._milliseconds=ks(this._milliseconds),this._days=ks(this._days),this._months=ks(this._months),e.milliseconds=ks(e.milliseconds),e.seconds=ks(e.seconds),e.minutes=ks(e.minutes),e.hours=ks(e.hours),e.months=ks(e.months),e.years=ks(e.years),this}function Ms(e,t,n,r){var i=Tr(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Ss(e,t){return Ms(this,e,t,1)}function Ys(e,t){return Ms(this,e,t,-1)}function bs(e){return e<0?Math.floor(e):Math.ceil(e)}function Os(){var e,t,n,r,i,s=this._milliseconds,a=this._days,o=this._months,l=this._data;return s>=0&&a>=0&&o>=0||s<=0&&a<=0&&o<=0||(s+=864e5*bs(xs(o)+a),a=0,o=0),l.milliseconds=s%1e3,e=Ne(s/1e3),l.seconds=e%60,t=Ne(e/60),l.minutes=t%60,n=Ne(t/60),l.hours=n%24,a+=Ne(n/24),o+=i=Ne(Ts(a)),a-=bs(xs(i)),r=Ne(o/12),o%=12,l.days=a,l.months=o,l.years=r,this}function Ts(e){return 4800*e/146097}function xs(e){return 146097*e/4800}function Ns(e){if(!this.isValid())return NaN;var t,n,r=this._milliseconds;if('month'===(e=ne(e))||'quarter'===e||'year'===e)switch(t=this._days+r/864e5,n=this._months+Ts(t),e){case'month':return n;case'quarter':return n/3;case'year':return n/12}else switch(t=this._days+Math.round(xs(this._months)),e){case'week':return t/7+r/6048e5;case'day':return t+r/864e5;case'hour':return 24*t+r/36e5;case'minute':return 1440*t+r/6e4;case'second':return 86400*t+r/1e3;case'millisecond':return Math.floor(864e5*t)+r;default:throw new Error('Unknown unit '+e)}}function Ps(e){return function(){return this.as(e)}}var Rs=Ps('ms'),Cs=Ps('s'),Ws=Ps('m'),Fs=Ps('h'),Us=Ps('d'),Hs=Ps('w'),As=Ps('M'),Es=Ps('Q'),Ls=Ps('y'),Vs=Rs;function Is(){return Tr(this)}function Gs(e){return e=ne(e),this.isValid()?this[e+'s']():NaN}function js(e){return function(){return this.isValid()?this._data[e]:NaN}}var Zs=js('milliseconds'),zs=js('seconds'),qs=js('minutes'),$s=js('hours'),Bs=js('days'),Js=js('months'),Qs=js('years');function Xs(){return Ne(this.days()/7)}var Ks=Math.round,ea={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function ta(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function na(e,t,n,r){var i=Tr(e).abs(),s=Ks(i.as('s')),a=Ks(i.as('m')),o=Ks(i.as('h')),l=Ks(i.as('d')),u=Ks(i.as('M')),d=Ks(i.as('w')),c=Ks(i.as('y')),h=s<=n.ss&&['s',s]||s0,h[4]=r,ta.apply(null,h)}function ra(e){return void 0===e?Ks:'function'==typeof e&&(Ks=e,!0)}function ia(e,t){return void 0!==ea[e]&&(void 0===t?ea[e]:(ea[e]=t,'s'===e&&(ea.ss=t-1),!0))}function sa(e,t){if(!this.isValid())return this.localeData().invalidDate();var n,r,i=!1,s=ea;return'object'==typeof e&&(t=e,e=!1),'boolean'==typeof e&&(i=e),'object'==typeof t&&(s=Object.assign({},ea,t),null!=t.s&&null==t.ss&&(s.ss=t.s-1)),r=na(this,!i,s,n=this.localeData()),i&&(r=n.pastFuture(+this,r)),n.postformat(r)}var aa=Math.abs;function oa(e){return(e>0)-(e<0)||+e}function la(){if(!this.isValid())return this.localeData().invalidDate();var e,t,n,r,i,s,a,o,l=aa(this._milliseconds)/1e3,u=aa(this._days),d=aa(this._months),c=this.asSeconds();return c?(e=Ne(l/60),t=Ne(e/60),l%=60,e%=60,n=Ne(d/12),d%=12,r=l?l.toFixed(3).replace(/\\.?0+$/,''):'',i=c<0?'-':'',s=oa(this._months)!==oa(c)?'-':'',a=oa(this._days)!==oa(c)?'-':'',o=oa(this._milliseconds)!==oa(c)?'-':'',i+'P'+(n?s+n+'Y':'')+(d?s+d+'M':'')+(u?a+u+'D':'')+(t||e||l?'T':'')+(t?o+t+'H':'')+(e?o+e+'M':'')+(l?o+r+'S':'')):'P0D'}var ua=ar.prototype;return ua.isValid=ir,ua.abs=Ds,ua.add=Ss,ua.subtract=Ys,ua.as=Ns,ua.asMilliseconds=Rs,ua.asSeconds=Cs,ua.asMinutes=Ws,ua.asHours=Fs,ua.asDays=Us,ua.asWeeks=Hs,ua.asMonths=As,ua.asQuarters=Es,ua.asYears=Ls,ua.valueOf=Vs,ua._bubble=Os,ua.clone=Is,ua.get=Gs,ua.milliseconds=Zs,ua.seconds=zs,ua.minutes=qs,ua.hours=$s,ua.days=Bs,ua.weeks=Xs,ua.months=Js,ua.years=Qs,ua.humanize=sa,ua.toISOString=la,ua.toString=la,ua.toJSON=la,ua.locale=ai,ua.localeData=li,ua.toIsoString=Y('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',la),ua.lang=oi,L('X',0,0,'unix'),L('x',0,0,'valueOf'),be('x',ve),be('X',De),Ce('X',(function(e,t,n){n._d=new Date(1e3*parseFloat(e))})),Ce('x',(function(e,t,n){n._d=new Date(Pe(e))})),r.version='2.30.1',i(Bn),r.fn=ls,r.min=Kn,r.max=er,r.now=tr,r.utc=_,r.unix=us,r.months=ps,r.isDate=c,r.locale=mn,r.invalid=g,r.duration=Tr,r.isMoment=M,r.weekdays=gs,r.parseZone=ds,r.localeData=gn,r.isDuration=or,r.monthsShort=ys,r.weekdaysMin=ws,r.defineLocale=pn,r.updateLocale=yn,r.locales=vn,r.weekdaysShort=vs,r.normalizeUnits=ne,r.relativeTimeRounding=ra,r.relativeTimeThreshold=ia,r.calendarFormat=Vr,r.prototype=ls,r.HTML5_FMT={DATETIME_LOCAL:'YYYY-MM-DDTHH:mm',DATETIME_LOCAL_SECONDS:'YYYY-MM-DDTHH:mm:ss',DATETIME_LOCAL_MS:'YYYY-MM-DDTHH:mm:ss.SSS',DATE:'YYYY-MM-DD',TIME:'HH:mm',TIME_SECONDS:'HH:mm:ss',TIME_MS:'HH:mm:ss.SSS',WEEK:'GGGG-[W]WW',MONTH:'YYYY-MM'},r}()},597:e=>{function t(e){return e?Array.isArray(e)?e:[e]:[]}function n(e,t){switch(typeof e){case'undefined':return!0;case'function':return e(t);default:return e}}function r(e,t,r){if(n(e.appliesIf,r)){var i='function'==typeof e.fields?e.fields(r):e.fields.filter((function(e){return n(e.appliesIf,r)})).map((function(e){var t={};return s(e,t,'label'),s(e,t,'value'),s(e,t,'translate'),s(e,t,'filter'),s(e,t,'width'),s(e,t,'icon'),e.context&&(t.context={},s(e.context,t.context,'count'),s(e.context,t.context,'total')),t}));return e.modifyContext&&e.modifyContext(t,r),{label:e.label,fields:i}}function s(e,t,n){switch(typeof e[n]){case'undefined':return;case'function':t[n]=e[n](r);break;default:t[n]=e[n]}}}e.exports=function(e,n,i){var s=e.fields||[],a=e.context||{},o=e.cards||[],l=n&&('contact'===n.type?n.contact_type:n.type),u={cards:[],fields:s.filter((function(e){var n=t(e.appliesToType),r=n.filter((function(e){return e&&'!'===e.charAt(0)}));if((0===n.length||n.includes(l)||r.length>0&&!r.includes('!'+l))&&(!e.appliesIf||e.appliesIf()))return delete e.appliesToType,delete e.appliesIf,!0}))};return o.forEach((function(e){var n,s,o,d,c=t(e.appliesToType);if(c.includes('report')&&c.length>1)throw new Error('You cannot set appliesToType to an array which includes the type \\'report\\' and another type.');if(c.includes('report'))for(n=0;n0)return;(o=r(e,a))&&u.cards.push(o)}})),u.context=a,u}},766:(e,t,n)=>{const r=n(420),i=r().startOf('day'),s=['pregnancy'],a=['pregnancy_home_visit'],o=['delivery'],l=['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregannacy_danger_sign_follow_up'],u=294,d=(e,t)=>['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t,n,r){return e.filter((function(e){return t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r}))}function h(e,t){let n;return e.forEach((function(e){(function(e){return!!(e.form&&e.fields&&e.reported_date)})(e)&&t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function f(e){return M(e)&&d(e,'lmp_date_8601')&&r(d(e,'lmp_date_8601'))}function _(e,t){let n=f(t),i=t.reported_date;return x(e,t).forEach((function(e){const t=S(s=e)&&d(s,'lmp_date_8601')&&r(d(s,'lmp_date_8601'));var s;e.reported_date>i&&'yes'===d(e,'lmp_updated')&&(i=e.reported_date,n=t)})),n}function m(e,t){const n=_(e,t);if(n)return n.clone().add(280,'days')}function p(e){return Y(e)&&d(e,'delivery_outcome.delivery_date')&&r(d(e,'delivery_outcome.delivery_date'))}function y(e){const t=[];if('yes'===d(e,'t_danger_signs_referral_follow_up')){const n=d(e,'danger_signs');if(n)for(const e in n)'yes'===n[e]&&'r_danger_sign_present'!==e&&t.push(e)}return t}function g(e){const t=[];if(!M(e))return[];if('yes'===d(e,'risk_factors.r_risk_factor_present')){'yes'===d(e,'risk_factors.risk_factors_history.first_pregnancy')&&t.push('first_pregnancy'),'yes'===d(e,'risk_factors.risk_factors_history.previous_miscarriage')&&t.push('previous_miscarriage');const n=d(e,'risk_factors.risk_factors_present.primary_condition'),r=d(e,'risk_factors.risk_factors_present.secondary_condition');n&&t.push(...n.split(' ')),r&&t.push(...r.split(' '))}return t}function v(e,t){const n=g(t);return x(e,t).forEach((function(e){n.push(...function(e){const t=[];if(!S(e))return[];if('yes'===d(e,'anc_visits_hf.risk_factors.r_risk_factor_present')){const n=d(e,'anc_visits_hf.risk_factors.new_risks');n&&t.push(...n.split(' '))}return t}(e))})),n}function w(e){let t;return e&&M(e)?t=d(e,'risk_factors.risk_factors_present.additional_risk'):e&&S(e)&&(t=d(e,'anc_visits_hf.risk_factors.additional_risk')),t}function k(e,t){const n=[],r=w(t);r&&n.push(r);return x(e,t).forEach((function(e){const t=w(e);t&&n.push(t)})),n}function D(e){return e&&!e.date_of_death}function M(e){return e&&s.includes(e.form)}function S(e){return e&&a.includes(e.form)}function Y(e){return e&&o.includes(e.form)}function b(e,t,n){if('person'!==e.type||!D(e)||!M(n))return!1;const r=(_(t,n)||n.reported_date)>i.clone().subtract(u,'day'),s=T(t,n,42).length>0,a=function(e,t){return e.filter((function(e){return M(e)&&e.reported_date>t.reported_date}))}(t,n).length>0;return r&&!s&&!a&&!O(t,n,'abortion')&&!O(t,n,'miscarriage')}function O(e,t,n){const r=h(x(e,t),a);if(r&&d(r,'pregnancy_summary.visit_option')===n)return r}function T(e,t,n){return e.filter((function(e){return Y(e)&&e.reported_date>t.reported_date&&(!n||e.reported_date>=i.clone().subtract(n,'days'))}))}function x(e,t){let n=f(t);n||(n=r(t.reported_date));return e.filter((function(e){return S(e)&&e.reported_date>t.reported_date&&r(e.reported_date)b(e)))},isActivePregnancy:b,countANCFacilityVisits:function(e,t){let n=0;const r=x(e,t);return d(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=d(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},knowsHIVStatusInPast3Months:function(e){let t=!1;return c(e,s,i.clone().subtract(3,'months'),i).forEach((function(e){'yes'===d(e,'pregnancy_new_or_current.hiv_status.hiv_status_know')&&(t=!0)})),t},getAllRiskFactors:v,getAllRiskFactorExtra:k,getDangerSignCodes:y,getLatestDangerSignsForPregnancy:function(e,t){if(!t)return[];let n=_(e,t);n||(n=r(t.reported_date));const i=c(e,l,n.toDate(),n.clone().add(u,'days').toDate()),s=[];i.forEach((e=>{S(e)?'yes'===d(e,'pregnancy_summary.visit_option')&&s.push(e):s.push(e)}));const a=h(s,l);return a?y(a):[]},getNextANCVisitDate:function(e,t){let n=d(t,'t_pregnancy_follow_up_date'),i=t.reported_date;return x(e,t).forEach((function(e){e.reported_date>i&&d(e,'t_pregnancy_follow_up_date')&&(i=e.reported_date,n=d(e,'t_pregnancy_follow_up_date'))})),r(n)},isReadyForNewPregnancy:function(e,t){if('person'!==e.type)return!1;const n=h(t,s),a=h(t,o);if(!n&&!a)return!0;if(n){if(!a||a.reported_daten.reported_date))return p(a){const r=n(420),i=n(766),{today:s,MAX_DAYS_IN_PREGNANCY:a,isHighRiskPregnancy:o,getNewestReport:l,getSubsequentPregnancyFollowUps:u,getSubsequentDeliveries:d,isAlive:c,isReadyForNewPregnancy:h,isReadyForDelivery:f,isActivePregnancy:_,countANCFacilityVisits:m,getAllRiskFactors:p,getLatestDangerSignsForPregnancy:y,getNextANCVisitDate:g,getMostRecentLMPDateForPregnancy:v,getMostRecentEDDForPregnancy:w,getDeliveryDate:k,getFormArraySubmittedInWindow:D,getRecentANCVisitWithEvent:M,getAllRiskFactorExtra:S,getField:Y}=i,b=contact,O=lineage,T=reports,x={alive:c(b),muted:!1,show_pregnancy_form:h(b,T),show_delivery_form:f(b,T)},N=[{appliesToType:'person',label:'patient_id',value:b.patient_id,width:4},{appliesToType:'person',label:'contact.age',value:b.date_of_birth,width:4,filter:'age'},{appliesToType:'person',label:'contact.sex',value:'contact.sex.'+b.sex,translate:!0,width:4},{appliesToType:'person',label:'person.field.phone',value:b.phone,width:4},{appliesToType:'person',label:'person.field.alternate_phone',value:b.phone_alternate,width:4},{appliesToType:'person',label:'External ID',value:b.external_id,width:4},{appliesToType:'person',label:'contact.parent',value:O,filter:'lineage'},{appliesToType:'!person',label:'contact',value:b.contact&&b.contact.name,width:4},{appliesToType:'!person',label:'contact.phone',value:b.contact&&b.contact.phone,width:4},{appliesToType:'!person',label:'External ID',value:b.external_id,width:4},{appliesToType:'!person',appliesIf:function(){return b.parent&&O[0]},label:'contact.parent',value:O,filter:'lineage'},{appliesToType:'person',label:'contact.notes',value:b.notes,width:12},{appliesToType:'!person',label:'contact.notes',value:b.notes,width:12}];b.short_name&&N.unshift({appliesToType:'person',label:'contact.short_name',value:b.short_name,width:4});const P=[{label:'contact.profile.pregnancy.active',appliesToType:'report',appliesIf:function(e){return _(b,T,e)},fields:function(e){const t=[],n=p(T,e),i=S(T,e),a=y(T,e),d=o(T,e),c=l(T,['pregnancy','pregnancy_home_visit']),h=r(c.reported_date),f=v(T,e),_=w(T,e),k=g(T,e),D=f?s.diff(f,'weeks'):null;let b=Y(e,'lmp_approx'),O=e.reported_date;u(T,e).forEach((function(e){e.reported_date>O&&'yes'===Y(e,'lmp_updated')&&(O=e.reported_date,Y(e,'lmp_method_approx')&&(b=Y(e,'lmp_method_approx')))}));const x=M(T,e,'migrated'),N=M(T,e,'refused'),P=x||N;if(P){const e='clear_all'===Y(P,'pregnancy_ended.clear_option');t.push({label:'contact.profile.change_care',value:x?'Migrated out of area':'Refusing care',width:6},{label:'contact.profile.tasks_on_off',value:e?'Off':'On',width:6})}if(t.push({label:'Weeks Pregnant',value:D||0===D?{number:D,approximate:'yes'===b}:'contact.profile.value.unknown',translate:!D&&0!==D,filter:D||0===D?'weeksPregnant':'',width:6},{label:'contact.profile.edd',value:_?_.valueOf():'contact.profile.value.unknown',translate:!_,filter:_?'simpleDate':'',width:6}),d){let e='';e=!n&&i?i.join(', '):n.length>1||n&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+n[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}return a.length>0&&t.push({label:'contact.profile.danger_signs.current',value:a.length>1?'contact.profile.danger_sign.multiple':'contact.profile.danger_sign.'+a[0],translate:!0,width:6}),t.push({label:'contact.profile.visit',value:'contact.profile.visits.of',context:{count:m(T,e),total:8},translate:!0,width:6},{label:'contact.profile.last_visited',value:h.valueOf(),filter:'relativeDay',width:6}),k&&k.isSameOrAfter(s)&&t.push({label:'contact.profile.anc.next',value:k.valueOf(),filter:'simpleDate',width:6}),t},modifyContext:function(e,t){let n=Y(t,'lmp_date_8601'),r=Y(t,'lmp_method_approx'),i=Y(t,'hiv_status_known'),s=Y(t,'deworming_med_received'),a=Y(t,'tt_received');const o=p(T,t),l=S(T,t);let d=Y(t,'t_pregnancy_follow_up_date');u(T,t).forEach((function(e){'yes'===Y(e,'lmp_updated')&&(n=Y(e,'lmp_date_8601'),r=Y(e,'lmp_method_approx')),i=Y(e,'hiv_status_known'),s=Y(e,'deworming_med_received'),a=Y(e,'tt_received'),'yes'===Y(e,'t_pregnancy_follow_up')&&(d=Y(e,'t_pregnancy_follow_up_date'))})),e.lmp_date_8601=n,e.lmp_method_approx=r,e.is_active_pregnancy=!0,e.deworming_med_received=s,e.hiv_tested_past=i,e.tt_received_past=a,e.risk_factor_codes=o.join(' '),e.risk_factor_extra=l.join('; '),e.pregnancy_follow_up_date_recent=d,e.pregnancy_uuid=t._id}},{label:'contact.profile.death.title',appliesToType:'person',appliesIf:function(){return!c(b)},fields:function(){const e=[];let t,n;const r=l(T,['death_report']);if(r){const e=Y(r,'death_details');e&&(t=e.date_of_death,n=e.place_of_death)}else b.date_of_death&&(t=b.date_of_death);return e.push({label:'contact.profile.death.date',value:t||'contact.profile.value.unknown',filter:t?'simpleDate':'',translate:!t,width:6},{label:'contact.profile.death.place',value:n||'contact.profile.value.unknown',translate:!0,width:6}),e}},{label:'contact.profile.pregnancy.past',appliesToType:'report',appliesIf:function(e){if('person'!==b.type)return!1;if('delivery'===e.form)return!0;if('pregnancy'===e.form){if(M(T,e,'abortion')||M(T,e,'miscarriage'))return!0;const t=v(T,e);return t&&s.isSameOrAfter(t.clone().add(42,'weeks'))&&0===d(T,e,a).length}return!1},fields:function(e){const t=[];let n,i,l='',u=0,c=0,h=0;if('delivery'===e.form){const s=r(e.reported_date);n=D(T,['pregnancy'],s.clone().subtract(a,'days').toDate(),s.toDate())[0],Y(e,'delivery_outcome')&&(i=k(e),l=Y(e,'delivery_outcome.delivery_place'),u=Y(e,'delivery_outcome.babies_delivered_num'),c=Y(e,'delivery_outcome.babies_deceased_num'),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'',filter:'simpleDate',width:6},{label:'contact.profile.delivery_place',value:l,translate:!0,width:6},{label:'contact.profile.delivered_babies',value:u,width:6}))}else if('pregnancy'===e.form){n=e;const o=v(T,n),l=M(T,n,'abortion'),u=M(T,n,'miscarriage');if(l||u){let e='',n=r(0),i=0;l?(e='abortion',n=r(Y(l,'pregnancy_ended.abortion_date'))):(e='miscarriage',n=r(Y(u,'pregnancy_ended.miscarriage_date'))),i=n.diff(o,'weeks'),t.push({label:'contact.profile.pregnancy.end_early',value:e,translate:!0,width:6},{label:'contact.profile.pregnancy.end_date',value:n.valueOf(),filter:'simpleDate',width:6},{label:'contact.profile.pregnancy.end_weeks',value:i>0?i:'contact.profile.value.unknown',translate:i<=0,width:6})}else o&&s.isSameOrAfter(o.clone().add(42,'weeks'))&&0===d(T,e,a).length&&(i=w(T,e),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'contact.profile.value.unknown',filter:'simpleDate',translate:!i,width:6}))}if(c>0&&Y(e,'baby_death')){t.push({label:'contact.profile.deceased_babies',value:c,width:6});let n=Y(e,'baby_death.baby_death_repeat');n||(n=[]);let r=0;n.forEach((function(e){r>0&&t.push({label:'',value:'',width:6}),t.push({label:'contact.profile.newborn.death_date',value:e.baby_death_date,filter:'simpleDate',width:6},{label:'contact.profile.newborn.death_place',value:e.baby_death_place,translate:!0,width:6},{label:'contact.profile.delivery.stillbirthQ',value:e.stillbirth,translate:!0,width:6}),r++,r===n.length&&t.push({label:'',value:'',width:6})}))}if(n){h=m(T,n),t.push({label:'contact.profile.anc_visit',value:h,width:3});if(o(T,n)){let e='';const r=p(T,n),i=S(T,n);e=!r&&i?i.join(', '):r.length>1||r&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+r[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}}return t}}];e.exports={context:x,cards:P,fields:N}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={id:r,loaded:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.loaded=!0,s.exports}return n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),n(344)})())); return ContactSummary;", + "contact_summary": "var ContactSummary = {}; /*! For license information please see contact-summary.js.LICENSE.txt */\n!function(e,t){if('object'==typeof exports&&'object'==typeof module)module.exports=t();else if('function'==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)('object'==typeof exports?exports:e)[r]=n[r]}}(ContactSummary,(()=>(()=>{var e={597(e){function t(e){return e?Array.isArray(e)?e:[e]:[]}function n(e,t){switch(typeof e){case'undefined':return!0;case'function':return e(t);default:return e}}function r(e,t,r){if(!n(e.appliesIf,r))return;function i(e,t,n){switch(typeof e[n]){case'undefined':return;case'function':t[n]=e[n](r);break;default:t[n]=e[n]}}var s='function'==typeof e.fields?e.fields(r):e.fields.filter((function(e){return n(e.appliesIf,r)})).map((function(e){var t={};return i(e,t,'label'),i(e,t,'value'),i(e,t,'translate'),i(e,t,'filter'),i(e,t,'width'),i(e,t,'icon'),e.context&&(t.context={},i(e.context,t.context,'count'),i(e.context,t.context,'total')),t}));e.modifyContext&&e.modifyContext(t,r);const a={label:e.label,fields:s};return void 0!==e.collapsed&&(a.collapsed=e.collapsed),a}e.exports=function(e,n,i){var s=e.fields||[],a=e.context||{},o=e.cards||[],l=n&&('contact'===n.type?n.contact_type:n.type),u={cards:[],fields:s.filter((function(e){var n=t(e.appliesToType),r=n.filter((function(e){return e&&'!'===e.charAt(0)}));if((0===n.length||n.includes(l)||r.length>0&&!r.includes('!'+l))&&(!e.appliesIf||e.appliesIf()))return delete e.appliesToType,delete e.appliesIf,!0}))};return o.forEach((function(e){var n,s,o,d,c=t(e.appliesToType);if(c.includes('report')&&c.length>1)throw new Error('You cannot set appliesToType to an array which includes the type \\'report\\' and another type.');if(c.includes('report'))for(n=0;n0)return;(o=r(e,a))&&u.cards.push(o)}})),u.context=a,u}},344(e,t,n){var r=n(972),i=n(597);e.exports=i(r,contact,reports)},420(e,t,n){(e=n.nmd(e)).exports=function(){'use strict';var t,n;function r(){return t.apply(null,arguments)}function i(e){t=e}function s(e){return e instanceof Array||'[object Array]'===Object.prototype.toString.call(e)}function a(e){return null!=e&&'[object Object]'===Object.prototype.toString.call(e)}function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){if(Object.getOwnPropertyNames)return 0===Object.getOwnPropertyNames(e).length;var t;for(t in e)if(o(e,t))return!1;return!0}function u(e){return void 0===e}function d(e){return'number'==typeof e||'[object Number]'===Object.prototype.toString.call(e)}function c(e){return e instanceof Date||'[object Date]'===Object.prototype.toString.call(e)}function h(e,t){var n,r=[],i=e.length;for(n=0;n>>0;for(t=0;t0)for(n=0;n=0?n?'+':'':'-')+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}var U=/(\\[[^\\[]*\\])|(\\\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,H=/(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})/g,A={},E={};function L(e,t,n,r){var i=r;'string'==typeof r&&(i=function(){return this[r]()}),e&&(E[e]=i),t&&(E[t[0]]=function(){return F(i.apply(this,arguments),t[1],t[2])}),n&&(E[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function V(e){return e.match(/\\[[\\s\\S]/)?e.replace(/^\\[|\\]$/g,''):e.replace(/\\\\/g,'')}function I(e){var t,n,r=e.match(U);for(t=0,n=r.length;t=0&&H.test(e);)e=e.replace(H,r),H.lastIndex=0,n-=1;return e}var Z={LTS:'h:mm:ss A',LT:'h:mm A',L:'MM/DD/YYYY',LL:'MMMM D, YYYY',LLL:'MMMM D, YYYY h:mm A',LLLL:'dddd, MMMM D, YYYY h:mm A'};function z(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.match(U).map((function(e){return'MMMM'===e||'MM'===e||'DD'===e||'dddd'===e?e.slice(1):e})).join(''),this._longDateFormat[e])}var q='Invalid date';function $(){return this._invalidDate}var B='%d',J=/\\d{1,2}/;function Q(e){return this._ordinal.replace('%d',e)}var X={future:'in %s',past:'%s ago',s:'a few seconds',ss:'%d seconds',m:'a minute',mm:'%d minutes',h:'an hour',hh:'%d hours',d:'a day',dd:'%d days',w:'a week',ww:'%d weeks',M:'a month',MM:'%d months',y:'a year',yy:'%d years'};function K(e,t,n,r){var i=this._relativeTime[n];return x(i)?i(e,t,n,r):i.replace(/%d/i,e)}function ee(e,t){var n=this._relativeTime[e>0?'future':'past'];return x(n)?n(t):n.replace(/%s/i,t)}var te={D:'date',dates:'date',date:'date',d:'day',days:'day',day:'day',e:'weekday',weekdays:'weekday',weekday:'weekday',E:'isoWeekday',isoweekdays:'isoWeekday',isoweekday:'isoWeekday',DDD:'dayOfYear',dayofyears:'dayOfYear',dayofyear:'dayOfYear',h:'hour',hours:'hour',hour:'hour',ms:'millisecond',milliseconds:'millisecond',millisecond:'millisecond',m:'minute',minutes:'minute',minute:'minute',M:'month',months:'month',month:'month',Q:'quarter',quarters:'quarter',quarter:'quarter',s:'second',seconds:'second',second:'second',gg:'weekYear',weekyears:'weekYear',weekyear:'weekYear',GG:'isoWeekYear',isoweekyears:'isoWeekYear',isoweekyear:'isoWeekYear',w:'week',weeks:'week',week:'week',W:'isoWeek',isoweeks:'isoWeek',isoweek:'isoWeek',y:'year',years:'year',year:'year'};function ne(e){return'string'==typeof e?te[e]||te[e.toLowerCase()]:void 0}function re(e){var t,n,r={};for(n in e)o(e,n)&&(t=ne(n))&&(r[t]=e[n]);return r}var ie={date:9,day:11,weekday:11,isoWeekday:11,dayOfYear:4,hour:13,millisecond:16,minute:14,month:8,quarter:7,second:15,weekYear:1,isoWeekYear:1,week:5,isoWeek:5,year:1};function se(e){var t,n=[];for(t in e)o(e,t)&&n.push({unit:t,priority:ie[t]});return n.sort((function(e,t){return e.priority-t.priority})),n}var ae,oe=/\\d/,le=/\\d\\d/,ue=/\\d{3}/,de=/\\d{4}/,ce=/[+-]?\\d{6}/,he=/\\d\\d?/,fe=/\\d\\d\\d\\d?/,_e=/\\d\\d\\d\\d\\d\\d?/,me=/\\d{1,3}/,pe=/\\d{1,4}/,ye=/[+-]?\\d{1,6}/,ge=/\\d+/,ve=/[+-]?\\d+/,we=/Z|[+-]\\d\\d:?\\d\\d/gi,ke=/Z|[+-]\\d\\d(?::?\\d\\d)?/gi,De=/[+-]?\\d+(\\.\\d{1,3})?/,Me=/[0-9]{0,256}['a-z\\u00A0-\\u05FF\\u0700-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFF07\\uFF10-\\uFFEF]{1,256}|[\\u0600-\\u06FF\\/]{1,256}(\\s*?[\\u0600-\\u06FF]{1,256}){1,2}/i,Se=/^[1-9]\\d?/,Ye=/^([1-9]\\d|\\d)/;function be(e,t,n){ae[e]=x(t)?t:function(e,r){return e&&n?n:t}}function Oe(e,t){return o(ae,e)?ae[e](t._strict,t._locale):new RegExp(Te(e))}function Te(e){return xe(e.replace('\\\\','').replace(/\\\\(\\[)|\\\\(\\])|\\[([^\\]\\[]*)\\]|\\\\(.)/g,(function(e,t,n,r,i){return t||n||r||i})))}function xe(e){return e.replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g,'\\\\$&')}function Ne(e){return e<0?Math.ceil(e)||0:Math.floor(e)}function Pe(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=Ne(t)),n}ae={};var Re={};function Ce(e,t){var n,r,i=t;for('string'==typeof e&&(e=[e]),d(t)&&(i=function(e,n){n[t]=Pe(e)}),r=e.length,n=0;n68?1900:2e3)};var qe,$e=Je('FullYear',!0);function Be(){return Ue(this.year())}function Je(e,t){return function(n){return null!=n?(Xe(this,e,n),r.updateOffset(this,t),this):Qe(this,e)}}function Qe(e,t){if(!e.isValid())return NaN;var n=e._d,r=e._isUTC;switch(t){case'Milliseconds':return r?n.getUTCMilliseconds():n.getMilliseconds();case'Seconds':return r?n.getUTCSeconds():n.getSeconds();case'Minutes':return r?n.getUTCMinutes():n.getMinutes();case'Hours':return r?n.getUTCHours():n.getHours();case'Date':return r?n.getUTCDate():n.getDate();case'Day':return r?n.getUTCDay():n.getDay();case'Month':return r?n.getUTCMonth():n.getMonth();case'FullYear':return r?n.getUTCFullYear():n.getFullYear();default:return NaN}}function Xe(e,t,n){var r,i,s,a,o;if(e.isValid()&&!isNaN(n)){switch(r=e._d,i=e._isUTC,t){case'Milliseconds':return void(i?r.setUTCMilliseconds(n):r.setMilliseconds(n));case'Seconds':return void(i?r.setUTCSeconds(n):r.setSeconds(n));case'Minutes':return void(i?r.setUTCMinutes(n):r.setMinutes(n));case'Hours':return void(i?r.setUTCHours(n):r.setHours(n));case'Date':return void(i?r.setUTCDate(n):r.setDate(n));case'FullYear':break;default:return}s=n,a=e.month(),o=29!==(o=e.date())||1!==a||Ue(s)?o:28,i?r.setUTCFullYear(s,a,o):r.setFullYear(s,a,o)}}function Ke(e){return x(this[e=ne(e)])?this[e]():this}function et(e,t){if('object'==typeof e){var n,r=se(e=re(e)),i=r.length;for(n=0;n=0?(o=new Date(e+400,t,n,r,i,s,a),isFinite(o.getFullYear())&&o.setFullYear(e)):o=new Date(e,t,n,r,i,s,a),o}function vt(e){var t,n;return e<100&&e>=0?((n=Array.prototype.slice.call(arguments))[0]=e+400,t=new Date(Date.UTC.apply(null,n)),isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e)):t=new Date(Date.UTC.apply(null,arguments)),t}function wt(e,t,n){var r=7+t-n;return-(7+vt(e,0,r).getUTCDay()-t)%7+r-1}function kt(e,t,n,r,i){var s,a,o=1+7*(t-1)+(7+n-r)%7+wt(e,r,i);return o<=0?a=ze(s=e-1)+o:o>ze(e)?(s=e+1,a=o-ze(e)):(s=e,a=o),{year:s,dayOfYear:a}}function Dt(e,t,n){var r,i,s=wt(e.year(),t,n),a=Math.floor((e.dayOfYear()-s-1)/7)+1;return a<1?r=a+Mt(i=e.year()-1,t,n):a>Mt(e.year(),t,n)?(r=a-Mt(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function Mt(e,t,n){var r=wt(e,t,n),i=wt(e+1,t,n);return(ze(e)-r+i)/7}function St(e){return Dt(e,this._week.dow,this._week.doy).week}L('w',['ww',2],'wo','week'),L('W',['WW',2],'Wo','isoWeek'),be('w',he,Se),be('ww',he,le),be('W',he,Se),be('WW',he,le),We(['w','ww','W','WW'],(function(e,t,n,r){t[r.substr(0,1)]=Pe(e)}));var Yt={dow:0,doy:6};function bt(){return this._week.dow}function Ot(){return this._week.doy}function Tt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),'d')}function xt(e){var t=Dt(this,1,4).week;return null==e?t:this.add(7*(e-t),'d')}function Nt(e,t){return'string'!=typeof e?e:isNaN(e)?'number'==typeof(e=t.weekdaysParse(e))?e:null:parseInt(e,10)}function Pt(e,t){return'string'==typeof e?t.weekdaysParse(e)%7||7:isNaN(e)?null:e}function Rt(e,t){return e.slice(t,7).concat(e.slice(0,t))}L('d',0,'do','day'),L('dd',0,0,(function(e){return this.localeData().weekdaysMin(this,e)})),L('ddd',0,0,(function(e){return this.localeData().weekdaysShort(this,e)})),L('dddd',0,0,(function(e){return this.localeData().weekdays(this,e)})),L('e',0,0,'weekday'),L('E',0,0,'isoWeekday'),be('d',he),be('e',he),be('E',he),be('dd',(function(e,t){return t.weekdaysMinRegex(e)})),be('ddd',(function(e,t){return t.weekdaysShortRegex(e)})),be('dddd',(function(e,t){return t.weekdaysRegex(e)})),We(['dd','ddd','dddd'],(function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:p(n).invalidWeekday=e})),We(['d','e','E'],(function(e,t,n,r){t[r]=Pe(e)}));var Ct='Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),Wt='Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),Ft='Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),Ut=Me,Ht=Me,At=Me;function Et(e,t){var n=s(this._weekdays)?this._weekdays:this._weekdays[e&&!0!==e&&this._weekdays.isFormat.test(t)?'format':'standalone'];return!0===e?Rt(n,this._week.dow):e?n[e.day()]:n}function Lt(e){return!0===e?Rt(this._weekdaysShort,this._week.dow):e?this._weekdaysShort[e.day()]:this._weekdaysShort}function Vt(e){return!0===e?Rt(this._weekdaysMin,this._week.dow):e?this._weekdaysMin[e.day()]:this._weekdaysMin}function It(e,t,n){var r,i,s,a=e.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],r=0;r<7;++r)s=_([2e3,1]).day(r),this._minWeekdaysParse[r]=this.weekdaysMin(s,'').toLocaleLowerCase(),this._shortWeekdaysParse[r]=this.weekdaysShort(s,'').toLocaleLowerCase(),this._weekdaysParse[r]=this.weekdays(s,'').toLocaleLowerCase();return n?'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null}function Gt(e,t,n){var r,i,s;if(this._weekdaysParseExact)return It.call(this,e,t,n);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;r<7;r++){if(i=_([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp('^'+this.weekdays(i,'').replace('.','\\\\.?')+'$','i'),this._shortWeekdaysParse[r]=new RegExp('^'+this.weekdaysShort(i,'').replace('.','\\\\.?')+'$','i'),this._minWeekdaysParse[r]=new RegExp('^'+this.weekdaysMin(i,'').replace('.','\\\\.?')+'$','i')),this._weekdaysParse[r]||(s='^'+this.weekdays(i,'')+'|^'+this.weekdaysShort(i,'')+'|^'+this.weekdaysMin(i,''),this._weekdaysParse[r]=new RegExp(s.replace('.',''),'i')),n&&'dddd'===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&'ddd'===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&'dd'===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function jt(e){if(!this.isValid())return null!=e?this:NaN;var t=Qe(this,'Day');return null!=e?(e=Nt(e,this.localeData()),this.add(e-t,'d')):t}function Zt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,'d')}function zt(e){if(!this.isValid())return null!=e?this:NaN;if(null!=e){var t=Pt(e,this.localeData());return this.day(this.day()%7?t:t-7)}return this.day()||7}function qt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysStrictRegex:this._weekdaysRegex):(o(this,'_weekdaysRegex')||(this._weekdaysRegex=Ut),this._weekdaysStrictRegex&&e?this._weekdaysStrictRegex:this._weekdaysRegex)}function $t(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(o(this,'_weekdaysShortRegex')||(this._weekdaysShortRegex=Ht),this._weekdaysShortStrictRegex&&e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function Bt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(o(this,'_weekdaysMinRegex')||(this._weekdaysMinRegex=At),this._weekdaysMinStrictRegex&&e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function Jt(){function e(e,t){return t.length-e.length}var t,n,r,i,s,a=[],o=[],l=[],u=[];for(t=0;t<7;t++)n=_([2e3,1]).day(t),r=xe(this.weekdaysMin(n,'')),i=xe(this.weekdaysShort(n,'')),s=xe(this.weekdays(n,'')),a.push(r),o.push(i),l.push(s),u.push(r),u.push(i),u.push(s);a.sort(e),o.sort(e),l.sort(e),u.sort(e),this._weekdaysRegex=new RegExp('^('+u.join('|')+')','i'),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp('^('+l.join('|')+')','i'),this._weekdaysShortStrictRegex=new RegExp('^('+o.join('|')+')','i'),this._weekdaysMinStrictRegex=new RegExp('^('+a.join('|')+')','i')}function Qt(){return this.hours()%12||12}function Xt(){return this.hours()||24}function Kt(e,t){L(e,0,0,(function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)}))}function en(e,t){return t._meridiemParse}function tn(e){return'p'===(e+'').toLowerCase().charAt(0)}L('H',['HH',2],0,'hour'),L('h',['hh',2],0,Qt),L('k',['kk',2],0,Xt),L('hmm',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)})),L('hmmss',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)+F(this.seconds(),2)})),L('Hmm',0,0,(function(){return''+this.hours()+F(this.minutes(),2)})),L('Hmmss',0,0,(function(){return''+this.hours()+F(this.minutes(),2)+F(this.seconds(),2)})),Kt('a',!0),Kt('A',!1),be('a',en),be('A',en),be('H',he,Ye),be('h',he,Se),be('k',he,Se),be('HH',he,le),be('hh',he,le),be('kk',he,le),be('hmm',fe),be('hmmss',_e),be('Hmm',fe),be('Hmmss',_e),Ce(['H','HH'],Le),Ce(['k','kk'],(function(e,t,n){var r=Pe(e);t[Le]=24===r?0:r})),Ce(['a','A'],(function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e})),Ce(['h','hh'],(function(e,t,n){t[Le]=Pe(e),p(n).bigHour=!0})),Ce('hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r)),p(n).bigHour=!0})),Ce('hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i)),p(n).bigHour=!0})),Ce('Hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r))})),Ce('Hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i))}));var nn=/[ap]\\.?m?\\.?/i,rn=Je('Hours',!0);function sn(e,t,n){return e>11?n?'pm':'PM':n?'am':'AM'}var an,on={calendar:C,longDateFormat:Z,invalidDate:q,ordinal:B,dayOfMonthOrdinalParse:J,relativeTime:X,months:rt,monthsShort:it,week:Yt,weekdays:Ct,weekdaysMin:Ft,weekdaysShort:Wt,meridiemParse:nn},ln={},un={};function dn(e,t){var n,r=Math.min(e.length,t.length);for(n=0;n0;){if(r=_n(i.slice(0,t).join('-')))return r;if(n&&n.length>=t&&dn(i,n)>=t-1)break;t--}s++}return an}function fn(e){return!(!e||!e.match('^[^/\\\\\\\\]*$'))}function _n(t){var n=null;if(void 0===ln[t]&&e&&e.exports&&fn(t))try{n=an._abbr,Object(function(){var e=new Error('Cannot find module \\'undefined\\'');throw e.code='MODULE_NOT_FOUND',e}()),mn(n)}catch(e){ln[t]=null}return ln[t]}function mn(e,t){var n;return e&&((n=u(t)?gn(e):pn(e,t))?an=n:'undefined'!=typeof console&&console.warn&&console.warn('Locale '+e+' not found. Did you forget to load it?')),an._abbr}function pn(e,t){if(null!==t){var n,r=on;if(t.abbr=e,null!=ln[e])T('defineLocaleOverride','use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'),r=ln[e]._config;else if(null!=t.parentLocale)if(null!=ln[t.parentLocale])r=ln[t.parentLocale]._config;else{if(null==(n=_n(t.parentLocale)))return un[t.parentLocale]||(un[t.parentLocale]=[]),un[t.parentLocale].push({name:e,config:t}),null;r=n._config}return ln[e]=new R(P(r,t)),un[e]&&un[e].forEach((function(e){pn(e.name,e.config)})),mn(e),ln[e]}return delete ln[e],null}function yn(e,t){if(null!=t){var n,r,i=on;null!=ln[e]&&null!=ln[e].parentLocale?ln[e].set(P(ln[e]._config,t)):(null!=(r=_n(e))&&(i=r._config),t=P(i,t),null==r&&(t.abbr=e),(n=new R(t)).parentLocale=ln[e],ln[e]=n),mn(e)}else null!=ln[e]&&(null!=ln[e].parentLocale?(ln[e]=ln[e].parentLocale,e===mn()&&mn(e)):null!=ln[e]&&delete ln[e]);return ln[e]}function gn(e){var t;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return an;if(!s(e)){if(t=_n(e))return t;e=[e]}return hn(e)}function vn(){return b(ln)}function wn(e){var t,n=e._a;return n&&-2===p(e).overflow&&(t=n[Ae]<0||n[Ae]>11?Ae:n[Ee]<1||n[Ee]>nt(n[He],n[Ae])?Ee:n[Le]<0||n[Le]>24||24===n[Le]&&(0!==n[Ve]||0!==n[Ie]||0!==n[Ge])?Le:n[Ve]<0||n[Ve]>59?Ve:n[Ie]<0||n[Ie]>59?Ie:n[Ge]<0||n[Ge]>999?Ge:-1,p(e)._overflowDayOfYear&&(tEe)&&(t=Ee),p(e)._overflowWeeks&&-1===t&&(t=je),p(e)._overflowWeekday&&-1===t&&(t=Ze),p(e).overflow=t),e}var kn=/^\\s*((?:[+-]\\d{6}|\\d{4})-(?:\\d\\d-\\d\\d|W\\d\\d-\\d|W\\d\\d|\\d\\d\\d|\\d\\d))(?:(T| )(\\d\\d(?::\\d\\d(?::\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Dn=/^\\s*((?:[+-]\\d{6}|\\d{4})(?:\\d\\d\\d\\d|W\\d\\d\\d|W\\d\\d|\\d\\d\\d|\\d\\d|))(?:(T| )(\\d\\d(?:\\d\\d(?:\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Mn=/Z|[+-]\\d\\d(?::?\\d\\d)?/,Sn=[['YYYYYY-MM-DD',/[+-]\\d{6}-\\d\\d-\\d\\d/],['YYYY-MM-DD',/\\d{4}-\\d\\d-\\d\\d/],['GGGG-[W]WW-E',/\\d{4}-W\\d\\d-\\d/],['GGGG-[W]WW',/\\d{4}-W\\d\\d/,!1],['YYYY-DDD',/\\d{4}-\\d{3}/],['YYYY-MM',/\\d{4}-\\d\\d/,!1],['YYYYYYMMDD',/[+-]\\d{10}/],['YYYYMMDD',/\\d{8}/],['GGGG[W]WWE',/\\d{4}W\\d{3}/],['GGGG[W]WW',/\\d{4}W\\d{2}/,!1],['YYYYDDD',/\\d{7}/],['YYYYMM',/\\d{6}/,!1],['YYYY',/\\d{4}/,!1]],Yn=[['HH:mm:ss.SSSS',/\\d\\d:\\d\\d:\\d\\d\\.\\d+/],['HH:mm:ss,SSSS',/\\d\\d:\\d\\d:\\d\\d,\\d+/],['HH:mm:ss',/\\d\\d:\\d\\d:\\d\\d/],['HH:mm',/\\d\\d:\\d\\d/],['HHmmss.SSSS',/\\d\\d\\d\\d\\d\\d\\.\\d+/],['HHmmss,SSSS',/\\d\\d\\d\\d\\d\\d,\\d+/],['HHmmss',/\\d\\d\\d\\d\\d\\d/],['HHmm',/\\d\\d\\d\\d/],['HH',/\\d\\d/]],bn=/^\\/?Date\\((-?\\d+)/i,On=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\\s)?(\\d{1,2})\\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s(\\d{2,4})\\s(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\\d{4}))$/,Tn={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function xn(e){var t,n,r,i,s,a,o=e._i,l=kn.exec(o)||Dn.exec(o),u=Sn.length,d=Yn.length;if(l){for(p(e).iso=!0,t=0,n=u;tze(s)||0===e._dayOfYear)&&(p(e)._overflowDayOfYear=!0),n=vt(s,0,e._dayOfYear),e._a[Ae]=n.getUTCMonth(),e._a[Ee]=n.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=a[t]=r[t];for(;t<7;t++)e._a[t]=a[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[Le]&&0===e._a[Ve]&&0===e._a[Ie]&&0===e._a[Ge]&&(e._nextDay=!0,e._a[Le]=0),e._d=(e._useUTC?vt:gt).apply(null,a),i=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[Le]=24),e._w&&void 0!==e._w.d&&e._w.d!==i&&(p(e).weekdayMismatch=!0)}}function Ln(e){var t,n,r,i,s,a,o,l,u;null!=(t=e._w).GG||null!=t.W||null!=t.E?(s=1,a=4,n=Hn(t.GG,e._a[He],Dt(Bn(),1,4).year),r=Hn(t.W,1),((i=Hn(t.E,1))<1||i>7)&&(l=!0)):(s=e._locale._week.dow,a=e._locale._week.doy,u=Dt(Bn(),s,a),n=Hn(t.gg,e._a[He],u.year),r=Hn(t.w,u.week),null!=t.d?((i=t.d)<0||i>6)&&(l=!0):null!=t.e?(i=t.e+s,(t.e<0||t.e>6)&&(l=!0)):i=s),r<1||r>Mt(n,s,a)?p(e)._overflowWeeks=!0:null!=l?p(e)._overflowWeekday=!0:(o=kt(n,r,i,s,a),e._a[He]=o.year,e._dayOfYear=o.dayOfYear)}function Vn(e){if(e._f!==r.ISO_8601)if(e._f!==r.RFC_2822){e._a=[],p(e).empty=!0;var t,n,i,s,a,o,l,u=''+e._i,d=u.length,c=0;for(l=(i=j(e._f,e._locale).match(U)||[]).length,t=0;t0&&p(e).unusedInput.push(a),u=u.slice(u.indexOf(n)+n.length),c+=n.length),E[s]?(n?p(e).empty=!1:p(e).unusedTokens.push(s),Fe(s,n,e)):e._strict&&!n&&p(e).unusedTokens.push(s);p(e).charsLeftOver=d-c,u.length>0&&p(e).unusedInput.push(u),e._a[Le]<=12&&!0===p(e).bigHour&&e._a[Le]>0&&(p(e).bigHour=void 0),p(e).parsedDateParts=e._a.slice(0),p(e).meridiem=e._meridiem,e._a[Le]=In(e._locale,e._a[Le],e._meridiem),null!==(o=p(e).era)&&(e._a[He]=e._locale.erasConvertYear(o,e._a[He])),En(e),wn(e)}else Fn(e);else xn(e)}function In(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?((r=e.isPM(n))&&t<12&&(t+=12),r||12!==t||(t=0),t):t}function Gn(e){var t,n,r,i,s,a,o=!1,l=e._f.length;if(0===l)return p(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ithis?this:e:g()}));function Xn(e,t){var n,r;if(1===t.length&&s(t[0])&&(t=t[0]),!t.length)return Bn();for(n=t[0],r=1;rthis.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Dr(){if(!u(this._isDSTShifted))return this._isDSTShifted;var e,t={};return k(t,this),(t=zn(t))._a?(e=t._isUTC?_(t._a):Bn(t._a),this._isDSTShifted=this.isValid()&&ur(t._a,e.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function Mr(){return!!this.isValid()&&!this._isUTC}function Sr(){return!!this.isValid()&&this._isUTC}function Yr(){return!!this.isValid()&&this._isUTC&&0===this._offset}r.updateOffset=function(){};var br=/^(-|\\+)?(?:(\\d*)[. ])?(\\d+):(\\d+)(?::(\\d+)(\\.\\d*)?)?$/,Or=/^(-|\\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function Tr(e,t){var n,r,i,s=e,a=null;return or(e)?s={ms:e._milliseconds,d:e._days,M:e._months}:d(e)||!isNaN(+e)?(s={},t?s[t]=+e:s.milliseconds=+e):(a=br.exec(e))?(n='-'===a[1]?-1:1,s={y:0,d:Pe(a[Ee])*n,h:Pe(a[Le])*n,m:Pe(a[Ve])*n,s:Pe(a[Ie])*n,ms:Pe(lr(1e3*a[Ge]))*n}):(a=Or.exec(e))?(n='-'===a[1]?-1:1,s={y:xr(a[2],n),M:xr(a[3],n),w:xr(a[4],n),d:xr(a[5],n),h:xr(a[6],n),m:xr(a[7],n),s:xr(a[8],n)}):null==s?s={}:'object'==typeof s&&('from'in s||'to'in s)&&(i=Pr(Bn(s.from),Bn(s.to)),(s={}).ms=i.milliseconds,s.M=i.months),r=new ar(s),or(e)&&o(e,'_locale')&&(r._locale=e._locale),or(e)&&o(e,'_isValid')&&(r._isValid=e._isValid),r}function xr(e,t){var n=e&&parseFloat(e.replace(',','.'));return(isNaN(n)?0:n)*t}function Nr(e,t){var n={};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,'M').isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,'M'),n}function Pr(e,t){var n;return e.isValid()&&t.isValid()?(t=fr(t,e),e.isBefore(t)?n=Nr(e,t):((n=Nr(t,e)).milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function Rr(e,t){return function(n,r){var i;return null===r||isNaN(+r)||(T(t,'moment().'+t+'(period, number) is deprecated. Please use moment().'+t+'(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'),i=n,n=r,r=i),Cr(this,Tr(n,r),e),this}}function Cr(e,t,n,i){var s=t._milliseconds,a=lr(t._days),o=lr(t._months);e.isValid()&&(i=null==i||i,o&&ht(e,Qe(e,'Month')+o*n),a&&Xe(e,'Date',Qe(e,'Date')+a*n),s&&e._d.setTime(e._d.valueOf()+s*n),i&&r.updateOffset(e,a||o))}Tr.fn=ar.prototype,Tr.invalid=sr;var Wr=Rr(1,'add'),Fr=Rr(-1,'subtract');function Ur(e){return'string'==typeof e||e instanceof String}function Hr(e){return M(e)||c(e)||Ur(e)||d(e)||Er(e)||Ar(e)||null==e}function Ar(e){var t,n,r=a(e)&&!l(e),i=!1,s=['years','year','y','months','month','M','days','day','d','dates','date','D','hours','hour','h','minutes','minute','m','seconds','second','s','milliseconds','millisecond','ms'],u=s.length;for(t=0;tn.valueOf():n.valueOf()9999?G(n,t?'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'):x(Date.prototype.toISOString)?t?this.toDate().toISOString():new Date(this.valueOf()+60*this.utcOffset()*1e3).toISOString().replace('Z',G(n,'Z')):G(n,t?'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYY-MM-DD[T]HH:mm:ss.SSSZ')}function ei(){if(!this.isValid())return'moment.invalid(/* '+this._i+' */)';var e,t,n,r,i='moment',s='';return this.isLocal()||(i=0===this.utcOffset()?'moment.utc':'moment.parseZone',s='Z'),e='['+i+'(\"]',t=0<=this.year()&&this.year()<=9999?'YYYY':'YYYYYY',n='-MM-DD[T]HH:mm:ss.SSS',r=s+'[\")]',this.format(e+t+n+r)}function ti(e){e||(e=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var t=G(this,e);return this.localeData().postformat(t)}function ni(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({to:this,from:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function ri(e){return this.from(Bn(),e)}function ii(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({from:this,to:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function si(e){return this.to(Bn(),e)}function ai(e){var t;return void 0===e?this._locale._abbr:(null!=(t=gn(e))&&(this._locale=t),this)}r.defaultFormat='YYYY-MM-DDTHH:mm:ssZ',r.defaultFormatUtc='YYYY-MM-DDTHH:mm:ss[Z]';var oi=Y('moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',(function(e){return void 0===e?this.localeData():this.locale(e)}));function li(){return this._locale}var ui=1e3,di=60*ui,ci=60*di,hi=3506328*ci;function fi(e,t){return(e%t+t)%t}function _i(e,t,n){return e<100&&e>=0?new Date(e+400,t,n)-hi:new Date(e,t,n).valueOf()}function mi(e,t,n){return e<100&&e>=0?Date.UTC(e+400,t,n)-hi:Date.UTC(e,t,n)}function pi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year(),0,1);break;case'quarter':t=n(this.year(),this.month()-this.month()%3,1);break;case'month':t=n(this.year(),this.month(),1);break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday());break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case'day':case'date':t=n(this.year(),this.month(),this.date());break;case'hour':t=this._d.valueOf(),t-=fi(t+(this._isUTC?0:this.utcOffset()*di),ci);break;case'minute':t=this._d.valueOf(),t-=fi(t,di);break;case'second':t=this._d.valueOf(),t-=fi(t,ui)}return this._d.setTime(t),r.updateOffset(this,!0),this}function yi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year()+1,0,1)-1;break;case'quarter':t=n(this.year(),this.month()-this.month()%3+3,1)-1;break;case'month':t=n(this.year(),this.month()+1,1)-1;break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case'day':case'date':t=n(this.year(),this.month(),this.date()+1)-1;break;case'hour':t=this._d.valueOf(),t+=ci-fi(t+(this._isUTC?0:this.utcOffset()*di),ci)-1;break;case'minute':t=this._d.valueOf(),t+=di-fi(t,di)-1;break;case'second':t=this._d.valueOf(),t+=ui-fi(t,ui)-1}return this._d.setTime(t),r.updateOffset(this,!0),this}function gi(){return this._d.valueOf()-6e4*(this._offset||0)}function vi(){return Math.floor(this.valueOf()/1e3)}function wi(){return new Date(this.valueOf())}function ki(){var e=this;return[e.year(),e.month(),e.date(),e.hour(),e.minute(),e.second(),e.millisecond()]}function Di(){var e=this;return{years:e.year(),months:e.month(),date:e.date(),hours:e.hours(),minutes:e.minutes(),seconds:e.seconds(),milliseconds:e.milliseconds()}}function Mi(){return this.isValid()?this.toISOString():null}function Si(){return y(this)}function Yi(){return f({},p(this))}function bi(){return p(this).overflow}function Oi(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}function Ti(e,t){var n,i,s,a=this._eras||gn('en')._eras;for(n=0,i=a.length;n=0)return l[r]}function Ni(e,t){var n=e.since<=e.until?1:-1;return void 0===t?r(e.since).year():r(e.since).year()+(t-e.offset)*n}function Pi(){var e,t,n,r=this.localeData().eras();for(e=0,t=r.length;e(s=Mt(e,r,i))&&(t=s),Qi.call(this,e,t,n,r,i))}function Qi(e,t,n,r,i){var s=kt(e,t,n,r,i),a=vt(s.year,0,s.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()),this.date(a.getUTCDate()),this}function Xi(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}L('N',0,0,'eraAbbr'),L('NN',0,0,'eraAbbr'),L('NNN',0,0,'eraAbbr'),L('NNNN',0,0,'eraName'),L('NNNNN',0,0,'eraNarrow'),L('y',['y',1],'yo','eraYear'),L('y',['yy',2],0,'eraYear'),L('y',['yyy',3],0,'eraYear'),L('y',['yyyy',4],0,'eraYear'),be('N',Ai),be('NN',Ai),be('NNN',Ai),be('NNNN',Ei),be('NNNNN',Li),Ce(['N','NN','NNN','NNNN','NNNNN'],(function(e,t,n,r){var i=n._locale.erasParse(e,r,n._strict);i?p(n).era=i:p(n).invalidEra=e})),be('y',ge),be('yy',ge),be('yyy',ge),be('yyyy',ge),be('yo',Vi),Ce(['y','yy','yyy','yyyy'],He),Ce(['yo'],(function(e,t,n,r){var i;n._locale._eraYearOrdinalRegex&&(i=e.match(n._locale._eraYearOrdinalRegex)),n._locale.eraYearOrdinalParse?t[He]=n._locale.eraYearOrdinalParse(e,i):t[He]=parseInt(e,10)})),L(0,['gg',2],0,(function(){return this.weekYear()%100})),L(0,['GG',2],0,(function(){return this.isoWeekYear()%100})),Gi('gggg','weekYear'),Gi('ggggg','weekYear'),Gi('GGGG','isoWeekYear'),Gi('GGGGG','isoWeekYear'),be('G',ve),be('g',ve),be('GG',he,le),be('gg',he,le),be('GGGG',pe,de),be('gggg',pe,de),be('GGGGG',ye,ce),be('ggggg',ye,ce),We(['gggg','ggggg','GGGG','GGGGG'],(function(e,t,n,r){t[r.substr(0,2)]=Pe(e)})),We(['gg','GG'],(function(e,t,n,i){t[i]=r.parseTwoDigitYear(e)})),L('Q',0,'Qo','quarter'),be('Q',oe),Ce('Q',(function(e,t){t[Ae]=3*(Pe(e)-1)})),L('D',['DD',2],'Do','date'),be('D',he,Se),be('DD',he,le),be('Do',(function(e,t){return e?t._dayOfMonthOrdinalParse||t._ordinalParse:t._dayOfMonthOrdinalParseLenient})),Ce(['D','DD'],Ee),Ce('Do',(function(e,t){t[Ee]=Pe(e.match(he)[0])}));var Ki=Je('Date',!0);function es(e){var t=Math.round((this.clone().startOf('day')-this.clone().startOf('year'))/864e5)+1;return null==e?t:this.add(e-t,'d')}L('DDD',['DDDD',3],'DDDo','dayOfYear'),be('DDD',me),be('DDDD',ue),Ce(['DDD','DDDD'],(function(e,t,n){n._dayOfYear=Pe(e)})),L('m',['mm',2],0,'minute'),be('m',he,Ye),be('mm',he,le),Ce(['m','mm'],Ve);var ts=Je('Minutes',!1);L('s',['ss',2],0,'second'),be('s',he,Ye),be('ss',he,le),Ce(['s','ss'],Ie);var ns,rs,is=Je('Seconds',!1);for(L('S',0,0,(function(){return~~(this.millisecond()/100)})),L(0,['SS',2],0,(function(){return~~(this.millisecond()/10)})),L(0,['SSS',3],0,'millisecond'),L(0,['SSSS',4],0,(function(){return 10*this.millisecond()})),L(0,['SSSSS',5],0,(function(){return 100*this.millisecond()})),L(0,['SSSSSS',6],0,(function(){return 1e3*this.millisecond()})),L(0,['SSSSSSS',7],0,(function(){return 1e4*this.millisecond()})),L(0,['SSSSSSSS',8],0,(function(){return 1e5*this.millisecond()})),L(0,['SSSSSSSSS',9],0,(function(){return 1e6*this.millisecond()})),be('S',me,oe),be('SS',me,le),be('SSS',me,ue),ns='SSSS';ns.length<=9;ns+='S')be(ns,ge);function ss(e,t){t[Ge]=Pe(1e3*('0.'+e))}for(ns='S';ns.length<=9;ns+='S')Ce(ns,ss);function as(){return this._isUTC?'UTC':''}function os(){return this._isUTC?'Coordinated Universal Time':''}rs=Je('Milliseconds',!1),L('z',0,0,'zoneAbbr'),L('zz',0,0,'zoneName');var ls=D.prototype;function us(e){return Bn(1e3*e)}function ds(){return Bn.apply(null,arguments).parseZone()}function cs(e){return e}ls.add=Wr,ls.calendar=Ir,ls.clone=Gr,ls.diff=Jr,ls.endOf=yi,ls.format=ti,ls.from=ni,ls.fromNow=ri,ls.to=ii,ls.toNow=si,ls.get=Ke,ls.invalidAt=bi,ls.isAfter=jr,ls.isBefore=Zr,ls.isBetween=zr,ls.isSame=qr,ls.isSameOrAfter=$r,ls.isSameOrBefore=Br,ls.isValid=Si,ls.lang=oi,ls.locale=ai,ls.localeData=li,ls.max=Qn,ls.min=Jn,ls.parsingFlags=Yi,ls.set=et,ls.startOf=pi,ls.subtract=Fr,ls.toArray=ki,ls.toObject=Di,ls.toDate=wi,ls.toISOString=Kr,ls.inspect=ei,'undefined'!=typeof Symbol&&null!=Symbol.for&&(ls[Symbol.for('nodejs.util.inspect.custom')]=function(){return'Moment<'+this.format()+'>'}),ls.toJSON=Mi,ls.toString=Xr,ls.unix=vi,ls.valueOf=gi,ls.creationData=Oi,ls.eraName=Pi,ls.eraNarrow=Ri,ls.eraAbbr=Ci,ls.eraYear=Wi,ls.year=$e,ls.isLeapYear=Be,ls.weekYear=ji,ls.isoWeekYear=Zi,ls.quarter=ls.quarters=Xi,ls.month=ft,ls.daysInMonth=_t,ls.week=ls.weeks=Tt,ls.isoWeek=ls.isoWeeks=xt,ls.weeksInYear=$i,ls.weeksInWeekYear=Bi,ls.isoWeeksInYear=zi,ls.isoWeeksInISOWeekYear=qi,ls.date=Ki,ls.day=ls.days=jt,ls.weekday=Zt,ls.isoWeekday=zt,ls.dayOfYear=es,ls.hour=ls.hours=rn,ls.minute=ls.minutes=ts,ls.second=ls.seconds=is,ls.millisecond=ls.milliseconds=rs,ls.utcOffset=mr,ls.utc=yr,ls.local=gr,ls.parseZone=vr,ls.hasAlignedHourOffset=wr,ls.isDST=kr,ls.isLocal=Mr,ls.isUtcOffset=Sr,ls.isUtc=Yr,ls.isUTC=Yr,ls.zoneAbbr=as,ls.zoneName=os,ls.dates=Y('dates accessor is deprecated. Use date instead.',Ki),ls.months=Y('months accessor is deprecated. Use month instead',ft),ls.years=Y('years accessor is deprecated. Use year instead',$e),ls.zone=Y('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',pr),ls.isDSTShifted=Y('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',Dr);var hs=R.prototype;function fs(e,t,n,r){var i=gn(),s=_().set(r,t);return i[n](s,e)}function _s(e,t,n){if(d(e)&&(t=e,e=void 0),e=e||'',null!=t)return fs(e,t,n,'month');var r,i=[];for(r=0;r<12;r++)i[r]=fs(e,r,n,'month');return i}function ms(e,t,n,r){'boolean'==typeof e?(d(t)&&(n=t,t=void 0),t=t||''):(n=t=e,e=!1,d(t)&&(n=t,t=void 0),t=t||'');var i,s=gn(),a=e?s._week.dow:0,o=[];if(null!=n)return fs(t,(n+a)%7,r,'day');for(i=0;i<7;i++)o[i]=fs(t,(i+a)%7,r,'day');return o}function ps(e,t){return _s(e,t,'months')}function ys(e,t){return _s(e,t,'monthsShort')}function gs(e,t,n){return ms(e,t,n,'weekdays')}function vs(e,t,n){return ms(e,t,n,'weekdaysShort')}function ws(e,t,n){return ms(e,t,n,'weekdaysMin')}hs.calendar=W,hs.longDateFormat=z,hs.invalidDate=$,hs.ordinal=Q,hs.preparse=cs,hs.postformat=cs,hs.relativeTime=K,hs.pastFuture=ee,hs.set=N,hs.eras=Ti,hs.erasParse=xi,hs.erasConvertYear=Ni,hs.erasAbbrRegex=Ui,hs.erasNameRegex=Fi,hs.erasNarrowRegex=Hi,hs.months=lt,hs.monthsShort=ut,hs.monthsParse=ct,hs.monthsRegex=pt,hs.monthsShortRegex=mt,hs.week=St,hs.firstDayOfYear=Ot,hs.firstDayOfWeek=bt,hs.weekdays=Et,hs.weekdaysMin=Vt,hs.weekdaysShort=Lt,hs.weekdaysParse=Gt,hs.weekdaysRegex=qt,hs.weekdaysShortRegex=$t,hs.weekdaysMinRegex=Bt,hs.isPM=tn,hs.meridiem=sn,mn('en',{eras:[{since:'0001-01-01',until:1/0,offset:1,name:'Anno Domini',narrow:'AD',abbr:'AD'},{since:'0000-12-31',until:-1/0,offset:1,name:'Before Christ',narrow:'BC',abbr:'BC'}],dayOfMonthOrdinalParse:/\\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===Pe(e%100/10)?'th':1===t?'st':2===t?'nd':3===t?'rd':'th')}}),r.lang=Y('moment.lang is deprecated. Use moment.locale instead.',mn),r.langData=Y('moment.langData is deprecated. Use moment.localeData instead.',gn);var ks=Math.abs;function Ds(){var e=this._data;return this._milliseconds=ks(this._milliseconds),this._days=ks(this._days),this._months=ks(this._months),e.milliseconds=ks(e.milliseconds),e.seconds=ks(e.seconds),e.minutes=ks(e.minutes),e.hours=ks(e.hours),e.months=ks(e.months),e.years=ks(e.years),this}function Ms(e,t,n,r){var i=Tr(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Ss(e,t){return Ms(this,e,t,1)}function Ys(e,t){return Ms(this,e,t,-1)}function bs(e){return e<0?Math.floor(e):Math.ceil(e)}function Os(){var e,t,n,r,i,s=this._milliseconds,a=this._days,o=this._months,l=this._data;return s>=0&&a>=0&&o>=0||s<=0&&a<=0&&o<=0||(s+=864e5*bs(xs(o)+a),a=0,o=0),l.milliseconds=s%1e3,e=Ne(s/1e3),l.seconds=e%60,t=Ne(e/60),l.minutes=t%60,n=Ne(t/60),l.hours=n%24,a+=Ne(n/24),o+=i=Ne(Ts(a)),a-=bs(xs(i)),r=Ne(o/12),o%=12,l.days=a,l.months=o,l.years=r,this}function Ts(e){return 4800*e/146097}function xs(e){return 146097*e/4800}function Ns(e){if(!this.isValid())return NaN;var t,n,r=this._milliseconds;if('month'===(e=ne(e))||'quarter'===e||'year'===e)switch(t=this._days+r/864e5,n=this._months+Ts(t),e){case'month':return n;case'quarter':return n/3;case'year':return n/12}else switch(t=this._days+Math.round(xs(this._months)),e){case'week':return t/7+r/6048e5;case'day':return t+r/864e5;case'hour':return 24*t+r/36e5;case'minute':return 1440*t+r/6e4;case'second':return 86400*t+r/1e3;case'millisecond':return Math.floor(864e5*t)+r;default:throw new Error('Unknown unit '+e)}}function Ps(e){return function(){return this.as(e)}}var Rs=Ps('ms'),Cs=Ps('s'),Ws=Ps('m'),Fs=Ps('h'),Us=Ps('d'),Hs=Ps('w'),As=Ps('M'),Es=Ps('Q'),Ls=Ps('y'),Vs=Rs;function Is(){return Tr(this)}function Gs(e){return e=ne(e),this.isValid()?this[e+'s']():NaN}function js(e){return function(){return this.isValid()?this._data[e]:NaN}}var Zs=js('milliseconds'),zs=js('seconds'),qs=js('minutes'),$s=js('hours'),Bs=js('days'),Js=js('months'),Qs=js('years');function Xs(){return Ne(this.days()/7)}var Ks=Math.round,ea={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function ta(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function na(e,t,n,r){var i=Tr(e).abs(),s=Ks(i.as('s')),a=Ks(i.as('m')),o=Ks(i.as('h')),l=Ks(i.as('d')),u=Ks(i.as('M')),d=Ks(i.as('w')),c=Ks(i.as('y')),h=s<=n.ss&&['s',s]||s0,h[4]=r,ta.apply(null,h)}function ra(e){return void 0===e?Ks:'function'==typeof e&&(Ks=e,!0)}function ia(e,t){return void 0!==ea[e]&&(void 0===t?ea[e]:(ea[e]=t,'s'===e&&(ea.ss=t-1),!0))}function sa(e,t){if(!this.isValid())return this.localeData().invalidDate();var n,r,i=!1,s=ea;return'object'==typeof e&&(t=e,e=!1),'boolean'==typeof e&&(i=e),'object'==typeof t&&(s=Object.assign({},ea,t),null!=t.s&&null==t.ss&&(s.ss=t.s-1)),r=na(this,!i,s,n=this.localeData()),i&&(r=n.pastFuture(+this,r)),n.postformat(r)}var aa=Math.abs;function oa(e){return(e>0)-(e<0)||+e}function la(){if(!this.isValid())return this.localeData().invalidDate();var e,t,n,r,i,s,a,o,l=aa(this._milliseconds)/1e3,u=aa(this._days),d=aa(this._months),c=this.asSeconds();return c?(e=Ne(l/60),t=Ne(e/60),l%=60,e%=60,n=Ne(d/12),d%=12,r=l?l.toFixed(3).replace(/\\.?0+$/,''):'',i=c<0?'-':'',s=oa(this._months)!==oa(c)?'-':'',a=oa(this._days)!==oa(c)?'-':'',o=oa(this._milliseconds)!==oa(c)?'-':'',i+'P'+(n?s+n+'Y':'')+(d?s+d+'M':'')+(u?a+u+'D':'')+(t||e||l?'T':'')+(t?o+t+'H':'')+(e?o+e+'M':'')+(l?o+r+'S':'')):'P0D'}var ua=ar.prototype;return ua.isValid=ir,ua.abs=Ds,ua.add=Ss,ua.subtract=Ys,ua.as=Ns,ua.asMilliseconds=Rs,ua.asSeconds=Cs,ua.asMinutes=Ws,ua.asHours=Fs,ua.asDays=Us,ua.asWeeks=Hs,ua.asMonths=As,ua.asQuarters=Es,ua.asYears=Ls,ua.valueOf=Vs,ua._bubble=Os,ua.clone=Is,ua.get=Gs,ua.milliseconds=Zs,ua.seconds=zs,ua.minutes=qs,ua.hours=$s,ua.days=Bs,ua.weeks=Xs,ua.months=Js,ua.years=Qs,ua.humanize=sa,ua.toISOString=la,ua.toString=la,ua.toJSON=la,ua.locale=ai,ua.localeData=li,ua.toIsoString=Y('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',la),ua.lang=oi,L('X',0,0,'unix'),L('x',0,0,'valueOf'),be('x',ve),be('X',De),Ce('X',(function(e,t,n){n._d=new Date(1e3*parseFloat(e))})),Ce('x',(function(e,t,n){n._d=new Date(Pe(e))})),r.version='2.30.1',i(Bn),r.fn=ls,r.min=Kn,r.max=er,r.now=tr,r.utc=_,r.unix=us,r.months=ps,r.isDate=c,r.locale=mn,r.invalid=g,r.duration=Tr,r.isMoment=M,r.weekdays=gs,r.parseZone=ds,r.localeData=gn,r.isDuration=or,r.monthsShort=ys,r.weekdaysMin=ws,r.defineLocale=pn,r.updateLocale=yn,r.locales=vn,r.weekdaysShort=vs,r.normalizeUnits=ne,r.relativeTimeRounding=ra,r.relativeTimeThreshold=ia,r.calendarFormat=Vr,r.prototype=ls,r.HTML5_FMT={DATETIME_LOCAL:'YYYY-MM-DDTHH:mm',DATETIME_LOCAL_SECONDS:'YYYY-MM-DDTHH:mm:ss',DATETIME_LOCAL_MS:'YYYY-MM-DDTHH:mm:ss.SSS',DATE:'YYYY-MM-DD',TIME:'HH:mm',TIME_SECONDS:'HH:mm:ss',TIME_MS:'HH:mm:ss.SSS',WEEK:'GGGG-[W]WW',MONTH:'YYYY-MM'},r}()},766(e,t,n){const r=n(420),i=r().startOf('day'),s=['pregnancy'],a=['pregnancy_home_visit'],o=['delivery'],l=['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregannacy_danger_sign_follow_up'],u=294,d=(e,t)=>['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t,n,r){return e.filter((function(e){return t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r}))}function h(e,t){let n;return e.forEach((function(e){(function(e){return!!(e.form&&e.fields&&e.reported_date)})(e)&&t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function f(e){return M(e)&&d(e,'lmp_date_8601')&&r(d(e,'lmp_date_8601'))}function _(e,t){let n=f(t),i=t.reported_date;return x(e,t).forEach((function(e){const t=S(s=e)&&d(s,'lmp_date_8601')&&r(d(s,'lmp_date_8601'));var s;e.reported_date>i&&'yes'===d(e,'lmp_updated')&&(i=e.reported_date,n=t)})),n}function m(e,t){const n=_(e,t);if(n)return n.clone().add(280,'days')}function p(e){return Y(e)&&d(e,'delivery_outcome.delivery_date')&&r(d(e,'delivery_outcome.delivery_date'))}function y(e){const t=[];if('yes'===d(e,'t_danger_signs_referral_follow_up')){const n=d(e,'danger_signs');if(n)for(const e in n)'yes'===n[e]&&'r_danger_sign_present'!==e&&t.push(e)}return t}function g(e){const t=[];if(!M(e))return[];if('yes'===d(e,'risk_factors.r_risk_factor_present')){'yes'===d(e,'risk_factors.risk_factors_history.first_pregnancy')&&t.push('first_pregnancy'),'yes'===d(e,'risk_factors.risk_factors_history.previous_miscarriage')&&t.push('previous_miscarriage');const n=d(e,'risk_factors.risk_factors_present.primary_condition'),r=d(e,'risk_factors.risk_factors_present.secondary_condition');n&&t.push(...n.split(' ')),r&&t.push(...r.split(' '))}return t}function v(e,t){const n=g(t);return x(e,t).forEach((function(e){n.push(...function(e){const t=[];if(!S(e))return[];if('yes'===d(e,'anc_visits_hf.risk_factors.r_risk_factor_present')){const n=d(e,'anc_visits_hf.risk_factors.new_risks');n&&t.push(...n.split(' '))}return t}(e))})),n}function w(e){let t;return e&&M(e)?t=d(e,'risk_factors.risk_factors_present.additional_risk'):e&&S(e)&&(t=d(e,'anc_visits_hf.risk_factors.additional_risk')),t}function k(e,t){const n=[],r=w(t);r&&n.push(r);return x(e,t).forEach((function(e){const t=w(e);t&&n.push(t)})),n}function D(e){return e&&!e.date_of_death}function M(e){return e&&s.includes(e.form)}function S(e){return e&&a.includes(e.form)}function Y(e){return e&&o.includes(e.form)}function b(e,t,n){if('person'!==e.type||!D(e)||!M(n))return!1;const r=(_(t,n)||n.reported_date)>i.clone().subtract(u,'day'),s=T(t,n,42).length>0,a=function(e,t){return e.filter((function(e){return M(e)&&e.reported_date>t.reported_date}))}(t,n).length>0;return r&&!s&&!a&&!O(t,n,'abortion')&&!O(t,n,'miscarriage')}function O(e,t,n){const r=h(x(e,t),a);if(r&&d(r,'pregnancy_summary.visit_option')===n)return r}function T(e,t,n){return e.filter((function(e){return Y(e)&&e.reported_date>t.reported_date&&(!n||e.reported_date>=i.clone().subtract(n,'days'))}))}function x(e,t){let n=f(t);n||(n=r(t.reported_date));return e.filter((function(e){return S(e)&&e.reported_date>t.reported_date&&r(e.reported_date)b(e)))},isActivePregnancy:b,countANCFacilityVisits:function(e,t){let n=0;const r=x(e,t);return d(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=d(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},knowsHIVStatusInPast3Months:function(e){let t=!1;return c(e,s,i.clone().subtract(3,'months'),i).forEach((function(e){'yes'===d(e,'pregnancy_new_or_current.hiv_status.hiv_status_know')&&(t=!0)})),t},getAllRiskFactors:v,getAllRiskFactorExtra:k,getDangerSignCodes:y,getLatestDangerSignsForPregnancy:function(e,t){if(!t)return[];let n=_(e,t);n||(n=r(t.reported_date));const i=c(e,l,n.toDate(),n.clone().add(u,'days').toDate()),s=[];i.forEach((e=>{S(e)?'yes'===d(e,'pregnancy_summary.visit_option')&&s.push(e):s.push(e)}));const a=h(s,l);return a?y(a):[]},getNextANCVisitDate:function(e,t){let n=d(t,'t_pregnancy_follow_up_date'),i=t.reported_date;return x(e,t).forEach((function(e){e.reported_date>i&&d(e,'t_pregnancy_follow_up_date')&&(i=e.reported_date,n=d(e,'t_pregnancy_follow_up_date'))})),r(n)},isReadyForNewPregnancy:function(e,t){if('person'!==e.type)return!1;const n=h(t,s),a=h(t,o);if(!n&&!a)return!0;if(n){if(!a||a.reported_daten.reported_date))return p(a)O&&'yes'===Y(e,'lmp_updated')&&(O=e.reported_date,Y(e,'lmp_method_approx')&&(b=Y(e,'lmp_method_approx')))}));const x=M(T,e,'migrated'),N=M(T,e,'refused'),P=x||N;if(P){const e='clear_all'===Y(P,'pregnancy_ended.clear_option');t.push({label:'contact.profile.change_care',value:x?'Migrated out of area':'Refusing care',width:6},{label:'contact.profile.tasks_on_off',value:e?'Off':'On',width:6})}if(t.push({label:'Weeks Pregnant',value:D||0===D?{number:D,approximate:'yes'===b}:'contact.profile.value.unknown',translate:!D&&0!==D,filter:D||0===D?'weeksPregnant':'',width:6},{label:'contact.profile.edd',value:_?_.valueOf():'contact.profile.value.unknown',translate:!_,filter:_?'simpleDate':'',width:6}),d){let e='';e=!n&&i?i.join(', '):n.length>1||n&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+n[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}return a.length>0&&t.push({label:'contact.profile.danger_signs.current',value:a.length>1?'contact.profile.danger_sign.multiple':'contact.profile.danger_sign.'+a[0],translate:!0,width:6}),t.push({label:'contact.profile.visit',value:'contact.profile.visits.of',context:{count:m(T,e),total:8},translate:!0,width:6},{label:'contact.profile.last_visited',value:h.valueOf(),filter:'relativeDay',width:6}),k&&k.isSameOrAfter(s)&&t.push({label:'contact.profile.anc.next',value:k.valueOf(),filter:'simpleDate',width:6}),t},modifyContext:function(e,t){let n=Y(t,'lmp_date_8601'),r=Y(t,'lmp_method_approx'),i=Y(t,'hiv_status_known'),s=Y(t,'deworming_med_received'),a=Y(t,'tt_received');const o=p(T,t),l=S(T,t);let d=Y(t,'t_pregnancy_follow_up_date');u(T,t).forEach((function(e){'yes'===Y(e,'lmp_updated')&&(n=Y(e,'lmp_date_8601'),r=Y(e,'lmp_method_approx')),i=Y(e,'hiv_status_known'),s=Y(e,'deworming_med_received'),a=Y(e,'tt_received'),'yes'===Y(e,'t_pregnancy_follow_up')&&(d=Y(e,'t_pregnancy_follow_up_date'))})),e.lmp_date_8601=n,e.lmp_method_approx=r,e.is_active_pregnancy=!0,e.deworming_med_received=s,e.hiv_tested_past=i,e.tt_received_past=a,e.risk_factor_codes=o.join(' '),e.risk_factor_extra=l.join('; '),e.pregnancy_follow_up_date_recent=d,e.pregnancy_uuid=t._id}},{label:'contact.profile.death.title',appliesToType:'person',appliesIf:function(){return!c(b)},fields:function(){const e=[];let t,n;const r=l(T,['death_report']);if(r){const e=Y(r,'death_details');e&&(t=e.date_of_death,n=e.place_of_death)}else b.date_of_death&&(t=b.date_of_death);return e.push({label:'contact.profile.death.date',value:t||'contact.profile.value.unknown',filter:t?'simpleDate':'',translate:!t,width:6},{label:'contact.profile.death.place',value:n||'contact.profile.value.unknown',translate:!0,width:6}),e}},{label:'contact.profile.pregnancy.past',appliesToType:'report',appliesIf:function(e){if('person'!==b.type)return!1;if('delivery'===e.form)return!0;if('pregnancy'===e.form){if(M(T,e,'abortion')||M(T,e,'miscarriage'))return!0;const t=v(T,e);return t&&s.isSameOrAfter(t.clone().add(42,'weeks'))&&0===d(T,e,a).length}return!1},fields:function(e){const t=[];let n,i,l='',u=0,c=0,h=0;if('delivery'===e.form){const s=r(e.reported_date);n=D(T,['pregnancy'],s.clone().subtract(a,'days').toDate(),s.toDate())[0],Y(e,'delivery_outcome')&&(i=k(e),l=Y(e,'delivery_outcome.delivery_place'),u=Y(e,'delivery_outcome.babies_delivered_num'),c=Y(e,'delivery_outcome.babies_deceased_num'),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'',filter:'simpleDate',width:6},{label:'contact.profile.delivery_place',value:l,translate:!0,width:6},{label:'contact.profile.delivered_babies',value:u,width:6}))}else if('pregnancy'===e.form){n=e;const o=v(T,n),l=M(T,n,'abortion'),u=M(T,n,'miscarriage');if(l||u){let e='',n=r(0),i=0;l?(e='abortion',n=r(Y(l,'pregnancy_ended.abortion_date'))):(e='miscarriage',n=r(Y(u,'pregnancy_ended.miscarriage_date'))),i=n.diff(o,'weeks'),t.push({label:'contact.profile.pregnancy.end_early',value:e,translate:!0,width:6},{label:'contact.profile.pregnancy.end_date',value:n.valueOf(),filter:'simpleDate',width:6},{label:'contact.profile.pregnancy.end_weeks',value:i>0?i:'contact.profile.value.unknown',translate:i<=0,width:6})}else o&&s.isSameOrAfter(o.clone().add(42,'weeks'))&&0===d(T,e,a).length&&(i=w(T,e),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'contact.profile.value.unknown',filter:'simpleDate',translate:!i,width:6}))}if(c>0&&Y(e,'baby_death')){t.push({label:'contact.profile.deceased_babies',value:c,width:6});let n=Y(e,'baby_death.baby_death_repeat');n||(n=[]);let r=0;n.forEach((function(e){r>0&&t.push({label:'',value:'',width:6}),t.push({label:'contact.profile.newborn.death_date',value:e.baby_death_date,filter:'simpleDate',width:6},{label:'contact.profile.newborn.death_place',value:e.baby_death_place,translate:!0,width:6},{label:'contact.profile.delivery.stillbirthQ',value:e.stillbirth,translate:!0,width:6}),r++,r===n.length&&t.push({label:'',value:'',width:6})}))}if(n){h=m(T,n),t.push({label:'contact.profile.anc_visit',value:h,width:3});if(o(T,n)){let e='';const r=p(T,n),i=S(T,n);e=!r&&i?i.join(', '):r.length>1||r&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+r[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}}return t}}];e.exports={context:x,cards:P,fields:N}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={id:r,loaded:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.loaded=!0,s.exports}return n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),n(344)})())); return ContactSummary;", "tasks": { - "rules": "(()=>{var e={85:(e,t,n)=>{var r=n(730),i=n(721);function o(e,t,n,r,i,o){var a;if(e.appliesToType){var s;if('contacts'===e.appliesTo){if(!i.contact)return;s='contact'===i.contact.type?i.contact.contact_type:i.contact.type}else{if(!o)return;s=o.form}if(-1===e.appliesToType.indexOf(s))return}if('scheduled_tasks'===e.appliesTo||!e.appliesIf||e.appliesIf(i,o))if('scheduled_tasks'===e.appliesTo){if(o&&e.appliesIf){if(!o.scheduled_tasks)return;for(a=0;a{const t=d(Date.now()),n=864e5,r=['pregnancy'],i=['delivery'],o=['pregnancy_home_visit'],a=['pregnancy','pregnancy_home_visit','pregnancy_facility_visit_reminder','pregnancy_danger_sign','pregnancy_danger_sign_follow_up','delivery'];const s=(e,t)=>['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&!e.deleted&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function p(e){if(!e)return new Date;const t=e.split(/\\D/),n=new Date(t[0],t[1]-1,t[2]);return function(e){return e instanceof Date&&!isNaN(e)}(n)?n:new Date}function l(e){const t=new Date(e);return t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t}function d(e){if('string'==typeof e){if(''===e)return null;e=p(e)}return l(e).getTime()}function _(e,t){const n=l(new Date(e));return n.setDate(n.getDate()+t),n}function u(e){return r.includes(e.form)}function f(e){return o.includes(e.form)}const g=function(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n},y=function(e){return u(e)&&d(s(e,'lmp_date_8601'))};function m(e,t){return e.reports.filter((function(e){let n=y(t);return n||(n=t.reported_date),f(e)&&e.reported_date>t.reported_date&&e.reported_date<_(n,294)}))}function v(e,t){let n=y(t),r=t.reported_date;return m(e,t).forEach((function(e){const t=function(e){return f(e)&&d(s(e,'lmp_date_8601'))}(e);e.reported_date>r&&''!==t&&t!==n&&(r=e.reported_date,n=t)})),n}e.exports={today:t,MS_IN_DAY:n,MAX_DAYS_IN_PREGNANCY:294,addDays:_,isAlive:function(e){return e&&e.contact&&!e.contact.date_of_death},getTimeForMidnight:l,isFormArraySubmittedInWindow:function(e,t,n,r,i){let o=!1,a=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(o=!0,i&&a++)})),i?a>=i:o},isFormArraySubmittedInWindowExcludingThisReport:function(e,t,n,r,i,o){let a=!1,s=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&e._id!==i._id&&(a=!0,o&&s++)})),o?s>=o:a},getDateMS:d,getDateISOLocal:p,isDeliveryForm:function(e){return i.includes(e.form)},getMostRecentReport:c,getNewestPregnancyTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'pregnancy');return t?t.reported_date:0},getNewestDeliveryTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'delivery');return t?t.reported_date:0},getReportsSubmittedInWindow:function(e,t,n,r,i){const o=[];return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o.push(e))})),o},countReportsSubmittedInWindow:function(e,t,n,r,i){let o=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o++)})),o},countANCFacilityVisits:function(e,t){let n=0;const r=m(e,t);return s(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=s(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},isFacilityDelivery:function(e,t){return!!e&&(1===arguments.length&&(t=e),'yes'===s(t,'facility_delivery'))},getMostRecentLMPDateForPregnancy:v,getNewestReport:g,getSubsequentPregnancyFollowUps:m,isActivePregnancy:function(e,r){if(!u(r))return!1;const i=(v(e,r)||r.reported_date)>t-254016e5,a=function(e,r,i){return e.reports.filter((function(e){return'delivery'===e.form&&e.reported_date>r.reported_date&&(!i||r.reported_date>=t-i*n)}))}(e,r,42).length>0,c=function(e,t){return e.reports.filter((function(e){return u(e)&&e.reported_date>t.reported_date}))}(e,r).length>0;return i&&!a&&!c&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'abortion'===s(r,'pregnancy_summary.visit_option')}(e,r)&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'miscarriage'===s(r,'pregnancy_summary.visit_option')}(e,r)},getRecentANCVisitWithEvent:function(e,t,n){const r=m(e,t),i=g(r,o);if(i&&s(i,'pregnancy_summary.visit_option')===n)return i},isPregnancyTaskMuted:function(e){const t=g(e.reports,a);return t&&f(t)&&'clear_all'===s(t,'pregnancy_ended.clear_option')},getField:s}},721:e=>{e.exports={defaultResolvedIf:function(e,t,n,r,i){var o,a;i||(i=Utils);var s=function(e){var t;if(!e||!e.actions)return;return(t=e.actions.find((function(e){return!e.type||'report'===e.type})))&&t.form}(this.definition);if(!s)throw new Error('Could not find the default resolving form!');return o=0,o=t?Math.max(i.addDate(r,-n.start).getTime(),t.reported_date+1):i.addDate(r,-n.start).getTime(),a=i.addDate(r,n.end+1).getTime(),i.isFormSubmittedInWindow(e.reports,s,o,a)}}},730:e=>{function t(e,n){var r=Object.keys(e);for(var i in r){var o=r[i];switch(typeof e[o]){case'object':t(e[o],n);break;case'function':e[o]=e[o].bind(n)}}}function n(e){var t=Object.assign({},e),r=Object.keys(t);for(var i in r){var o=r[i];if(Array.isArray(t[o])){t[o]=t[o].slice(0);for(var a=0;a{const r=n(190),{isAlive:i,getSubsequentPregnancyFollowUps:o,getMostRecentLMPDateForPregnancy:a,isActivePregnancy:s,countANCFacilityVisits:c,getField:p}=r;e.exports=[{id:'deaths-this-month',type:'count',icon:'icon-death-general',goal:0,translation_key:'targets.death_reporting.deaths.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return!i(e)},date:e=>e.contact.date_of_death},{id:'pregnancy-registrations-this-month',type:'count',icon:'icon-pregnancy',goal:20,translation_key:'targets.anc.new_pregnancy_registrations.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return!!t&&a(e,t)},date:'reported',idType:'contact'},{id:'births-this-month',type:'count',icon:'icon-infant',goal:-1,translation_key:'targets.births.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e&&e.contact&&e.contact.date_of_birth},date:e=>e.contact.date_of_birth,dhis:{dataElement:'kB0ZBFisE0e'}},{id:'active-pregnancies',type:'count',icon:'icon-pregnancy',goal:-1,translation_key:'targets.anc.active_pregnancies.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return s(e,t)},date:'now',idType:'contact'},{id:'active-pregnancies-1+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_1p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>0},date:'now',idType:'contact'},{id:'facility-deliveries',type:'percent',icon:'icon-mother-child',goal:-1,translation_key:'targets.anc.facility_deliveries.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['delivery'],appliesIf:function(e,t){return p(t,'delivery_outcome.delivery_place')},passesIf:function(e,t){return'health_facility'===p(t,'delivery_outcome.delivery_place')},date:'now',idType:'contact',dhis:{dataElement:'e22tIwy1nKR',categoryOptionCombo:'HllvX50cXC0',attributeOptionCombo:'HllvX50cXC0'}},{id:'active-pregnancies-4+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_4p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>3},date:'now',idType:'contact'},{id:'active-pregnancies-8+-contacts',type:'count',icon:'icon-follow-up',goal:-1,translation_key:'targets.anc.active_pregnancies_8p_contacts.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return 1+(o(e,t).length||0)+(c(e,t)||0)>7},date:'now',idType:'contact'}]},945:(e,t,n)=>{var r=n(730);function i(e,t,n,r,i,o){var a=!!o;if(i.contact){var s='contact'===i.contact.type?i.contact.contact_type:i.contact.type,c=a?o.form:s;if(!(e.appliesToType&&e.appliesToType.indexOf(c)<0)&&(!e.appliesIf||e.appliesIf(i,o)))for(var p=a?o:i.contact,l=function(e,t,n){var r;return r='function'==typeof e.idType?e.idType(t,n):'report'===e.idType?n&&n._id:t.contact&&t.contact._id,Array.isArray(r)||(r=[r]),r}(e,i,o),d=!e.passesIf||!!e.passesIf(i,o),_=function(e,t,n,r){if('function'==typeof e.date)return e.date(n,r)||t.now().getTime();if(void 0===e.date||null===e.date||'now'===e.date)return t.now().getTime();if('reported'===e.date)return r?r.reported_date:n.contact.reported_date;throw new Error('Unrecognised value for target.date: '+e.date)}(e,n,i,o),u=e.groupBy&&e.groupBy(i,o),f=0;f{const r=n(190),{MAX_DAYS_IN_PREGNANCY:i,today:o,getNewestPregnancyTimestamp:a,getNewestDeliveryTimestamp:s,isAlive:c,isFormArraySubmittedInWindow:p,getDateISOLocal:l,getTimeForMidnight:d,isDeliveryForm:_,getMostRecentLMPDateForPregnancy:u,addDays:f,getRecentANCVisitWithEvent:g,isPregnancyTaskMuted:y,getField:m}=r,v=(e,t,n)=>({id:`pregnancy-home-visit-week${e}`,start:t,end:n,dueDate:function(t,n,r){const i=u(n,r);return f(i||r.reported_date,7*e)}});function h(e,t,n,r){if(t.reported_date=o},resolvedIf:h,actions:[{type:'report',form:'pregnancy_home_visit',label:'Pregnancy home visit'}],events:[...Array(21).keys()].map((e=>v(2*(e+1),6,7)))},{name:'anc.facility_reminder',icon:'icon-pregnancy',title:'task.anc.facility_reminder.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit'],appliesIf:function(e,t){return m(t,'t_pregnancy_follow_up_date')},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_facility_visit_reminder'],i,o)},actions:[{type:'report',form:'pregnancy_facility_visit_reminder',label:'Pregnancy facility visit reminder',modifyContent:function(e,t,n){e.source_visit_date=m(n,'t_pregnancy_follow_up_date')}}],events:[{id:'pregnancy-facility-visit-reminder',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_pregnancy_follow_up_date'))}}]},{name:'anc.pregnancy_danger_sign_followup',icon:'icon-pregnancy-danger',title:'task.anc.pregnancy_danger_sign_followup.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregnancy_danger_sign_follow_up'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_danger_sign_follow_up'],i,o)},actions:[{type:'report',form:'pregnancy_danger_sign_follow_up'}],events:[{id:'pregnancy-danger-sign-follow-up',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'anc.delivery',icon:'icon-mother-child',title:'task.anc.delivery.title',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){const n=u(e,t);return n&&f(n,336)>=o&&c(e)},resolvedIf:function(e,t,n,r){if(g(e,t,'abortion')||g(e,t,'miscarriage'))return!0;if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['delivery'],i,o)},actions:[{type:'report',form:'delivery'}],events:[{id:'delivery-reminder',start:28,end:42,dueDate:function(e,t,n){return f(u(t,n),i)}}]},{name:'pnc.danger_sign_followup_mother',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_mother.title',appliesTo:'reports',appliesToType:['delivery','pnc_danger_sign_follow_up_mother'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_mother'],i,o)},actions:[{type:'report',form:'pnc_danger_sign_follow_up_mother',modifyContent:function(e,t,n){_(n)?e.delivery_uuid=n._id:e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-mother',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'pnc.danger_sign_followup_baby.from_contact',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e.contact&&'yes'===e.contact.t_danger_signs_referral_follow_up&&c(e)},resolvedIf:function(e,t,n,r){const i=Math.max(f(r,-n.start).getTime(),e.contact.reported_date),o=f(r,n.end).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t){e.delivery_uuid=t.contact.created_by_doc}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t){return l(t.contact.t_danger_signs_referral_follow_up_date)}}]},{name:'pnc.danger_sign_followup_baby.from_report',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'reports',appliesToType:['pnc_danger_sign_follow_up_baby'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t,n){e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]}]}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}var r=n(991),i=n(931),o=n(85);n(945)(i,c,Utils,Target,emit),o(r,c,Utils,Task,emit),emit('_complete',{_id:!0})})();", + "rules": "(()=>{var e={730(e){function t(e,n){var r=Object.keys(e);for(var i in r){var o=r[i];switch(typeof e[o]){case'object':t(e[o],n);break;case'function':e[o]=e[o].bind(n)}}}function n(e){var t=Object.assign({},e),r=Object.keys(t);for(var i in r){var o=r[i];if(Array.isArray(t[o])){t[o]=t[o].slice(0);for(var a=0;a['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&!e.deleted&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function p(e){if(!e)return new Date;const t=e.split(/\\D/),n=new Date(t[0],t[1]-1,t[2]);return function(e){return e instanceof Date&&!isNaN(e)}(n)?n:new Date}function l(e){const t=new Date(e);return t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t}function d(e){if('string'==typeof e){if(''===e)return null;e=p(e)}return l(e).getTime()}function _(e,t){const n=l(new Date(e));return n.setDate(n.getDate()+t),n}function u(e){return r.includes(e.form)}function f(e){return o.includes(e.form)}const g=function(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n},y=function(e){return u(e)&&d(s(e,'lmp_date_8601'))};function m(e,t){return e.reports.filter((function(e){let n=y(t);return n||(n=t.reported_date),f(e)&&e.reported_date>t.reported_date&&e.reported_date<_(n,294)}))}function v(e,t){let n=y(t),r=t.reported_date;return m(e,t).forEach((function(e){const t=function(e){return f(e)&&d(s(e,'lmp_date_8601'))}(e);e.reported_date>r&&''!==t&&t!==n&&(r=e.reported_date,n=t)})),n}e.exports={today:t,MS_IN_DAY:n,MAX_DAYS_IN_PREGNANCY:294,addDays:_,isAlive:function(e){return e&&e.contact&&!e.contact.date_of_death},getTimeForMidnight:l,isFormArraySubmittedInWindow:function(e,t,n,r,i){let o=!1,a=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(o=!0,i&&a++)})),i?a>=i:o},isFormArraySubmittedInWindowExcludingThisReport:function(e,t,n,r,i,o){let a=!1,s=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&e._id!==i._id&&(a=!0,o&&s++)})),o?s>=o:a},getDateMS:d,getDateISOLocal:p,isDeliveryForm:function(e){return i.includes(e.form)},getMostRecentReport:c,getNewestPregnancyTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'pregnancy');return t?t.reported_date:0},getNewestDeliveryTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'delivery');return t?t.reported_date:0},getReportsSubmittedInWindow:function(e,t,n,r,i){const o=[];return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o.push(e))})),o},countReportsSubmittedInWindow:function(e,t,n,r,i){let o=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o++)})),o},countANCFacilityVisits:function(e,t){let n=0;const r=m(e,t);return s(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=s(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},isFacilityDelivery:function(e,t){return!!e&&(1===arguments.length&&(t=e),'yes'===s(t,'facility_delivery'))},getMostRecentLMPDateForPregnancy:v,getNewestReport:g,getSubsequentPregnancyFollowUps:m,isActivePregnancy:function(e,r){if(!u(r))return!1;const i=(v(e,r)||r.reported_date)>t-254016e5,a=function(e,r,i){return e.reports.filter((function(e){return'delivery'===e.form&&e.reported_date>r.reported_date&&(!i||r.reported_date>=t-i*n)}))}(e,r,42).length>0,c=function(e,t){return e.reports.filter((function(e){return u(e)&&e.reported_date>t.reported_date}))}(e,r).length>0;return i&&!a&&!c&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'abortion'===s(r,'pregnancy_summary.visit_option')}(e,r)&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'miscarriage'===s(r,'pregnancy_summary.visit_option')}(e,r)},getRecentANCVisitWithEvent:function(e,t,n){const r=m(e,t),i=g(r,o);if(i&&s(i,'pregnancy_summary.visit_option')===n)return i},isPregnancyTaskMuted:function(e){const t=g(e.reports,a);return t&&f(t)&&'clear_all'===s(t,'pregnancy_ended.clear_option')},getField:s}},931(e,t,n){const r=n(190),{isAlive:i,getSubsequentPregnancyFollowUps:o,getMostRecentLMPDateForPregnancy:a,isActivePregnancy:s,countANCFacilityVisits:c,getField:p}=r;e.exports=[{id:'deaths-this-month',type:'count',icon:'icon-death-general',goal:0,translation_key:'targets.death_reporting.deaths.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return!i(e)},date:e=>e.contact.date_of_death},{id:'pregnancy-registrations-this-month',type:'count',icon:'icon-pregnancy',goal:20,translation_key:'targets.anc.new_pregnancy_registrations.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return!!t&&a(e,t)},date:'reported',idType:'contact'},{id:'births-this-month',type:'count',icon:'icon-infant',goal:-1,translation_key:'targets.births.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e&&e.contact&&e.contact.date_of_birth},date:e=>e.contact.date_of_birth,dhis:{dataElement:'kB0ZBFisE0e'}},{id:'active-pregnancies',type:'count',icon:'icon-pregnancy',goal:-1,translation_key:'targets.anc.active_pregnancies.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return s(e,t)},date:'now',idType:'contact'},{id:'active-pregnancies-1+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_1p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>0},date:'now',idType:'contact'},{id:'facility-deliveries',type:'percent',icon:'icon-mother-child',goal:-1,translation_key:'targets.anc.facility_deliveries.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['delivery'],appliesIf:function(e,t){return p(t,'delivery_outcome.delivery_place')},passesIf:function(e,t){return'health_facility'===p(t,'delivery_outcome.delivery_place')},date:'now',idType:'contact',dhis:{dataElement:'e22tIwy1nKR',categoryOptionCombo:'HllvX50cXC0',attributeOptionCombo:'HllvX50cXC0'}},{id:'active-pregnancies-4+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_4p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>3},date:'now',idType:'contact'},{id:'active-pregnancies-8+-contacts',type:'count',icon:'icon-follow-up',goal:-1,translation_key:'targets.anc.active_pregnancies_8p_contacts.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return 1+(o(e,t).length||0)+(c(e,t)||0)>7},date:'now',idType:'contact'}]},991(e,t,n){const r=n(190),{MAX_DAYS_IN_PREGNANCY:i,today:o,getNewestPregnancyTimestamp:a,getNewestDeliveryTimestamp:s,isAlive:c,isFormArraySubmittedInWindow:p,getDateISOLocal:l,getTimeForMidnight:d,isDeliveryForm:_,getMostRecentLMPDateForPregnancy:u,addDays:f,getRecentANCVisitWithEvent:g,isPregnancyTaskMuted:y,getField:m}=r,v=(e,t,n)=>({id:`pregnancy-home-visit-week${e}`,start:t,end:n,dueDate:function(t,n,r){const i=u(n,r);return f(i||r.reported_date,7*e)}});function h(e,t,n,r){if(t.reported_date=o},resolvedIf:h,actions:[{type:'report',form:'pregnancy_home_visit',label:'Pregnancy home visit'}],events:[...Array(21).keys()].map((e=>v(2*(e+1),6,7)))},{name:'anc.facility_reminder',icon:'icon-pregnancy',title:'task.anc.facility_reminder.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit'],appliesIf:function(e,t){return m(t,'t_pregnancy_follow_up_date')},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_facility_visit_reminder'],i,o)},actions:[{type:'report',form:'pregnancy_facility_visit_reminder',label:'Pregnancy facility visit reminder',modifyContent:function(e,t,n){e.source_visit_date=m(n,'t_pregnancy_follow_up_date')}}],events:[{id:'pregnancy-facility-visit-reminder',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_pregnancy_follow_up_date'))}}]},{name:'anc.pregnancy_danger_sign_followup',icon:'icon-pregnancy-danger',title:'task.anc.pregnancy_danger_sign_followup.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregnancy_danger_sign_follow_up'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_danger_sign_follow_up'],i,o)},actions:[{type:'report',form:'pregnancy_danger_sign_follow_up'}],events:[{id:'pregnancy-danger-sign-follow-up',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'anc.delivery',icon:'icon-mother-child',title:'task.anc.delivery.title',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){const n=u(e,t);return n&&f(n,336)>=o&&c(e)},resolvedIf:function(e,t,n,r){if(g(e,t,'abortion')||g(e,t,'miscarriage'))return!0;if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['delivery'],i,o)},actions:[{type:'report',form:'delivery'}],events:[{id:'delivery-reminder',start:28,end:42,dueDate:function(e,t,n){return f(u(t,n),i)}}]},{name:'pnc.danger_sign_followup_mother',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_mother.title',appliesTo:'reports',appliesToType:['delivery','pnc_danger_sign_follow_up_mother'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_mother'],i,o)},actions:[{type:'report',form:'pnc_danger_sign_follow_up_mother',modifyContent:function(e,t,n){_(n)?e.delivery_uuid=n._id:e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-mother',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'pnc.danger_sign_followup_baby.from_contact',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e.contact&&'yes'===e.contact.t_danger_signs_referral_follow_up&&c(e)},resolvedIf:function(e,t,n,r){const i=Math.max(f(r,-n.start).getTime(),e.contact.reported_date),o=f(r,n.end).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t){e.delivery_uuid=t.contact.created_by_doc}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t){return l(t.contact.t_danger_signs_referral_follow_up_date)}}]},{name:'pnc.danger_sign_followup_baby.from_report',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'reports',appliesToType:['pnc_danger_sign_follow_up_baby'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t,n){e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]}]}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}var r=n(991),i=n(931),o=n(85);n(945)(i,c,Utils,Target,emit),o(r,c,Utils,Task,emit),emit('_complete',{_id:!0})})();", "isDeclarative": true, "targets": { "enabled": true, diff --git a/ddocs/medic-db/medic-client/views/docs_by_id_lineage/map.js b/ddocs/medic-db/medic-client/views/docs_by_id_lineage/map.js deleted file mode 100644 index c87b7d182f8..00000000000 --- a/ddocs/medic-db/medic-client/views/docs_by_id_lineage/map.js +++ /dev/null @@ -1,20 +0,0 @@ -function(doc) { - - var emitLineage = function(contact, depth) { - while (contact && contact._id) { - emit([ doc._id, depth++ ], { _id: contact._id }); - contact = contact.parent; - } - }; - - var types = [ 'contact', 'district_hospital', 'health_center', 'clinic', 'person' ]; - - if (types.indexOf(doc.type) !== -1) { - // contact - emitLineage(doc, 0); - } else if (doc.type === 'data_record' && doc.form) { - // report - emit([ doc._id, 0 ]); - emitLineage(doc.contact, 1); - } -} diff --git a/shared-libs/cht-datasource/src/local/libs/lineage.ts b/shared-libs/cht-datasource/src/local/libs/lineage.ts index 5c53ab7e326..c32f2ed9e5b 100644 --- a/shared-libs/cht-datasource/src/local/libs/lineage.ts +++ b/shared-libs/cht-datasource/src/local/libs/lineage.ts @@ -15,7 +15,7 @@ import { Nullable } from '../../libs/core'; import { Doc } from '../../libs/doc'; -import { getDocsByIds, queryDocsByRange } from './doc'; +import { getDocsByIds } from './doc'; import logger from '@medic/logger'; import lineageFactory from '@medic/lineage'; import * as Report from '../../report'; @@ -27,14 +27,41 @@ import { InvalidArgumentError } from '../../libs/error'; import contactTypeUtils from '@medic/contact-types-utils'; import { isEqual } from 'lodash'; +const getParentIds = (doc: Doc): string[] => { + const parentIds: string[] = []; + let current: unknown = doc.type === 'data_record' ? doc.contact : doc.parent; + while (isRecord(current)) { + if (typeof current._id === 'string') { + parentIds.push(current._id); + } + current = current.parent; + } + return parentIds; +}; + /** * Returns the identified document along with the parent documents recorded for its lineage. The returned array is * sorted such that the identified document is the first element and the parent documents are in order of lineage. * @internal */ export const getLineageDocsById = (medicDb: PouchDB.Database): (id: string) => Promise[]> => { - const fn = queryDocsByRange(medicDb, 'medic-client/docs_by_id_lineage'); - return (id: string) => fn([id], [id, {}]); + const getMedicDocsById = getDocsByIds(medicDb); + return async (id: string) => { + try { + const doc = await medicDb.get(id); + const parentIds = getParentIds(doc); + if (parentIds.length === 0) { + return [doc]; + } + const ancestors = await getMedicDocsById(parentIds); + return [doc, ...ancestors]; + } catch (err: unknown) { + if ((err as PouchDB.Core.Error).status === 404) { + return []; + } + throw err; + } + }; }; /** @internal */ diff --git a/shared-libs/cht-datasource/test/local/libs/doc.spec.ts b/shared-libs/cht-datasource/test/local/libs/doc.spec.ts index 44fb2385280..db7e37f0919 100644 --- a/shared-libs/cht-datasource/test/local/libs/doc.spec.ts +++ b/shared-libs/cht-datasource/test/local/libs/doc.spec.ts @@ -245,11 +245,11 @@ describe('local doc lib', () => { }); isDoc.returns(true); - const result = await queryDocsByRange(db, 'medic-client/docs_by_id_lineage')(doc0._id, doc1._id); + const result = await queryDocsByRange(db, 'medic-client/contacts_by_type')(doc0._id, doc1._id); expect(result).to.deep.equal([doc0, doc1, doc2]); - expect(dbQuery.calledOnceWithExactly('medic-client/docs_by_id_lineage', { + expect(dbQuery.calledOnceWithExactly('medic-client/contacts_by_type', { include_docs: true, startkey: doc0._id, endkey: doc1._id, @@ -271,10 +271,10 @@ describe('local doc lib', () => { }); isDoc.returns(true); - const result = await queryDocsByRange(db, 'medic-client/docs_by_id_lineage')(doc0._id, doc2._id, limit, skip); + const result = await queryDocsByRange(db, 'medic-client/contacts_by_type')(doc0._id, doc2._id, limit, skip); expect(result).to.deep.equal([doc0, null, doc2]); - expect(dbQuery.calledOnceWithExactly('medic-client/docs_by_id_lineage', { + expect(dbQuery.calledOnceWithExactly('medic-client/contacts_by_type', { startkey: doc0._id, endkey: doc2._id, include_docs: true, @@ -291,10 +291,10 @@ describe('local doc lib', () => { }); isDoc.returns(false); - const result = await queryDocsByRange(db, 'medic-client/docs_by_id_lineage')(doc0._id, doc0._id, limit, skip); + const result = await queryDocsByRange(db, 'medic-client/contacts_by_type')(doc0._id, doc0._id, limit, skip); expect(result).to.deep.equal([null]); - expect(dbQuery.calledOnceWithExactly('medic-client/docs_by_id_lineage', { + expect(dbQuery.calledOnceWithExactly('medic-client/contacts_by_type', { startkey: doc0._id, endkey: doc0._id, include_docs: true, diff --git a/shared-libs/cht-datasource/test/local/libs/lineage.spec.ts b/shared-libs/cht-datasource/test/local/libs/lineage.spec.ts index 9312ef26632..895aee76bd9 100644 --- a/shared-libs/cht-datasource/test/local/libs/lineage.spec.ts +++ b/shared-libs/cht-datasource/test/local/libs/lineage.spec.ts @@ -30,18 +30,26 @@ describe('local lineage lib', () => { it('getLineageDocsById', async () => { const uuid = '123'; - const queryFn = sinon.stub().resolves([]); - const queryDocsByRange = sinon - .stub(LocalDoc, 'queryDocsByRange') - .returns(queryFn); - const medicDb = { hello: 'world' } as unknown as PouchDB.Database; + const doc = { _id: uuid, parent: { _id: 'parent1' } }; + const parentDoc = { _id: 'parent1' }; + medicGet.resolves(doc); + const getDocsByIdsInner = sinon.stub().resolves([parentDoc]); + const getDocsByIdsOuter = sinon.stub(LocalDoc, 'getDocsByIds').returns(getDocsByIdsInner); const fn = Lineage.getLineageDocsById(medicDb); const result = await fn(uuid); + expect(result).to.deep.equal([doc, parentDoc]); + expect(medicGet.calledOnceWithExactly(uuid)).to.be.true; + expect(getDocsByIdsOuter.calledOnceWithExactly(medicDb)).to.be.true; + expect(getDocsByIdsInner.calledOnceWithExactly(['parent1'])).to.be.true; + }); + + it('getLineageDocsById handles 404', async () => { + medicGet.rejects({ status: 404 }); + const fn = Lineage.getLineageDocsById(medicDb); + const result = await fn('missing'); expect(result).to.deep.equal([]); - expect(queryDocsByRange.calledOnceWithExactly(medicDb, 'medic-client/docs_by_id_lineage')).to.be.true; - expect(queryFn.calledOnceWithExactly([uuid], [uuid, {}])).to.be.true; }); describe('getPrimaryContactIds', () => { diff --git a/shared-libs/lineage/src/hydration.js b/shared-libs/lineage/src/hydration.js index 33ee9c0547f..275106d54e3 100644 --- a/shared-libs/lineage/src/hydration.js +++ b/shared-libs/lineage/src/hydration.js @@ -229,16 +229,25 @@ module.exports = function(Promise, DB) { }; const fetchLineageById = function(id) { - const options = { - startkey: [id], - endkey: [id, {}], - include_docs: true - }; - return DB.query('medic-client/docs_by_id_lineage', options) - .then(function(result) { - return result.rows.map(function(row) { - return row.doc; + // The lineage of a document is recorded on the document itself: the parent chain for a contact, or the contact's + // parent chain for a report. Fetch the document, then fetch its ancestors by id, preserving lineage order. + return DB.get(id) + .then(function(doc) { + const startParent = utils.isReport(doc) ? doc.contact : doc.parent; + const parentIds = extractParentIds(startParent); + if (!parentIds.length) { + return [doc]; + } + return fetchDocs(parentIds).then(function(ancestors) { + const ancestorsById = new Map(ancestors.map(ancestor => [ancestor._id, ancestor])); + return [doc, ...parentIds.map(parentId => ancestorsById.get(parentId))]; }); + }) + .catch(function(err) { + if (err.status === 404) { + return []; + } + throw err; }); }; diff --git a/shared-libs/lineage/test/hydration.spec.js b/shared-libs/lineage/test/hydration.spec.js index 6da39b4a5ef..f75e383a27a 100644 --- a/shared-libs/lineage/test/hydration.spec.js +++ b/shared-libs/lineage/test/hydration.spec.js @@ -24,15 +24,15 @@ describe('Lineage', function() { describe('fetchLineageById', function() { it('queries db with correct parameters', function() { - query.resolves({ rows: [] }); + get.resolves({ _id: 'banana', parent: { _id: 'apple' } }); + allDocs.resolves({ rows: [{ doc: { _id: 'apple' } }] }); const id = 'banana'; return lineage.fetchLineageById(id).then(() => { - chai.expect(query.callCount).to.equal(1); - chai.expect(query.getCall(0).args[0]).to.equal('medic-client/docs_by_id_lineage'); - chai.expect(query.getCall(0).args[1].startkey).to.deep.equal([ id ]); - chai.expect(query.getCall(0).args[1].endkey).to.deep.equal([ id, {} ]); - chai.expect(query.getCall(0).args[1].include_docs).to.deep.equal(true); + chai.expect(get.callCount).to.equal(1); + chai.expect(get.getCall(0).args[0]).to.equal('banana'); + chai.expect(allDocs.callCount).to.equal(1); + chai.expect(allDocs.getCall(0).args[0]).to.deep.equal({ keys: ['apple'], include_docs: true }); }); }); }); @@ -164,7 +164,6 @@ describe('Lineage', function() { describe('fetchHydratedDoc', function() { it('supports callback as second argument', function(done) { - query.resolves({ rows: [] }); get.resolves({ _id: 'a', type: 'person' }); lineage.fetchHydratedDoc('a', function(err, result) { @@ -175,7 +174,7 @@ describe('Lineage', function() { }); it('passes error to callback', function(done) { - query.rejects(new Error('db fail')); + get.rejects(new Error('db fail')); lineage.fetchHydratedDoc('a', function(err) { chai.expect(err.message).to.equal('db fail'); @@ -184,7 +183,7 @@ describe('Lineage', function() { }); it('throws when lineage is empty and throwWhenMissingLineage is true', function() { - query.resolves({ rows: [] }); + get.rejects({ status: 404 }); return lineage.fetchHydratedDoc('a', { throwWhenMissingLineage: true }) .then(() => chai.expect.fail('should have thrown')) @@ -205,7 +204,7 @@ describe('Lineage', function() { it('throws non-404 errors for single doc', function() { const err = new Error('server error'); err.status = 500; - query.rejects(err); + get.rejects(err); return lineage.fetchHydratedDocs(['a']) .then(() => chai.expect.fail('should have thrown')) diff --git a/tests/integration/api/server.spec.js b/tests/integration/api/server.spec.js index 1f8b2ee87f8..690303ca085 100644 --- a/tests/integration/api/server.spec.js +++ b/tests/integration/api/server.spec.js @@ -276,9 +276,14 @@ describe('server', () => { const reqID = getReqId(apiLogs[0]); const haproxyRequests = haproxyLogs.filter(entry => getReqId(entry) === reqID); - expect(haproxyRequests.length).to.equal(2); + // Request count depends on whether the doc has ancestors: + // _session + DB.get (2) OR _session + DB.get + _all_docs (3) + expect(haproxyRequests.length).to.be.at.least(2); expect(haproxyRequests[0]).to.include('_session'); - expect(haproxyRequests[1]).to.include('_design/medic-client/_view/docs_by_id_lineage'); + const hasDbGetOrPost = haproxyRequests.some(r => { + return r.includes(constants.USER_CONTACT_ID) || r.includes('_all_docs'); + }); + expect(hasDbGetOrPost).to.be.true; }); it('should propagate ID via couch-request', async () => { diff --git a/webapp/tests/karma/ts/services/lineage-model-generator.service.spec.ts b/webapp/tests/karma/ts/services/lineage-model-generator.service.spec.ts index 302a7697d40..ed0b5af9176 100644 --- a/webapp/tests/karma/ts/services/lineage-model-generator.service.spec.ts +++ b/webapp/tests/karma/ts/services/lineage-model-generator.service.spec.ts @@ -10,14 +10,16 @@ describe('LineageModelGenerator service', () => { let service; let dbQuery; let dbAllDocs; + let dbGet; beforeEach(() => { dbQuery = sinon.stub(); dbAllDocs = sinon.stub(); + dbGet = sinon.stub(); TestBed.configureTestingModule({ providers: [ - { provide: DbService, useValue: { get: () => ({ query: dbQuery, allDocs: dbAllDocs }) }}, + { provide: DbService, useValue: { get: () => ({ query: dbQuery, allDocs: dbAllDocs, get: dbGet }) }}, ], }); @@ -31,7 +33,7 @@ describe('LineageModelGenerator service', () => { describe('contact', () => { it('handles not found', done => { - dbQuery.resolves({ rows: [] }); + dbGet.rejects({ status: 404 }); service.contact('a') .then(() => { done(new Error('expected error to be thrown')); @@ -45,10 +47,7 @@ describe('LineageModelGenerator service', () => { it('handles no lineage', () => { const contact = { _id: 'a', _rev: '1' }; - dbQuery.resolves({ - rows: [ - { doc: contact } - ] }); + dbGet.resolves(contact); return service.contact('a').then(model => { expect(model._id).to.equal('a'); expect(model.doc).to.deep.equal(contact); @@ -56,23 +55,19 @@ describe('LineageModelGenerator service', () => { }); it('binds lineage', () => { - const contact = { _id: 'a', _rev: '1' }; - const parent = { _id: 'b', _rev: '1' }; + const contact = { _id: 'a', _rev: '1', parent: { _id: 'b', parent: { _id: 'c' } } }; + const parent = { _id: 'b', _rev: '1', parent: { _id: 'c' } }; const grandparent = { _id: 'c', _rev: '1' }; - dbQuery.resolves({ + dbGet.withArgs('a').resolves(contact); + dbAllDocs.withArgs({ keys: ['b', 'c'], include_docs: true }).resolves({ rows: [ - { doc: contact }, { doc: parent }, { doc: grandparent } ] }); return service.contact('a').then(model => { - expect(dbQuery.callCount).to.equal(1); - expect(dbQuery.args[0][0]).to.equal('medic-client/docs_by_id_lineage'); - expect(dbQuery.args[0][1]).to.deep.equal({ - startkey: [ 'a' ], - endkey: [ 'a', {} ], - include_docs: true - }); + expect(dbGet.callCount).to.equal(1); + expect(dbAllDocs.callCount).to.equal(1); + expect(dbAllDocs.args[0][0].keys).to.deep.equal(['b', 'c']); expect(model._id).to.equal('a'); expect(model.doc).to.deep.equal(contact); expect(model.lineage).to.deep.equal([ parent, grandparent ]); @@ -80,18 +75,18 @@ describe('LineageModelGenerator service', () => { }); it('binds contacts', () => { - const contact = { _id: 'a', _rev: '1', contact: { _id: 'd' } }; + const contact = { _id: 'a', _rev: '1', contact: { _id: 'd' }, parent: { _id: 'b', parent: { _id: 'c' } } }; const contactsContact = { _id: 'd', name: 'dave' }; - const parent = { _id: 'b', _rev: '1', contact: { _id: 'e' } }; + const parent = { _id: 'b', _rev: '1', contact: { _id: 'e' }, parent: { _id: 'c' } }; const parentsContact = { _id: 'e', name: 'eliza' }; const grandparent = { _id: 'c', _rev: '1' }; - dbQuery.resolves({ + dbGet.resolves(contact); + dbAllDocs.withArgs({ keys: ['b', 'c'], include_docs: true }).resolves({ rows: [ - { doc: contact }, { doc: parent }, { doc: grandparent } ] }); - dbAllDocs.resolves({ + dbAllDocs.withArgs({ keys: sinon.match.array.deepEquals(['d', 'e']), include_docs: true }).resolves({ rows: [ { doc: contactsContact }, { doc: parentsContact } @@ -104,25 +99,27 @@ describe('LineageModelGenerator service', () => { }); it('hydrates lineage contacts - #3812', () => { - const contact = { _id: 'a', _rev: '1', contact: { _id: 'x' } }; - const parent = { _id: 'b', _rev: '1', contact: { _id: 'd' } }; + const contact = { _id: 'a', _rev: '1', contact: { _id: 'x' }, parent: { _id: 'b', parent: { _id: 'c' } } }; + const parent = { _id: 'b', _rev: '1', contact: { _id: 'd' }, parent: { _id: 'c' } }; const grandparent = { _id: 'c', _rev: '1', contact: { _id: 'e' } }; const parentContact = { _id: 'd', name: 'donny' }; const grandparentContact = { _id: 'e', name: 'erica' }; - dbQuery.resolves({ + const xContact = { _id: 'x', name: 'xavier' }; + dbGet.resolves(contact); + dbAllDocs.withArgs({ keys: ['b', 'c'], include_docs: true }).resolves({ rows: [ - { doc: contact }, { doc: parent }, { doc: grandparent } ] }); - dbAllDocs.resolves({ + dbAllDocs.withArgs({ keys: sinon.match.array.deepEquals(['x', 'd', 'e']), include_docs: true }).resolves({ rows: [ + { doc: xContact }, { doc: parentContact }, { doc: grandparentContact } ] }); return service.contact('a').then(model => { - expect(dbAllDocs.callCount).to.equal(1); - expect(dbAllDocs.args[0][0]).to.deep.equal({ + expect(dbAllDocs.callCount).to.equal(2); + expect(dbAllDocs.args[1][0]).to.deep.equal({ keys: [ 'x', 'd', 'e' ], include_docs: true }); @@ -132,18 +129,18 @@ describe('LineageModelGenerator service', () => { }); it('should skip lineage contact hydration if requested', () => { - const contact = { _id: 'a', _rev: '1', contact: { _id: 'x' } }; - const parent = { _id: 'b', _rev: '1', contact: { _id: 'd' } }; + const contact = { _id: 'a', _rev: '1', contact: { _id: 'x' }, parent: { _id: 'b', parent: { _id: 'c' } } }; + const parent = { _id: 'b', _rev: '1', contact: { _id: 'd' }, parent: { _id: 'c' } }; const grandparent = { _id: 'c', _rev: '1', contact: { _id: 'e' } }; - dbQuery.resolves({ + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: [ - { doc: contact }, { doc: parent }, { doc: grandparent } ] }); return service.contact('a', { hydrate: false }).then(model => { - expect(dbAllDocs.callCount).to.equal(0); + expect(dbAllDocs.callCount).to.equal(1); // One for lineage, zero for contacts expect(model.doc.contact).to.deep.equal({ _id: 'x' }); expect(model.lineage[0].contact).to.deep.equal({ _id: 'd' }); expect(model.lineage[1].contact).to.deep.equal({ _id: 'e' }); @@ -152,7 +149,7 @@ describe('LineageModelGenerator service', () => { it('merges lineage when merge passed', () => { const contact = { _id: 'a', name: '1', parent: { _id: 'b', parent: { _id: 'c' } } }; - const parent = { _id: 'b', name: '2' }; + const parent = { _id: 'b', name: '2', parent: { _id: 'c' } }; const grandparent = { _id: 'c', name: '3' }; const expected = { _id: 'a', @@ -183,9 +180,9 @@ describe('LineageModelGenerator service', () => { } ] }; - dbQuery.resolves({ + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: [ - { doc: contact }, { doc: parent }, { doc: grandparent } ] }); @@ -197,8 +194,9 @@ describe('LineageModelGenerator service', () => { it('should merge lineage with undefined members', () => { const contact = { _id: 'a', name: '1', parent: { _id: 'b', parent: { _id: 'c', parent: { _id: 'd' } } } }; const parent = { _id: 'b', name: '2', parent: { _id: 'c', parent: { _id: 'd' } } }; - dbQuery.resolves({ rows: - [{ doc: contact, key: ['a', 0] }, { doc: parent, key: ['a', 1] }, { key: ['a', 2] }, { key: ['a', 3] }] + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: + [{ doc: parent, id: 'b' }, { id: 'c' }, { id: 'd' }] }); const expected = { _id: 'a', @@ -217,12 +215,12 @@ describe('LineageModelGenerator service', () => { it('should merge lineage with undefined members v2', () => { const contact = { _id: 'a', name: '1', parent: { _id: 'b', parent: { _id: 'c', parent: { _id: 'd' } } } }; const parent = { _id: 'b', name: '2', parent: { _id: 'c', parent: { _id: 'd' } } }; - dbQuery.resolves({ + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: [ - { doc: contact, key: ['a', 0] }, - { doc: parent, key: ['a', 1] }, - { key: ['a', 2] }, - { key: ['a', 3], doc: { _id: 'd', name: '4' } } + { doc: parent, id: 'b' }, + { id: 'c' }, + { id: 'd', doc: { _id: 'd', name: '4' } } ] }); const expected = { _id: 'a', @@ -267,9 +265,9 @@ describe('LineageModelGenerator service', () => { } ] }; - dbQuery.resolves({ + dbGet.resolves(contact); + dbAllDocs.resolves({ rows: [ - { doc: contact }, { doc: parent }, { doc: grandparent } ] }); @@ -282,7 +280,7 @@ describe('LineageModelGenerator service', () => { describe('report', () => { it('handles not found', done => { - dbQuery.resolves({ rows: [] }); + dbGet.rejects({ status: 404 }); service.report('a') .then(() => { done(new Error('expected error to be thrown')); @@ -296,10 +294,7 @@ describe('LineageModelGenerator service', () => { it('handles no lineage', () => { const report = { _id: 'a', _rev: '1' }; - dbQuery.resolves({ - rows: [ - { doc: report } - ] }); + dbGet.resolves(report); return service.report('a').then(model => { expect(model._id).to.equal('a'); expect(model.doc).to.deep.equal(report); @@ -311,9 +306,9 @@ describe('LineageModelGenerator service', () => { const contact = { _id: 'b', _rev: '1' }; const parent = { _id: 'c', _rev: '1' }; const grandparent = { _id: 'd', _rev: '1' }; - dbQuery.resolves({ + dbGet.withArgs('a').resolves(report); + dbAllDocs.resolves({ rows: [ - { doc: report }, { doc: contact }, { doc: parent }, { doc: grandparent } @@ -326,28 +321,33 @@ describe('LineageModelGenerator service', () => { }); it('hydrates lineage contacts - #3812', () => { - const report = { _id: 'a', _rev: '1', type: DOC_TYPES.DATA_RECORD, form: 'a', contact: { _id: 'x' } }; - const contact = { _id: 'b', _rev: '1', contact: { _id: 'y' } }; - const parent = { _id: 'c', _rev: '1', contact: { _id: 'e' } }; + const reportContact = { _id: 'x', parent: { _id: 'c', parent: { _id: 'd' } } }; + const report = { _id: 'a', _rev: '1', type: DOC_TYPES.DATA_RECORD, form: 'a', contact: reportContact }; + const contact = { _id: 'x', _rev: '1', contact: { _id: 'y' }, parent: { _id: 'c' } }; + const parent = { _id: 'c', _rev: '1', contact: { _id: 'e' }, parent: { _id: 'd' } }; const grandparent = { _id: 'd', _rev: '1', contact: { _id: 'f' } }; const parentContact = { _id: 'e', name: 'erica' }; const grandparentContact = { _id: 'f', name: 'frank' }; - dbQuery.resolves({ + const xContact = { _id: 'x', name: 'xavier' }; + const yContact = { _id: 'y', name: 'yvonne' }; + dbGet.resolves(report); + dbAllDocs.withArgs(sinon.match({ keys: ['x', 'c', 'd'], include_docs: true })).resolves({ rows: [ - { doc: report }, { doc: contact }, { doc: parent }, { doc: grandparent } ] }); - dbAllDocs.resolves({ + dbAllDocs.withArgs(sinon.match({ keys: ['y', 'e', 'f'], include_docs: true })).resolves({ rows: [ + { doc: xContact }, + { doc: yContact }, { doc: parentContact }, { doc: grandparentContact } ] }); return service.report('a').then(model => { - expect(dbAllDocs.callCount).to.equal(1); - expect(dbAllDocs.args[0][0]).to.deep.equal({ - keys: [ 'x', 'y', 'e', 'f' ], + expect(dbAllDocs.callCount).to.equal(2); + expect(dbAllDocs.args[1][0]).to.deep.equal({ + keys: [ 'y', 'e', 'f' ], include_docs: true }); expect(model.doc.contact.parent.contact).to.deep.equal(parentContact); diff --git a/webapp/tests/mocha/unit/views/docs_by_id_lineage.spec.js b/webapp/tests/mocha/unit/views/docs_by_id_lineage.spec.js deleted file mode 100644 index cf88040d14e..00000000000 --- a/webapp/tests/mocha/unit/views/docs_by_id_lineage.spec.js +++ /dev/null @@ -1,198 +0,0 @@ -const expect = require('chai').expect; -const utils = require('./utils'); -const map = utils.loadView('medic-db', 'medic-client', 'docs_by_id_lineage'); -const { DOC_TYPES, CONTACT_TYPES } = require('@medic/constants'); - -describe('docs_by_id_lineage view', () => { - beforeEach(() => { - map.reset(); - }); - describe('data_record lineage', () => { - it('does not emit if doc is not a report', () => { - const doc = { - _id: 'messsage', - type: DOC_TYPES.DATA_RECORD, - sms_message: { } - }; - - const result = map(doc, true); - expect(result.length).to.equal(0); - }); - it('emits report document for depth 0', () => { - const doc = { - _id: 'report', - type: DOC_TYPES.DATA_RECORD, - form: 'form', - }; - - const result = map(doc, true); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal({ key: [ 'report', 0 ], value: undefined }); - }); - - it('emits contact lineage for depth 1+', () => { - const doc = { - _id: 'report', - type: DOC_TYPES.DATA_RECORD, - form: 'form', - contact: { - _id: 'contact1', - parent: { - _id: 'contact2', - parent: { - _id: 'contact3' - } - } - } - }; - const result = map(doc, true); - expect(result.length).to.equal(4); - expect(result[0]).to.deep.equal({ key: [ 'report', 0 ], value: undefined }); - expect(result[1]).to.deep.equal({ key: [ 'report', 1 ], value: { _id: 'contact1' }}); - expect(result[2]).to.deep.equal({ key: [ 'report', 2 ], value: { _id: 'contact2' }}); - expect(result[3]).to.deep.equal({ key: [ 'report', 3 ], value: { _id: 'contact3' }}); - }); - - it('does not emit lineage for empty contact parents', () => { - const doc1 = { - _id: 'report1', - type: DOC_TYPES.DATA_RECORD, - form: 'form', - contact: {} - }; - const result1 = map(doc1, true); - expect(result1.length).to.equal(1); - expect(result1[0]).to.deep.equal({ key: [ 'report1', 0 ], value: undefined }); - - const doc2 = { - _id: 'report2', - type: DOC_TYPES.DATA_RECORD, - form: 'form', - contact: { - _id: 'contact1', - parent: {} - } - }; - - map.reset(); - const result2 = map(doc2, true); - expect(result2.length).to.equal(2); - expect(result2[0]).to.deep.equal({ key: [ 'report2', 0 ], value: undefined }); - expect(result2[1]).to.deep.equal({ key: [ 'report2', 1 ], value: { _id: 'contact1' }}); - - const doc3 = { - _id: 'report3', - type: DOC_TYPES.DATA_RECORD, - form: 'form', - contact: { - _id: 'contact1', - parent: { - _id: 'contact2', - parent: {} - } - } - }; - map.reset(); - const result3 = map(doc3, true); - expect(result3.length).to.equal(3); - expect(result3[0]).to.deep.equal({ key: [ 'report3', 0 ], value: undefined }); - expect(result3[1]).to.deep.equal({ key: [ 'report3', 1 ], value: { _id: 'contact1' }}); - expect(result3[2]).to.deep.equal({ key: [ 'report3', 2 ], value: { _id: 'contact2' }}); - }); - }); - - describe('contacts lineage', () => { - it('emits lineage for type `person`, `clinic`, `health_center` and `district_hospital`', () => { - const person = { _id: 'person', type: 'person' }; - const result = map(person, true); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal({ key: [ 'person', 0 ], value: { _id: 'person' }}); - - map.reset(); - const clinic = { _id: 'clinic', type: CONTACT_TYPES.CLINIC }; - const resultClinic = map(clinic, true); - expect(resultClinic.length).to.equal(1); - expect(resultClinic[0]).to.deep.equal({ key: [ CONTACT_TYPES.CLINIC, 0 ], value: { _id: 'clinic' }}); - - map.reset(); - const healthCenter = { _id: 'healthCenter', type: 'health_center' }; - const resultHealthCenter = map(healthCenter, true); - expect(resultHealthCenter.length).to.equal(1); - expect(resultHealthCenter[0]).to.deep.equal({ key: [ 'healthCenter', 0 ], value: { _id: 'healthCenter' }}); - - map.reset(); - const districtHospital = { _id: 'districtHospital', type: CONTACT_TYPES.DISTRICT_HOSPITAL }; - const resultdistrictHospital = map(districtHospital, true); - expect(resultdistrictHospital.length).to.equal(1); - expect(resultdistrictHospital[0]) - .to.deep.equal({ key: [ 'districtHospital', 0 ], value: { _id: 'districtHospital' }}); - }); - - it('emits full lineage', () => { - const checkLineage = (result, key) => { - if (key > 0) { - expect(result).to.deep.equal({ key: [ 'person', key ], value: { _id: `parent${key}` }}); - } else { - expect(result).to.deep.equal({ key: [ 'person', 0 ], value: { _id: 'person' }}); - } - }; - for (let depth = 1; depth < 10; depth++) { - const doc = { _id: 'person', type: 'person', parent: {} }; - let currentParent = doc.parent; - for (let i = 1; i <= depth; i++) { - currentParent._id = `parent${i}`; - currentParent.parent = {}; - currentParent = currentParent.parent; - } - - map.reset(); - const results = map(doc, true); - expect(results.length).to.equal(depth + 1); - results.forEach(checkLineage); - } - }); - - it('does not emit lineage for empty parents', () => { - const doc1 = { - _id: 'contact1', - type: 'person', - parent: {} - }; - const result1 = map(doc1, true); - expect(result1.length).to.equal(1); - expect(result1[0]).to.deep.equal({ key: [ 'contact1', 0 ], value: { _id: 'contact1'} }); - - const doc2 = { - _id: 'contact2', - type: 'person', - parent: { - _id: 'contact3', - parent: {} - } - }; - map.reset(); - const result2 = map(doc2, true); - expect(result2.length).to.equal(2); - expect(result2[0]).to.deep.equal({ key: [ 'contact2', 0 ], value: { _id: 'contact2' }}); - expect(result2[1]).to.deep.equal({ key: [ 'contact2', 1 ], value: { _id: 'contact3' }}); - - const doc3 = { - _id: 'contact3', - type: 'person', - parent: { - _id: 'contact4', - parent: { - _id: 'contact5', - parent: {} - } - } - }; - map.reset(); - const result3 = map(doc3, true); - expect(result3.length).to.equal(3); - expect(result3[0]).to.deep.equal({ key: [ 'contact3', 0 ], value: { _id: 'contact3' }}); - expect(result3[1]).to.deep.equal({ key: [ 'contact3', 1 ], value: { _id: 'contact4' }}); - expect(result3[2]).to.deep.equal({ key: [ 'contact3', 2 ], value: { _id: 'contact5' }}); - }); - }); -}); From 820b7dbf46bb3d5eb0f8bc028a80ba8600e98dbf Mon Sep 17 00:00:00 2001 From: Tom Wier Date: Tue, 4 Aug 2026 14:56:56 +0300 Subject: [PATCH 2/3] fix(#10748): reverting changes to app_settings --- config/default/app_settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default/app_settings.json b/config/default/app_settings.json index 01117c717ed..1d91b088dbb 100644 --- a/config/default/app_settings.json +++ b/config/default/app_settings.json @@ -365,9 +365,9 @@ "person": true } ], - "contact_summary": "var ContactSummary = {}; /*! For license information please see contact-summary.js.LICENSE.txt */\n!function(e,t){if('object'==typeof exports&&'object'==typeof module)module.exports=t();else if('function'==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)('object'==typeof exports?exports:e)[r]=n[r]}}(ContactSummary,(()=>(()=>{var e={597(e){function t(e){return e?Array.isArray(e)?e:[e]:[]}function n(e,t){switch(typeof e){case'undefined':return!0;case'function':return e(t);default:return e}}function r(e,t,r){if(!n(e.appliesIf,r))return;function i(e,t,n){switch(typeof e[n]){case'undefined':return;case'function':t[n]=e[n](r);break;default:t[n]=e[n]}}var s='function'==typeof e.fields?e.fields(r):e.fields.filter((function(e){return n(e.appliesIf,r)})).map((function(e){var t={};return i(e,t,'label'),i(e,t,'value'),i(e,t,'translate'),i(e,t,'filter'),i(e,t,'width'),i(e,t,'icon'),e.context&&(t.context={},i(e.context,t.context,'count'),i(e.context,t.context,'total')),t}));e.modifyContext&&e.modifyContext(t,r);const a={label:e.label,fields:s};return void 0!==e.collapsed&&(a.collapsed=e.collapsed),a}e.exports=function(e,n,i){var s=e.fields||[],a=e.context||{},o=e.cards||[],l=n&&('contact'===n.type?n.contact_type:n.type),u={cards:[],fields:s.filter((function(e){var n=t(e.appliesToType),r=n.filter((function(e){return e&&'!'===e.charAt(0)}));if((0===n.length||n.includes(l)||r.length>0&&!r.includes('!'+l))&&(!e.appliesIf||e.appliesIf()))return delete e.appliesToType,delete e.appliesIf,!0}))};return o.forEach((function(e){var n,s,o,d,c=t(e.appliesToType);if(c.includes('report')&&c.length>1)throw new Error('You cannot set appliesToType to an array which includes the type \\'report\\' and another type.');if(c.includes('report'))for(n=0;n0)return;(o=r(e,a))&&u.cards.push(o)}})),u.context=a,u}},344(e,t,n){var r=n(972),i=n(597);e.exports=i(r,contact,reports)},420(e,t,n){(e=n.nmd(e)).exports=function(){'use strict';var t,n;function r(){return t.apply(null,arguments)}function i(e){t=e}function s(e){return e instanceof Array||'[object Array]'===Object.prototype.toString.call(e)}function a(e){return null!=e&&'[object Object]'===Object.prototype.toString.call(e)}function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){if(Object.getOwnPropertyNames)return 0===Object.getOwnPropertyNames(e).length;var t;for(t in e)if(o(e,t))return!1;return!0}function u(e){return void 0===e}function d(e){return'number'==typeof e||'[object Number]'===Object.prototype.toString.call(e)}function c(e){return e instanceof Date||'[object Date]'===Object.prototype.toString.call(e)}function h(e,t){var n,r=[],i=e.length;for(n=0;n>>0;for(t=0;t0)for(n=0;n=0?n?'+':'':'-')+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}var U=/(\\[[^\\[]*\\])|(\\\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,H=/(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})/g,A={},E={};function L(e,t,n,r){var i=r;'string'==typeof r&&(i=function(){return this[r]()}),e&&(E[e]=i),t&&(E[t[0]]=function(){return F(i.apply(this,arguments),t[1],t[2])}),n&&(E[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function V(e){return e.match(/\\[[\\s\\S]/)?e.replace(/^\\[|\\]$/g,''):e.replace(/\\\\/g,'')}function I(e){var t,n,r=e.match(U);for(t=0,n=r.length;t=0&&H.test(e);)e=e.replace(H,r),H.lastIndex=0,n-=1;return e}var Z={LTS:'h:mm:ss A',LT:'h:mm A',L:'MM/DD/YYYY',LL:'MMMM D, YYYY',LLL:'MMMM D, YYYY h:mm A',LLLL:'dddd, MMMM D, YYYY h:mm A'};function z(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.match(U).map((function(e){return'MMMM'===e||'MM'===e||'DD'===e||'dddd'===e?e.slice(1):e})).join(''),this._longDateFormat[e])}var q='Invalid date';function $(){return this._invalidDate}var B='%d',J=/\\d{1,2}/;function Q(e){return this._ordinal.replace('%d',e)}var X={future:'in %s',past:'%s ago',s:'a few seconds',ss:'%d seconds',m:'a minute',mm:'%d minutes',h:'an hour',hh:'%d hours',d:'a day',dd:'%d days',w:'a week',ww:'%d weeks',M:'a month',MM:'%d months',y:'a year',yy:'%d years'};function K(e,t,n,r){var i=this._relativeTime[n];return x(i)?i(e,t,n,r):i.replace(/%d/i,e)}function ee(e,t){var n=this._relativeTime[e>0?'future':'past'];return x(n)?n(t):n.replace(/%s/i,t)}var te={D:'date',dates:'date',date:'date',d:'day',days:'day',day:'day',e:'weekday',weekdays:'weekday',weekday:'weekday',E:'isoWeekday',isoweekdays:'isoWeekday',isoweekday:'isoWeekday',DDD:'dayOfYear',dayofyears:'dayOfYear',dayofyear:'dayOfYear',h:'hour',hours:'hour',hour:'hour',ms:'millisecond',milliseconds:'millisecond',millisecond:'millisecond',m:'minute',minutes:'minute',minute:'minute',M:'month',months:'month',month:'month',Q:'quarter',quarters:'quarter',quarter:'quarter',s:'second',seconds:'second',second:'second',gg:'weekYear',weekyears:'weekYear',weekyear:'weekYear',GG:'isoWeekYear',isoweekyears:'isoWeekYear',isoweekyear:'isoWeekYear',w:'week',weeks:'week',week:'week',W:'isoWeek',isoweeks:'isoWeek',isoweek:'isoWeek',y:'year',years:'year',year:'year'};function ne(e){return'string'==typeof e?te[e]||te[e.toLowerCase()]:void 0}function re(e){var t,n,r={};for(n in e)o(e,n)&&(t=ne(n))&&(r[t]=e[n]);return r}var ie={date:9,day:11,weekday:11,isoWeekday:11,dayOfYear:4,hour:13,millisecond:16,minute:14,month:8,quarter:7,second:15,weekYear:1,isoWeekYear:1,week:5,isoWeek:5,year:1};function se(e){var t,n=[];for(t in e)o(e,t)&&n.push({unit:t,priority:ie[t]});return n.sort((function(e,t){return e.priority-t.priority})),n}var ae,oe=/\\d/,le=/\\d\\d/,ue=/\\d{3}/,de=/\\d{4}/,ce=/[+-]?\\d{6}/,he=/\\d\\d?/,fe=/\\d\\d\\d\\d?/,_e=/\\d\\d\\d\\d\\d\\d?/,me=/\\d{1,3}/,pe=/\\d{1,4}/,ye=/[+-]?\\d{1,6}/,ge=/\\d+/,ve=/[+-]?\\d+/,we=/Z|[+-]\\d\\d:?\\d\\d/gi,ke=/Z|[+-]\\d\\d(?::?\\d\\d)?/gi,De=/[+-]?\\d+(\\.\\d{1,3})?/,Me=/[0-9]{0,256}['a-z\\u00A0-\\u05FF\\u0700-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFF07\\uFF10-\\uFFEF]{1,256}|[\\u0600-\\u06FF\\/]{1,256}(\\s*?[\\u0600-\\u06FF]{1,256}){1,2}/i,Se=/^[1-9]\\d?/,Ye=/^([1-9]\\d|\\d)/;function be(e,t,n){ae[e]=x(t)?t:function(e,r){return e&&n?n:t}}function Oe(e,t){return o(ae,e)?ae[e](t._strict,t._locale):new RegExp(Te(e))}function Te(e){return xe(e.replace('\\\\','').replace(/\\\\(\\[)|\\\\(\\])|\\[([^\\]\\[]*)\\]|\\\\(.)/g,(function(e,t,n,r,i){return t||n||r||i})))}function xe(e){return e.replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g,'\\\\$&')}function Ne(e){return e<0?Math.ceil(e)||0:Math.floor(e)}function Pe(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=Ne(t)),n}ae={};var Re={};function Ce(e,t){var n,r,i=t;for('string'==typeof e&&(e=[e]),d(t)&&(i=function(e,n){n[t]=Pe(e)}),r=e.length,n=0;n68?1900:2e3)};var qe,$e=Je('FullYear',!0);function Be(){return Ue(this.year())}function Je(e,t){return function(n){return null!=n?(Xe(this,e,n),r.updateOffset(this,t),this):Qe(this,e)}}function Qe(e,t){if(!e.isValid())return NaN;var n=e._d,r=e._isUTC;switch(t){case'Milliseconds':return r?n.getUTCMilliseconds():n.getMilliseconds();case'Seconds':return r?n.getUTCSeconds():n.getSeconds();case'Minutes':return r?n.getUTCMinutes():n.getMinutes();case'Hours':return r?n.getUTCHours():n.getHours();case'Date':return r?n.getUTCDate():n.getDate();case'Day':return r?n.getUTCDay():n.getDay();case'Month':return r?n.getUTCMonth():n.getMonth();case'FullYear':return r?n.getUTCFullYear():n.getFullYear();default:return NaN}}function Xe(e,t,n){var r,i,s,a,o;if(e.isValid()&&!isNaN(n)){switch(r=e._d,i=e._isUTC,t){case'Milliseconds':return void(i?r.setUTCMilliseconds(n):r.setMilliseconds(n));case'Seconds':return void(i?r.setUTCSeconds(n):r.setSeconds(n));case'Minutes':return void(i?r.setUTCMinutes(n):r.setMinutes(n));case'Hours':return void(i?r.setUTCHours(n):r.setHours(n));case'Date':return void(i?r.setUTCDate(n):r.setDate(n));case'FullYear':break;default:return}s=n,a=e.month(),o=29!==(o=e.date())||1!==a||Ue(s)?o:28,i?r.setUTCFullYear(s,a,o):r.setFullYear(s,a,o)}}function Ke(e){return x(this[e=ne(e)])?this[e]():this}function et(e,t){if('object'==typeof e){var n,r=se(e=re(e)),i=r.length;for(n=0;n=0?(o=new Date(e+400,t,n,r,i,s,a),isFinite(o.getFullYear())&&o.setFullYear(e)):o=new Date(e,t,n,r,i,s,a),o}function vt(e){var t,n;return e<100&&e>=0?((n=Array.prototype.slice.call(arguments))[0]=e+400,t=new Date(Date.UTC.apply(null,n)),isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e)):t=new Date(Date.UTC.apply(null,arguments)),t}function wt(e,t,n){var r=7+t-n;return-(7+vt(e,0,r).getUTCDay()-t)%7+r-1}function kt(e,t,n,r,i){var s,a,o=1+7*(t-1)+(7+n-r)%7+wt(e,r,i);return o<=0?a=ze(s=e-1)+o:o>ze(e)?(s=e+1,a=o-ze(e)):(s=e,a=o),{year:s,dayOfYear:a}}function Dt(e,t,n){var r,i,s=wt(e.year(),t,n),a=Math.floor((e.dayOfYear()-s-1)/7)+1;return a<1?r=a+Mt(i=e.year()-1,t,n):a>Mt(e.year(),t,n)?(r=a-Mt(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function Mt(e,t,n){var r=wt(e,t,n),i=wt(e+1,t,n);return(ze(e)-r+i)/7}function St(e){return Dt(e,this._week.dow,this._week.doy).week}L('w',['ww',2],'wo','week'),L('W',['WW',2],'Wo','isoWeek'),be('w',he,Se),be('ww',he,le),be('W',he,Se),be('WW',he,le),We(['w','ww','W','WW'],(function(e,t,n,r){t[r.substr(0,1)]=Pe(e)}));var Yt={dow:0,doy:6};function bt(){return this._week.dow}function Ot(){return this._week.doy}function Tt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),'d')}function xt(e){var t=Dt(this,1,4).week;return null==e?t:this.add(7*(e-t),'d')}function Nt(e,t){return'string'!=typeof e?e:isNaN(e)?'number'==typeof(e=t.weekdaysParse(e))?e:null:parseInt(e,10)}function Pt(e,t){return'string'==typeof e?t.weekdaysParse(e)%7||7:isNaN(e)?null:e}function Rt(e,t){return e.slice(t,7).concat(e.slice(0,t))}L('d',0,'do','day'),L('dd',0,0,(function(e){return this.localeData().weekdaysMin(this,e)})),L('ddd',0,0,(function(e){return this.localeData().weekdaysShort(this,e)})),L('dddd',0,0,(function(e){return this.localeData().weekdays(this,e)})),L('e',0,0,'weekday'),L('E',0,0,'isoWeekday'),be('d',he),be('e',he),be('E',he),be('dd',(function(e,t){return t.weekdaysMinRegex(e)})),be('ddd',(function(e,t){return t.weekdaysShortRegex(e)})),be('dddd',(function(e,t){return t.weekdaysRegex(e)})),We(['dd','ddd','dddd'],(function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:p(n).invalidWeekday=e})),We(['d','e','E'],(function(e,t,n,r){t[r]=Pe(e)}));var Ct='Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),Wt='Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),Ft='Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),Ut=Me,Ht=Me,At=Me;function Et(e,t){var n=s(this._weekdays)?this._weekdays:this._weekdays[e&&!0!==e&&this._weekdays.isFormat.test(t)?'format':'standalone'];return!0===e?Rt(n,this._week.dow):e?n[e.day()]:n}function Lt(e){return!0===e?Rt(this._weekdaysShort,this._week.dow):e?this._weekdaysShort[e.day()]:this._weekdaysShort}function Vt(e){return!0===e?Rt(this._weekdaysMin,this._week.dow):e?this._weekdaysMin[e.day()]:this._weekdaysMin}function It(e,t,n){var r,i,s,a=e.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],r=0;r<7;++r)s=_([2e3,1]).day(r),this._minWeekdaysParse[r]=this.weekdaysMin(s,'').toLocaleLowerCase(),this._shortWeekdaysParse[r]=this.weekdaysShort(s,'').toLocaleLowerCase(),this._weekdaysParse[r]=this.weekdays(s,'').toLocaleLowerCase();return n?'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null}function Gt(e,t,n){var r,i,s;if(this._weekdaysParseExact)return It.call(this,e,t,n);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;r<7;r++){if(i=_([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp('^'+this.weekdays(i,'').replace('.','\\\\.?')+'$','i'),this._shortWeekdaysParse[r]=new RegExp('^'+this.weekdaysShort(i,'').replace('.','\\\\.?')+'$','i'),this._minWeekdaysParse[r]=new RegExp('^'+this.weekdaysMin(i,'').replace('.','\\\\.?')+'$','i')),this._weekdaysParse[r]||(s='^'+this.weekdays(i,'')+'|^'+this.weekdaysShort(i,'')+'|^'+this.weekdaysMin(i,''),this._weekdaysParse[r]=new RegExp(s.replace('.',''),'i')),n&&'dddd'===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&'ddd'===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&'dd'===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function jt(e){if(!this.isValid())return null!=e?this:NaN;var t=Qe(this,'Day');return null!=e?(e=Nt(e,this.localeData()),this.add(e-t,'d')):t}function Zt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,'d')}function zt(e){if(!this.isValid())return null!=e?this:NaN;if(null!=e){var t=Pt(e,this.localeData());return this.day(this.day()%7?t:t-7)}return this.day()||7}function qt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysStrictRegex:this._weekdaysRegex):(o(this,'_weekdaysRegex')||(this._weekdaysRegex=Ut),this._weekdaysStrictRegex&&e?this._weekdaysStrictRegex:this._weekdaysRegex)}function $t(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(o(this,'_weekdaysShortRegex')||(this._weekdaysShortRegex=Ht),this._weekdaysShortStrictRegex&&e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function Bt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(o(this,'_weekdaysMinRegex')||(this._weekdaysMinRegex=At),this._weekdaysMinStrictRegex&&e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function Jt(){function e(e,t){return t.length-e.length}var t,n,r,i,s,a=[],o=[],l=[],u=[];for(t=0;t<7;t++)n=_([2e3,1]).day(t),r=xe(this.weekdaysMin(n,'')),i=xe(this.weekdaysShort(n,'')),s=xe(this.weekdays(n,'')),a.push(r),o.push(i),l.push(s),u.push(r),u.push(i),u.push(s);a.sort(e),o.sort(e),l.sort(e),u.sort(e),this._weekdaysRegex=new RegExp('^('+u.join('|')+')','i'),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp('^('+l.join('|')+')','i'),this._weekdaysShortStrictRegex=new RegExp('^('+o.join('|')+')','i'),this._weekdaysMinStrictRegex=new RegExp('^('+a.join('|')+')','i')}function Qt(){return this.hours()%12||12}function Xt(){return this.hours()||24}function Kt(e,t){L(e,0,0,(function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)}))}function en(e,t){return t._meridiemParse}function tn(e){return'p'===(e+'').toLowerCase().charAt(0)}L('H',['HH',2],0,'hour'),L('h',['hh',2],0,Qt),L('k',['kk',2],0,Xt),L('hmm',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)})),L('hmmss',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)+F(this.seconds(),2)})),L('Hmm',0,0,(function(){return''+this.hours()+F(this.minutes(),2)})),L('Hmmss',0,0,(function(){return''+this.hours()+F(this.minutes(),2)+F(this.seconds(),2)})),Kt('a',!0),Kt('A',!1),be('a',en),be('A',en),be('H',he,Ye),be('h',he,Se),be('k',he,Se),be('HH',he,le),be('hh',he,le),be('kk',he,le),be('hmm',fe),be('hmmss',_e),be('Hmm',fe),be('Hmmss',_e),Ce(['H','HH'],Le),Ce(['k','kk'],(function(e,t,n){var r=Pe(e);t[Le]=24===r?0:r})),Ce(['a','A'],(function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e})),Ce(['h','hh'],(function(e,t,n){t[Le]=Pe(e),p(n).bigHour=!0})),Ce('hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r)),p(n).bigHour=!0})),Ce('hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i)),p(n).bigHour=!0})),Ce('Hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r))})),Ce('Hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i))}));var nn=/[ap]\\.?m?\\.?/i,rn=Je('Hours',!0);function sn(e,t,n){return e>11?n?'pm':'PM':n?'am':'AM'}var an,on={calendar:C,longDateFormat:Z,invalidDate:q,ordinal:B,dayOfMonthOrdinalParse:J,relativeTime:X,months:rt,monthsShort:it,week:Yt,weekdays:Ct,weekdaysMin:Ft,weekdaysShort:Wt,meridiemParse:nn},ln={},un={};function dn(e,t){var n,r=Math.min(e.length,t.length);for(n=0;n0;){if(r=_n(i.slice(0,t).join('-')))return r;if(n&&n.length>=t&&dn(i,n)>=t-1)break;t--}s++}return an}function fn(e){return!(!e||!e.match('^[^/\\\\\\\\]*$'))}function _n(t){var n=null;if(void 0===ln[t]&&e&&e.exports&&fn(t))try{n=an._abbr,Object(function(){var e=new Error('Cannot find module \\'undefined\\'');throw e.code='MODULE_NOT_FOUND',e}()),mn(n)}catch(e){ln[t]=null}return ln[t]}function mn(e,t){var n;return e&&((n=u(t)?gn(e):pn(e,t))?an=n:'undefined'!=typeof console&&console.warn&&console.warn('Locale '+e+' not found. Did you forget to load it?')),an._abbr}function pn(e,t){if(null!==t){var n,r=on;if(t.abbr=e,null!=ln[e])T('defineLocaleOverride','use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'),r=ln[e]._config;else if(null!=t.parentLocale)if(null!=ln[t.parentLocale])r=ln[t.parentLocale]._config;else{if(null==(n=_n(t.parentLocale)))return un[t.parentLocale]||(un[t.parentLocale]=[]),un[t.parentLocale].push({name:e,config:t}),null;r=n._config}return ln[e]=new R(P(r,t)),un[e]&&un[e].forEach((function(e){pn(e.name,e.config)})),mn(e),ln[e]}return delete ln[e],null}function yn(e,t){if(null!=t){var n,r,i=on;null!=ln[e]&&null!=ln[e].parentLocale?ln[e].set(P(ln[e]._config,t)):(null!=(r=_n(e))&&(i=r._config),t=P(i,t),null==r&&(t.abbr=e),(n=new R(t)).parentLocale=ln[e],ln[e]=n),mn(e)}else null!=ln[e]&&(null!=ln[e].parentLocale?(ln[e]=ln[e].parentLocale,e===mn()&&mn(e)):null!=ln[e]&&delete ln[e]);return ln[e]}function gn(e){var t;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return an;if(!s(e)){if(t=_n(e))return t;e=[e]}return hn(e)}function vn(){return b(ln)}function wn(e){var t,n=e._a;return n&&-2===p(e).overflow&&(t=n[Ae]<0||n[Ae]>11?Ae:n[Ee]<1||n[Ee]>nt(n[He],n[Ae])?Ee:n[Le]<0||n[Le]>24||24===n[Le]&&(0!==n[Ve]||0!==n[Ie]||0!==n[Ge])?Le:n[Ve]<0||n[Ve]>59?Ve:n[Ie]<0||n[Ie]>59?Ie:n[Ge]<0||n[Ge]>999?Ge:-1,p(e)._overflowDayOfYear&&(tEe)&&(t=Ee),p(e)._overflowWeeks&&-1===t&&(t=je),p(e)._overflowWeekday&&-1===t&&(t=Ze),p(e).overflow=t),e}var kn=/^\\s*((?:[+-]\\d{6}|\\d{4})-(?:\\d\\d-\\d\\d|W\\d\\d-\\d|W\\d\\d|\\d\\d\\d|\\d\\d))(?:(T| )(\\d\\d(?::\\d\\d(?::\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Dn=/^\\s*((?:[+-]\\d{6}|\\d{4})(?:\\d\\d\\d\\d|W\\d\\d\\d|W\\d\\d|\\d\\d\\d|\\d\\d|))(?:(T| )(\\d\\d(?:\\d\\d(?:\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Mn=/Z|[+-]\\d\\d(?::?\\d\\d)?/,Sn=[['YYYYYY-MM-DD',/[+-]\\d{6}-\\d\\d-\\d\\d/],['YYYY-MM-DD',/\\d{4}-\\d\\d-\\d\\d/],['GGGG-[W]WW-E',/\\d{4}-W\\d\\d-\\d/],['GGGG-[W]WW',/\\d{4}-W\\d\\d/,!1],['YYYY-DDD',/\\d{4}-\\d{3}/],['YYYY-MM',/\\d{4}-\\d\\d/,!1],['YYYYYYMMDD',/[+-]\\d{10}/],['YYYYMMDD',/\\d{8}/],['GGGG[W]WWE',/\\d{4}W\\d{3}/],['GGGG[W]WW',/\\d{4}W\\d{2}/,!1],['YYYYDDD',/\\d{7}/],['YYYYMM',/\\d{6}/,!1],['YYYY',/\\d{4}/,!1]],Yn=[['HH:mm:ss.SSSS',/\\d\\d:\\d\\d:\\d\\d\\.\\d+/],['HH:mm:ss,SSSS',/\\d\\d:\\d\\d:\\d\\d,\\d+/],['HH:mm:ss',/\\d\\d:\\d\\d:\\d\\d/],['HH:mm',/\\d\\d:\\d\\d/],['HHmmss.SSSS',/\\d\\d\\d\\d\\d\\d\\.\\d+/],['HHmmss,SSSS',/\\d\\d\\d\\d\\d\\d,\\d+/],['HHmmss',/\\d\\d\\d\\d\\d\\d/],['HHmm',/\\d\\d\\d\\d/],['HH',/\\d\\d/]],bn=/^\\/?Date\\((-?\\d+)/i,On=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\\s)?(\\d{1,2})\\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s(\\d{2,4})\\s(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\\d{4}))$/,Tn={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function xn(e){var t,n,r,i,s,a,o=e._i,l=kn.exec(o)||Dn.exec(o),u=Sn.length,d=Yn.length;if(l){for(p(e).iso=!0,t=0,n=u;tze(s)||0===e._dayOfYear)&&(p(e)._overflowDayOfYear=!0),n=vt(s,0,e._dayOfYear),e._a[Ae]=n.getUTCMonth(),e._a[Ee]=n.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=a[t]=r[t];for(;t<7;t++)e._a[t]=a[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[Le]&&0===e._a[Ve]&&0===e._a[Ie]&&0===e._a[Ge]&&(e._nextDay=!0,e._a[Le]=0),e._d=(e._useUTC?vt:gt).apply(null,a),i=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[Le]=24),e._w&&void 0!==e._w.d&&e._w.d!==i&&(p(e).weekdayMismatch=!0)}}function Ln(e){var t,n,r,i,s,a,o,l,u;null!=(t=e._w).GG||null!=t.W||null!=t.E?(s=1,a=4,n=Hn(t.GG,e._a[He],Dt(Bn(),1,4).year),r=Hn(t.W,1),((i=Hn(t.E,1))<1||i>7)&&(l=!0)):(s=e._locale._week.dow,a=e._locale._week.doy,u=Dt(Bn(),s,a),n=Hn(t.gg,e._a[He],u.year),r=Hn(t.w,u.week),null!=t.d?((i=t.d)<0||i>6)&&(l=!0):null!=t.e?(i=t.e+s,(t.e<0||t.e>6)&&(l=!0)):i=s),r<1||r>Mt(n,s,a)?p(e)._overflowWeeks=!0:null!=l?p(e)._overflowWeekday=!0:(o=kt(n,r,i,s,a),e._a[He]=o.year,e._dayOfYear=o.dayOfYear)}function Vn(e){if(e._f!==r.ISO_8601)if(e._f!==r.RFC_2822){e._a=[],p(e).empty=!0;var t,n,i,s,a,o,l,u=''+e._i,d=u.length,c=0;for(l=(i=j(e._f,e._locale).match(U)||[]).length,t=0;t0&&p(e).unusedInput.push(a),u=u.slice(u.indexOf(n)+n.length),c+=n.length),E[s]?(n?p(e).empty=!1:p(e).unusedTokens.push(s),Fe(s,n,e)):e._strict&&!n&&p(e).unusedTokens.push(s);p(e).charsLeftOver=d-c,u.length>0&&p(e).unusedInput.push(u),e._a[Le]<=12&&!0===p(e).bigHour&&e._a[Le]>0&&(p(e).bigHour=void 0),p(e).parsedDateParts=e._a.slice(0),p(e).meridiem=e._meridiem,e._a[Le]=In(e._locale,e._a[Le],e._meridiem),null!==(o=p(e).era)&&(e._a[He]=e._locale.erasConvertYear(o,e._a[He])),En(e),wn(e)}else Fn(e);else xn(e)}function In(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?((r=e.isPM(n))&&t<12&&(t+=12),r||12!==t||(t=0),t):t}function Gn(e){var t,n,r,i,s,a,o=!1,l=e._f.length;if(0===l)return p(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ithis?this:e:g()}));function Xn(e,t){var n,r;if(1===t.length&&s(t[0])&&(t=t[0]),!t.length)return Bn();for(n=t[0],r=1;rthis.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Dr(){if(!u(this._isDSTShifted))return this._isDSTShifted;var e,t={};return k(t,this),(t=zn(t))._a?(e=t._isUTC?_(t._a):Bn(t._a),this._isDSTShifted=this.isValid()&&ur(t._a,e.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function Mr(){return!!this.isValid()&&!this._isUTC}function Sr(){return!!this.isValid()&&this._isUTC}function Yr(){return!!this.isValid()&&this._isUTC&&0===this._offset}r.updateOffset=function(){};var br=/^(-|\\+)?(?:(\\d*)[. ])?(\\d+):(\\d+)(?::(\\d+)(\\.\\d*)?)?$/,Or=/^(-|\\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function Tr(e,t){var n,r,i,s=e,a=null;return or(e)?s={ms:e._milliseconds,d:e._days,M:e._months}:d(e)||!isNaN(+e)?(s={},t?s[t]=+e:s.milliseconds=+e):(a=br.exec(e))?(n='-'===a[1]?-1:1,s={y:0,d:Pe(a[Ee])*n,h:Pe(a[Le])*n,m:Pe(a[Ve])*n,s:Pe(a[Ie])*n,ms:Pe(lr(1e3*a[Ge]))*n}):(a=Or.exec(e))?(n='-'===a[1]?-1:1,s={y:xr(a[2],n),M:xr(a[3],n),w:xr(a[4],n),d:xr(a[5],n),h:xr(a[6],n),m:xr(a[7],n),s:xr(a[8],n)}):null==s?s={}:'object'==typeof s&&('from'in s||'to'in s)&&(i=Pr(Bn(s.from),Bn(s.to)),(s={}).ms=i.milliseconds,s.M=i.months),r=new ar(s),or(e)&&o(e,'_locale')&&(r._locale=e._locale),or(e)&&o(e,'_isValid')&&(r._isValid=e._isValid),r}function xr(e,t){var n=e&&parseFloat(e.replace(',','.'));return(isNaN(n)?0:n)*t}function Nr(e,t){var n={};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,'M').isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,'M'),n}function Pr(e,t){var n;return e.isValid()&&t.isValid()?(t=fr(t,e),e.isBefore(t)?n=Nr(e,t):((n=Nr(t,e)).milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function Rr(e,t){return function(n,r){var i;return null===r||isNaN(+r)||(T(t,'moment().'+t+'(period, number) is deprecated. Please use moment().'+t+'(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'),i=n,n=r,r=i),Cr(this,Tr(n,r),e),this}}function Cr(e,t,n,i){var s=t._milliseconds,a=lr(t._days),o=lr(t._months);e.isValid()&&(i=null==i||i,o&&ht(e,Qe(e,'Month')+o*n),a&&Xe(e,'Date',Qe(e,'Date')+a*n),s&&e._d.setTime(e._d.valueOf()+s*n),i&&r.updateOffset(e,a||o))}Tr.fn=ar.prototype,Tr.invalid=sr;var Wr=Rr(1,'add'),Fr=Rr(-1,'subtract');function Ur(e){return'string'==typeof e||e instanceof String}function Hr(e){return M(e)||c(e)||Ur(e)||d(e)||Er(e)||Ar(e)||null==e}function Ar(e){var t,n,r=a(e)&&!l(e),i=!1,s=['years','year','y','months','month','M','days','day','d','dates','date','D','hours','hour','h','minutes','minute','m','seconds','second','s','milliseconds','millisecond','ms'],u=s.length;for(t=0;tn.valueOf():n.valueOf()9999?G(n,t?'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'):x(Date.prototype.toISOString)?t?this.toDate().toISOString():new Date(this.valueOf()+60*this.utcOffset()*1e3).toISOString().replace('Z',G(n,'Z')):G(n,t?'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYY-MM-DD[T]HH:mm:ss.SSSZ')}function ei(){if(!this.isValid())return'moment.invalid(/* '+this._i+' */)';var e,t,n,r,i='moment',s='';return this.isLocal()||(i=0===this.utcOffset()?'moment.utc':'moment.parseZone',s='Z'),e='['+i+'(\"]',t=0<=this.year()&&this.year()<=9999?'YYYY':'YYYYYY',n='-MM-DD[T]HH:mm:ss.SSS',r=s+'[\")]',this.format(e+t+n+r)}function ti(e){e||(e=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var t=G(this,e);return this.localeData().postformat(t)}function ni(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({to:this,from:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function ri(e){return this.from(Bn(),e)}function ii(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({from:this,to:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function si(e){return this.to(Bn(),e)}function ai(e){var t;return void 0===e?this._locale._abbr:(null!=(t=gn(e))&&(this._locale=t),this)}r.defaultFormat='YYYY-MM-DDTHH:mm:ssZ',r.defaultFormatUtc='YYYY-MM-DDTHH:mm:ss[Z]';var oi=Y('moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',(function(e){return void 0===e?this.localeData():this.locale(e)}));function li(){return this._locale}var ui=1e3,di=60*ui,ci=60*di,hi=3506328*ci;function fi(e,t){return(e%t+t)%t}function _i(e,t,n){return e<100&&e>=0?new Date(e+400,t,n)-hi:new Date(e,t,n).valueOf()}function mi(e,t,n){return e<100&&e>=0?Date.UTC(e+400,t,n)-hi:Date.UTC(e,t,n)}function pi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year(),0,1);break;case'quarter':t=n(this.year(),this.month()-this.month()%3,1);break;case'month':t=n(this.year(),this.month(),1);break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday());break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case'day':case'date':t=n(this.year(),this.month(),this.date());break;case'hour':t=this._d.valueOf(),t-=fi(t+(this._isUTC?0:this.utcOffset()*di),ci);break;case'minute':t=this._d.valueOf(),t-=fi(t,di);break;case'second':t=this._d.valueOf(),t-=fi(t,ui)}return this._d.setTime(t),r.updateOffset(this,!0),this}function yi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year()+1,0,1)-1;break;case'quarter':t=n(this.year(),this.month()-this.month()%3+3,1)-1;break;case'month':t=n(this.year(),this.month()+1,1)-1;break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case'day':case'date':t=n(this.year(),this.month(),this.date()+1)-1;break;case'hour':t=this._d.valueOf(),t+=ci-fi(t+(this._isUTC?0:this.utcOffset()*di),ci)-1;break;case'minute':t=this._d.valueOf(),t+=di-fi(t,di)-1;break;case'second':t=this._d.valueOf(),t+=ui-fi(t,ui)-1}return this._d.setTime(t),r.updateOffset(this,!0),this}function gi(){return this._d.valueOf()-6e4*(this._offset||0)}function vi(){return Math.floor(this.valueOf()/1e3)}function wi(){return new Date(this.valueOf())}function ki(){var e=this;return[e.year(),e.month(),e.date(),e.hour(),e.minute(),e.second(),e.millisecond()]}function Di(){var e=this;return{years:e.year(),months:e.month(),date:e.date(),hours:e.hours(),minutes:e.minutes(),seconds:e.seconds(),milliseconds:e.milliseconds()}}function Mi(){return this.isValid()?this.toISOString():null}function Si(){return y(this)}function Yi(){return f({},p(this))}function bi(){return p(this).overflow}function Oi(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}function Ti(e,t){var n,i,s,a=this._eras||gn('en')._eras;for(n=0,i=a.length;n=0)return l[r]}function Ni(e,t){var n=e.since<=e.until?1:-1;return void 0===t?r(e.since).year():r(e.since).year()+(t-e.offset)*n}function Pi(){var e,t,n,r=this.localeData().eras();for(e=0,t=r.length;e(s=Mt(e,r,i))&&(t=s),Qi.call(this,e,t,n,r,i))}function Qi(e,t,n,r,i){var s=kt(e,t,n,r,i),a=vt(s.year,0,s.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()),this.date(a.getUTCDate()),this}function Xi(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}L('N',0,0,'eraAbbr'),L('NN',0,0,'eraAbbr'),L('NNN',0,0,'eraAbbr'),L('NNNN',0,0,'eraName'),L('NNNNN',0,0,'eraNarrow'),L('y',['y',1],'yo','eraYear'),L('y',['yy',2],0,'eraYear'),L('y',['yyy',3],0,'eraYear'),L('y',['yyyy',4],0,'eraYear'),be('N',Ai),be('NN',Ai),be('NNN',Ai),be('NNNN',Ei),be('NNNNN',Li),Ce(['N','NN','NNN','NNNN','NNNNN'],(function(e,t,n,r){var i=n._locale.erasParse(e,r,n._strict);i?p(n).era=i:p(n).invalidEra=e})),be('y',ge),be('yy',ge),be('yyy',ge),be('yyyy',ge),be('yo',Vi),Ce(['y','yy','yyy','yyyy'],He),Ce(['yo'],(function(e,t,n,r){var i;n._locale._eraYearOrdinalRegex&&(i=e.match(n._locale._eraYearOrdinalRegex)),n._locale.eraYearOrdinalParse?t[He]=n._locale.eraYearOrdinalParse(e,i):t[He]=parseInt(e,10)})),L(0,['gg',2],0,(function(){return this.weekYear()%100})),L(0,['GG',2],0,(function(){return this.isoWeekYear()%100})),Gi('gggg','weekYear'),Gi('ggggg','weekYear'),Gi('GGGG','isoWeekYear'),Gi('GGGGG','isoWeekYear'),be('G',ve),be('g',ve),be('GG',he,le),be('gg',he,le),be('GGGG',pe,de),be('gggg',pe,de),be('GGGGG',ye,ce),be('ggggg',ye,ce),We(['gggg','ggggg','GGGG','GGGGG'],(function(e,t,n,r){t[r.substr(0,2)]=Pe(e)})),We(['gg','GG'],(function(e,t,n,i){t[i]=r.parseTwoDigitYear(e)})),L('Q',0,'Qo','quarter'),be('Q',oe),Ce('Q',(function(e,t){t[Ae]=3*(Pe(e)-1)})),L('D',['DD',2],'Do','date'),be('D',he,Se),be('DD',he,le),be('Do',(function(e,t){return e?t._dayOfMonthOrdinalParse||t._ordinalParse:t._dayOfMonthOrdinalParseLenient})),Ce(['D','DD'],Ee),Ce('Do',(function(e,t){t[Ee]=Pe(e.match(he)[0])}));var Ki=Je('Date',!0);function es(e){var t=Math.round((this.clone().startOf('day')-this.clone().startOf('year'))/864e5)+1;return null==e?t:this.add(e-t,'d')}L('DDD',['DDDD',3],'DDDo','dayOfYear'),be('DDD',me),be('DDDD',ue),Ce(['DDD','DDDD'],(function(e,t,n){n._dayOfYear=Pe(e)})),L('m',['mm',2],0,'minute'),be('m',he,Ye),be('mm',he,le),Ce(['m','mm'],Ve);var ts=Je('Minutes',!1);L('s',['ss',2],0,'second'),be('s',he,Ye),be('ss',he,le),Ce(['s','ss'],Ie);var ns,rs,is=Je('Seconds',!1);for(L('S',0,0,(function(){return~~(this.millisecond()/100)})),L(0,['SS',2],0,(function(){return~~(this.millisecond()/10)})),L(0,['SSS',3],0,'millisecond'),L(0,['SSSS',4],0,(function(){return 10*this.millisecond()})),L(0,['SSSSS',5],0,(function(){return 100*this.millisecond()})),L(0,['SSSSSS',6],0,(function(){return 1e3*this.millisecond()})),L(0,['SSSSSSS',7],0,(function(){return 1e4*this.millisecond()})),L(0,['SSSSSSSS',8],0,(function(){return 1e5*this.millisecond()})),L(0,['SSSSSSSSS',9],0,(function(){return 1e6*this.millisecond()})),be('S',me,oe),be('SS',me,le),be('SSS',me,ue),ns='SSSS';ns.length<=9;ns+='S')be(ns,ge);function ss(e,t){t[Ge]=Pe(1e3*('0.'+e))}for(ns='S';ns.length<=9;ns+='S')Ce(ns,ss);function as(){return this._isUTC?'UTC':''}function os(){return this._isUTC?'Coordinated Universal Time':''}rs=Je('Milliseconds',!1),L('z',0,0,'zoneAbbr'),L('zz',0,0,'zoneName');var ls=D.prototype;function us(e){return Bn(1e3*e)}function ds(){return Bn.apply(null,arguments).parseZone()}function cs(e){return e}ls.add=Wr,ls.calendar=Ir,ls.clone=Gr,ls.diff=Jr,ls.endOf=yi,ls.format=ti,ls.from=ni,ls.fromNow=ri,ls.to=ii,ls.toNow=si,ls.get=Ke,ls.invalidAt=bi,ls.isAfter=jr,ls.isBefore=Zr,ls.isBetween=zr,ls.isSame=qr,ls.isSameOrAfter=$r,ls.isSameOrBefore=Br,ls.isValid=Si,ls.lang=oi,ls.locale=ai,ls.localeData=li,ls.max=Qn,ls.min=Jn,ls.parsingFlags=Yi,ls.set=et,ls.startOf=pi,ls.subtract=Fr,ls.toArray=ki,ls.toObject=Di,ls.toDate=wi,ls.toISOString=Kr,ls.inspect=ei,'undefined'!=typeof Symbol&&null!=Symbol.for&&(ls[Symbol.for('nodejs.util.inspect.custom')]=function(){return'Moment<'+this.format()+'>'}),ls.toJSON=Mi,ls.toString=Xr,ls.unix=vi,ls.valueOf=gi,ls.creationData=Oi,ls.eraName=Pi,ls.eraNarrow=Ri,ls.eraAbbr=Ci,ls.eraYear=Wi,ls.year=$e,ls.isLeapYear=Be,ls.weekYear=ji,ls.isoWeekYear=Zi,ls.quarter=ls.quarters=Xi,ls.month=ft,ls.daysInMonth=_t,ls.week=ls.weeks=Tt,ls.isoWeek=ls.isoWeeks=xt,ls.weeksInYear=$i,ls.weeksInWeekYear=Bi,ls.isoWeeksInYear=zi,ls.isoWeeksInISOWeekYear=qi,ls.date=Ki,ls.day=ls.days=jt,ls.weekday=Zt,ls.isoWeekday=zt,ls.dayOfYear=es,ls.hour=ls.hours=rn,ls.minute=ls.minutes=ts,ls.second=ls.seconds=is,ls.millisecond=ls.milliseconds=rs,ls.utcOffset=mr,ls.utc=yr,ls.local=gr,ls.parseZone=vr,ls.hasAlignedHourOffset=wr,ls.isDST=kr,ls.isLocal=Mr,ls.isUtcOffset=Sr,ls.isUtc=Yr,ls.isUTC=Yr,ls.zoneAbbr=as,ls.zoneName=os,ls.dates=Y('dates accessor is deprecated. Use date instead.',Ki),ls.months=Y('months accessor is deprecated. Use month instead',ft),ls.years=Y('years accessor is deprecated. Use year instead',$e),ls.zone=Y('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',pr),ls.isDSTShifted=Y('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',Dr);var hs=R.prototype;function fs(e,t,n,r){var i=gn(),s=_().set(r,t);return i[n](s,e)}function _s(e,t,n){if(d(e)&&(t=e,e=void 0),e=e||'',null!=t)return fs(e,t,n,'month');var r,i=[];for(r=0;r<12;r++)i[r]=fs(e,r,n,'month');return i}function ms(e,t,n,r){'boolean'==typeof e?(d(t)&&(n=t,t=void 0),t=t||''):(n=t=e,e=!1,d(t)&&(n=t,t=void 0),t=t||'');var i,s=gn(),a=e?s._week.dow:0,o=[];if(null!=n)return fs(t,(n+a)%7,r,'day');for(i=0;i<7;i++)o[i]=fs(t,(i+a)%7,r,'day');return o}function ps(e,t){return _s(e,t,'months')}function ys(e,t){return _s(e,t,'monthsShort')}function gs(e,t,n){return ms(e,t,n,'weekdays')}function vs(e,t,n){return ms(e,t,n,'weekdaysShort')}function ws(e,t,n){return ms(e,t,n,'weekdaysMin')}hs.calendar=W,hs.longDateFormat=z,hs.invalidDate=$,hs.ordinal=Q,hs.preparse=cs,hs.postformat=cs,hs.relativeTime=K,hs.pastFuture=ee,hs.set=N,hs.eras=Ti,hs.erasParse=xi,hs.erasConvertYear=Ni,hs.erasAbbrRegex=Ui,hs.erasNameRegex=Fi,hs.erasNarrowRegex=Hi,hs.months=lt,hs.monthsShort=ut,hs.monthsParse=ct,hs.monthsRegex=pt,hs.monthsShortRegex=mt,hs.week=St,hs.firstDayOfYear=Ot,hs.firstDayOfWeek=bt,hs.weekdays=Et,hs.weekdaysMin=Vt,hs.weekdaysShort=Lt,hs.weekdaysParse=Gt,hs.weekdaysRegex=qt,hs.weekdaysShortRegex=$t,hs.weekdaysMinRegex=Bt,hs.isPM=tn,hs.meridiem=sn,mn('en',{eras:[{since:'0001-01-01',until:1/0,offset:1,name:'Anno Domini',narrow:'AD',abbr:'AD'},{since:'0000-12-31',until:-1/0,offset:1,name:'Before Christ',narrow:'BC',abbr:'BC'}],dayOfMonthOrdinalParse:/\\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===Pe(e%100/10)?'th':1===t?'st':2===t?'nd':3===t?'rd':'th')}}),r.lang=Y('moment.lang is deprecated. Use moment.locale instead.',mn),r.langData=Y('moment.langData is deprecated. Use moment.localeData instead.',gn);var ks=Math.abs;function Ds(){var e=this._data;return this._milliseconds=ks(this._milliseconds),this._days=ks(this._days),this._months=ks(this._months),e.milliseconds=ks(e.milliseconds),e.seconds=ks(e.seconds),e.minutes=ks(e.minutes),e.hours=ks(e.hours),e.months=ks(e.months),e.years=ks(e.years),this}function Ms(e,t,n,r){var i=Tr(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Ss(e,t){return Ms(this,e,t,1)}function Ys(e,t){return Ms(this,e,t,-1)}function bs(e){return e<0?Math.floor(e):Math.ceil(e)}function Os(){var e,t,n,r,i,s=this._milliseconds,a=this._days,o=this._months,l=this._data;return s>=0&&a>=0&&o>=0||s<=0&&a<=0&&o<=0||(s+=864e5*bs(xs(o)+a),a=0,o=0),l.milliseconds=s%1e3,e=Ne(s/1e3),l.seconds=e%60,t=Ne(e/60),l.minutes=t%60,n=Ne(t/60),l.hours=n%24,a+=Ne(n/24),o+=i=Ne(Ts(a)),a-=bs(xs(i)),r=Ne(o/12),o%=12,l.days=a,l.months=o,l.years=r,this}function Ts(e){return 4800*e/146097}function xs(e){return 146097*e/4800}function Ns(e){if(!this.isValid())return NaN;var t,n,r=this._milliseconds;if('month'===(e=ne(e))||'quarter'===e||'year'===e)switch(t=this._days+r/864e5,n=this._months+Ts(t),e){case'month':return n;case'quarter':return n/3;case'year':return n/12}else switch(t=this._days+Math.round(xs(this._months)),e){case'week':return t/7+r/6048e5;case'day':return t+r/864e5;case'hour':return 24*t+r/36e5;case'minute':return 1440*t+r/6e4;case'second':return 86400*t+r/1e3;case'millisecond':return Math.floor(864e5*t)+r;default:throw new Error('Unknown unit '+e)}}function Ps(e){return function(){return this.as(e)}}var Rs=Ps('ms'),Cs=Ps('s'),Ws=Ps('m'),Fs=Ps('h'),Us=Ps('d'),Hs=Ps('w'),As=Ps('M'),Es=Ps('Q'),Ls=Ps('y'),Vs=Rs;function Is(){return Tr(this)}function Gs(e){return e=ne(e),this.isValid()?this[e+'s']():NaN}function js(e){return function(){return this.isValid()?this._data[e]:NaN}}var Zs=js('milliseconds'),zs=js('seconds'),qs=js('minutes'),$s=js('hours'),Bs=js('days'),Js=js('months'),Qs=js('years');function Xs(){return Ne(this.days()/7)}var Ks=Math.round,ea={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function ta(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function na(e,t,n,r){var i=Tr(e).abs(),s=Ks(i.as('s')),a=Ks(i.as('m')),o=Ks(i.as('h')),l=Ks(i.as('d')),u=Ks(i.as('M')),d=Ks(i.as('w')),c=Ks(i.as('y')),h=s<=n.ss&&['s',s]||s0,h[4]=r,ta.apply(null,h)}function ra(e){return void 0===e?Ks:'function'==typeof e&&(Ks=e,!0)}function ia(e,t){return void 0!==ea[e]&&(void 0===t?ea[e]:(ea[e]=t,'s'===e&&(ea.ss=t-1),!0))}function sa(e,t){if(!this.isValid())return this.localeData().invalidDate();var n,r,i=!1,s=ea;return'object'==typeof e&&(t=e,e=!1),'boolean'==typeof e&&(i=e),'object'==typeof t&&(s=Object.assign({},ea,t),null!=t.s&&null==t.ss&&(s.ss=t.s-1)),r=na(this,!i,s,n=this.localeData()),i&&(r=n.pastFuture(+this,r)),n.postformat(r)}var aa=Math.abs;function oa(e){return(e>0)-(e<0)||+e}function la(){if(!this.isValid())return this.localeData().invalidDate();var e,t,n,r,i,s,a,o,l=aa(this._milliseconds)/1e3,u=aa(this._days),d=aa(this._months),c=this.asSeconds();return c?(e=Ne(l/60),t=Ne(e/60),l%=60,e%=60,n=Ne(d/12),d%=12,r=l?l.toFixed(3).replace(/\\.?0+$/,''):'',i=c<0?'-':'',s=oa(this._months)!==oa(c)?'-':'',a=oa(this._days)!==oa(c)?'-':'',o=oa(this._milliseconds)!==oa(c)?'-':'',i+'P'+(n?s+n+'Y':'')+(d?s+d+'M':'')+(u?a+u+'D':'')+(t||e||l?'T':'')+(t?o+t+'H':'')+(e?o+e+'M':'')+(l?o+r+'S':'')):'P0D'}var ua=ar.prototype;return ua.isValid=ir,ua.abs=Ds,ua.add=Ss,ua.subtract=Ys,ua.as=Ns,ua.asMilliseconds=Rs,ua.asSeconds=Cs,ua.asMinutes=Ws,ua.asHours=Fs,ua.asDays=Us,ua.asWeeks=Hs,ua.asMonths=As,ua.asQuarters=Es,ua.asYears=Ls,ua.valueOf=Vs,ua._bubble=Os,ua.clone=Is,ua.get=Gs,ua.milliseconds=Zs,ua.seconds=zs,ua.minutes=qs,ua.hours=$s,ua.days=Bs,ua.weeks=Xs,ua.months=Js,ua.years=Qs,ua.humanize=sa,ua.toISOString=la,ua.toString=la,ua.toJSON=la,ua.locale=ai,ua.localeData=li,ua.toIsoString=Y('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',la),ua.lang=oi,L('X',0,0,'unix'),L('x',0,0,'valueOf'),be('x',ve),be('X',De),Ce('X',(function(e,t,n){n._d=new Date(1e3*parseFloat(e))})),Ce('x',(function(e,t,n){n._d=new Date(Pe(e))})),r.version='2.30.1',i(Bn),r.fn=ls,r.min=Kn,r.max=er,r.now=tr,r.utc=_,r.unix=us,r.months=ps,r.isDate=c,r.locale=mn,r.invalid=g,r.duration=Tr,r.isMoment=M,r.weekdays=gs,r.parseZone=ds,r.localeData=gn,r.isDuration=or,r.monthsShort=ys,r.weekdaysMin=ws,r.defineLocale=pn,r.updateLocale=yn,r.locales=vn,r.weekdaysShort=vs,r.normalizeUnits=ne,r.relativeTimeRounding=ra,r.relativeTimeThreshold=ia,r.calendarFormat=Vr,r.prototype=ls,r.HTML5_FMT={DATETIME_LOCAL:'YYYY-MM-DDTHH:mm',DATETIME_LOCAL_SECONDS:'YYYY-MM-DDTHH:mm:ss',DATETIME_LOCAL_MS:'YYYY-MM-DDTHH:mm:ss.SSS',DATE:'YYYY-MM-DD',TIME:'HH:mm',TIME_SECONDS:'HH:mm:ss',TIME_MS:'HH:mm:ss.SSS',WEEK:'GGGG-[W]WW',MONTH:'YYYY-MM'},r}()},766(e,t,n){const r=n(420),i=r().startOf('day'),s=['pregnancy'],a=['pregnancy_home_visit'],o=['delivery'],l=['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregannacy_danger_sign_follow_up'],u=294,d=(e,t)=>['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t,n,r){return e.filter((function(e){return t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r}))}function h(e,t){let n;return e.forEach((function(e){(function(e){return!!(e.form&&e.fields&&e.reported_date)})(e)&&t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function f(e){return M(e)&&d(e,'lmp_date_8601')&&r(d(e,'lmp_date_8601'))}function _(e,t){let n=f(t),i=t.reported_date;return x(e,t).forEach((function(e){const t=S(s=e)&&d(s,'lmp_date_8601')&&r(d(s,'lmp_date_8601'));var s;e.reported_date>i&&'yes'===d(e,'lmp_updated')&&(i=e.reported_date,n=t)})),n}function m(e,t){const n=_(e,t);if(n)return n.clone().add(280,'days')}function p(e){return Y(e)&&d(e,'delivery_outcome.delivery_date')&&r(d(e,'delivery_outcome.delivery_date'))}function y(e){const t=[];if('yes'===d(e,'t_danger_signs_referral_follow_up')){const n=d(e,'danger_signs');if(n)for(const e in n)'yes'===n[e]&&'r_danger_sign_present'!==e&&t.push(e)}return t}function g(e){const t=[];if(!M(e))return[];if('yes'===d(e,'risk_factors.r_risk_factor_present')){'yes'===d(e,'risk_factors.risk_factors_history.first_pregnancy')&&t.push('first_pregnancy'),'yes'===d(e,'risk_factors.risk_factors_history.previous_miscarriage')&&t.push('previous_miscarriage');const n=d(e,'risk_factors.risk_factors_present.primary_condition'),r=d(e,'risk_factors.risk_factors_present.secondary_condition');n&&t.push(...n.split(' ')),r&&t.push(...r.split(' '))}return t}function v(e,t){const n=g(t);return x(e,t).forEach((function(e){n.push(...function(e){const t=[];if(!S(e))return[];if('yes'===d(e,'anc_visits_hf.risk_factors.r_risk_factor_present')){const n=d(e,'anc_visits_hf.risk_factors.new_risks');n&&t.push(...n.split(' '))}return t}(e))})),n}function w(e){let t;return e&&M(e)?t=d(e,'risk_factors.risk_factors_present.additional_risk'):e&&S(e)&&(t=d(e,'anc_visits_hf.risk_factors.additional_risk')),t}function k(e,t){const n=[],r=w(t);r&&n.push(r);return x(e,t).forEach((function(e){const t=w(e);t&&n.push(t)})),n}function D(e){return e&&!e.date_of_death}function M(e){return e&&s.includes(e.form)}function S(e){return e&&a.includes(e.form)}function Y(e){return e&&o.includes(e.form)}function b(e,t,n){if('person'!==e.type||!D(e)||!M(n))return!1;const r=(_(t,n)||n.reported_date)>i.clone().subtract(u,'day'),s=T(t,n,42).length>0,a=function(e,t){return e.filter((function(e){return M(e)&&e.reported_date>t.reported_date}))}(t,n).length>0;return r&&!s&&!a&&!O(t,n,'abortion')&&!O(t,n,'miscarriage')}function O(e,t,n){const r=h(x(e,t),a);if(r&&d(r,'pregnancy_summary.visit_option')===n)return r}function T(e,t,n){return e.filter((function(e){return Y(e)&&e.reported_date>t.reported_date&&(!n||e.reported_date>=i.clone().subtract(n,'days'))}))}function x(e,t){let n=f(t);n||(n=r(t.reported_date));return e.filter((function(e){return S(e)&&e.reported_date>t.reported_date&&r(e.reported_date)b(e)))},isActivePregnancy:b,countANCFacilityVisits:function(e,t){let n=0;const r=x(e,t);return d(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=d(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},knowsHIVStatusInPast3Months:function(e){let t=!1;return c(e,s,i.clone().subtract(3,'months'),i).forEach((function(e){'yes'===d(e,'pregnancy_new_or_current.hiv_status.hiv_status_know')&&(t=!0)})),t},getAllRiskFactors:v,getAllRiskFactorExtra:k,getDangerSignCodes:y,getLatestDangerSignsForPregnancy:function(e,t){if(!t)return[];let n=_(e,t);n||(n=r(t.reported_date));const i=c(e,l,n.toDate(),n.clone().add(u,'days').toDate()),s=[];i.forEach((e=>{S(e)?'yes'===d(e,'pregnancy_summary.visit_option')&&s.push(e):s.push(e)}));const a=h(s,l);return a?y(a):[]},getNextANCVisitDate:function(e,t){let n=d(t,'t_pregnancy_follow_up_date'),i=t.reported_date;return x(e,t).forEach((function(e){e.reported_date>i&&d(e,'t_pregnancy_follow_up_date')&&(i=e.reported_date,n=d(e,'t_pregnancy_follow_up_date'))})),r(n)},isReadyForNewPregnancy:function(e,t){if('person'!==e.type)return!1;const n=h(t,s),a=h(t,o);if(!n&&!a)return!0;if(n){if(!a||a.reported_daten.reported_date))return p(a)O&&'yes'===Y(e,'lmp_updated')&&(O=e.reported_date,Y(e,'lmp_method_approx')&&(b=Y(e,'lmp_method_approx')))}));const x=M(T,e,'migrated'),N=M(T,e,'refused'),P=x||N;if(P){const e='clear_all'===Y(P,'pregnancy_ended.clear_option');t.push({label:'contact.profile.change_care',value:x?'Migrated out of area':'Refusing care',width:6},{label:'contact.profile.tasks_on_off',value:e?'Off':'On',width:6})}if(t.push({label:'Weeks Pregnant',value:D||0===D?{number:D,approximate:'yes'===b}:'contact.profile.value.unknown',translate:!D&&0!==D,filter:D||0===D?'weeksPregnant':'',width:6},{label:'contact.profile.edd',value:_?_.valueOf():'contact.profile.value.unknown',translate:!_,filter:_?'simpleDate':'',width:6}),d){let e='';e=!n&&i?i.join(', '):n.length>1||n&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+n[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}return a.length>0&&t.push({label:'contact.profile.danger_signs.current',value:a.length>1?'contact.profile.danger_sign.multiple':'contact.profile.danger_sign.'+a[0],translate:!0,width:6}),t.push({label:'contact.profile.visit',value:'contact.profile.visits.of',context:{count:m(T,e),total:8},translate:!0,width:6},{label:'contact.profile.last_visited',value:h.valueOf(),filter:'relativeDay',width:6}),k&&k.isSameOrAfter(s)&&t.push({label:'contact.profile.anc.next',value:k.valueOf(),filter:'simpleDate',width:6}),t},modifyContext:function(e,t){let n=Y(t,'lmp_date_8601'),r=Y(t,'lmp_method_approx'),i=Y(t,'hiv_status_known'),s=Y(t,'deworming_med_received'),a=Y(t,'tt_received');const o=p(T,t),l=S(T,t);let d=Y(t,'t_pregnancy_follow_up_date');u(T,t).forEach((function(e){'yes'===Y(e,'lmp_updated')&&(n=Y(e,'lmp_date_8601'),r=Y(e,'lmp_method_approx')),i=Y(e,'hiv_status_known'),s=Y(e,'deworming_med_received'),a=Y(e,'tt_received'),'yes'===Y(e,'t_pregnancy_follow_up')&&(d=Y(e,'t_pregnancy_follow_up_date'))})),e.lmp_date_8601=n,e.lmp_method_approx=r,e.is_active_pregnancy=!0,e.deworming_med_received=s,e.hiv_tested_past=i,e.tt_received_past=a,e.risk_factor_codes=o.join(' '),e.risk_factor_extra=l.join('; '),e.pregnancy_follow_up_date_recent=d,e.pregnancy_uuid=t._id}},{label:'contact.profile.death.title',appliesToType:'person',appliesIf:function(){return!c(b)},fields:function(){const e=[];let t,n;const r=l(T,['death_report']);if(r){const e=Y(r,'death_details');e&&(t=e.date_of_death,n=e.place_of_death)}else b.date_of_death&&(t=b.date_of_death);return e.push({label:'contact.profile.death.date',value:t||'contact.profile.value.unknown',filter:t?'simpleDate':'',translate:!t,width:6},{label:'contact.profile.death.place',value:n||'contact.profile.value.unknown',translate:!0,width:6}),e}},{label:'contact.profile.pregnancy.past',appliesToType:'report',appliesIf:function(e){if('person'!==b.type)return!1;if('delivery'===e.form)return!0;if('pregnancy'===e.form){if(M(T,e,'abortion')||M(T,e,'miscarriage'))return!0;const t=v(T,e);return t&&s.isSameOrAfter(t.clone().add(42,'weeks'))&&0===d(T,e,a).length}return!1},fields:function(e){const t=[];let n,i,l='',u=0,c=0,h=0;if('delivery'===e.form){const s=r(e.reported_date);n=D(T,['pregnancy'],s.clone().subtract(a,'days').toDate(),s.toDate())[0],Y(e,'delivery_outcome')&&(i=k(e),l=Y(e,'delivery_outcome.delivery_place'),u=Y(e,'delivery_outcome.babies_delivered_num'),c=Y(e,'delivery_outcome.babies_deceased_num'),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'',filter:'simpleDate',width:6},{label:'contact.profile.delivery_place',value:l,translate:!0,width:6},{label:'contact.profile.delivered_babies',value:u,width:6}))}else if('pregnancy'===e.form){n=e;const o=v(T,n),l=M(T,n,'abortion'),u=M(T,n,'miscarriage');if(l||u){let e='',n=r(0),i=0;l?(e='abortion',n=r(Y(l,'pregnancy_ended.abortion_date'))):(e='miscarriage',n=r(Y(u,'pregnancy_ended.miscarriage_date'))),i=n.diff(o,'weeks'),t.push({label:'contact.profile.pregnancy.end_early',value:e,translate:!0,width:6},{label:'contact.profile.pregnancy.end_date',value:n.valueOf(),filter:'simpleDate',width:6},{label:'contact.profile.pregnancy.end_weeks',value:i>0?i:'contact.profile.value.unknown',translate:i<=0,width:6})}else o&&s.isSameOrAfter(o.clone().add(42,'weeks'))&&0===d(T,e,a).length&&(i=w(T,e),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'contact.profile.value.unknown',filter:'simpleDate',translate:!i,width:6}))}if(c>0&&Y(e,'baby_death')){t.push({label:'contact.profile.deceased_babies',value:c,width:6});let n=Y(e,'baby_death.baby_death_repeat');n||(n=[]);let r=0;n.forEach((function(e){r>0&&t.push({label:'',value:'',width:6}),t.push({label:'contact.profile.newborn.death_date',value:e.baby_death_date,filter:'simpleDate',width:6},{label:'contact.profile.newborn.death_place',value:e.baby_death_place,translate:!0,width:6},{label:'contact.profile.delivery.stillbirthQ',value:e.stillbirth,translate:!0,width:6}),r++,r===n.length&&t.push({label:'',value:'',width:6})}))}if(n){h=m(T,n),t.push({label:'contact.profile.anc_visit',value:h,width:3});if(o(T,n)){let e='';const r=p(T,n),i=S(T,n);e=!r&&i?i.join(', '):r.length>1||r&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+r[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}}return t}}];e.exports={context:x,cards:P,fields:N}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={id:r,loaded:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.loaded=!0,s.exports}return n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),n(344)})())); return ContactSummary;", + "contact_summary": "var ContactSummary = {}; /*! For license information please see contact-summary.js.LICENSE.txt */\n!function(e,t){if('object'==typeof exports&&'object'==typeof module)module.exports=t();else if('function'==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)('object'==typeof exports?exports:e)[r]=n[r]}}(ContactSummary,(()=>(()=>{var e={344:(e,t,n)=>{var r=n(972),i=n(597);e.exports=i(r,contact,reports)},420:function(e,t,n){(e=n.nmd(e)).exports=function(){'use strict';var t,n;function r(){return t.apply(null,arguments)}function i(e){t=e}function s(e){return e instanceof Array||'[object Array]'===Object.prototype.toString.call(e)}function a(e){return null!=e&&'[object Object]'===Object.prototype.toString.call(e)}function o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function l(e){if(Object.getOwnPropertyNames)return 0===Object.getOwnPropertyNames(e).length;var t;for(t in e)if(o(e,t))return!1;return!0}function u(e){return void 0===e}function d(e){return'number'==typeof e||'[object Number]'===Object.prototype.toString.call(e)}function c(e){return e instanceof Date||'[object Date]'===Object.prototype.toString.call(e)}function h(e,t){var n,r=[],i=e.length;for(n=0;n>>0;for(t=0;t0)for(n=0;n=0?n?'+':'':'-')+Math.pow(10,Math.max(0,i)).toString().substr(1)+r}var U=/(\\[[^\\[]*\\])|(\\\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g,H=/(\\[[^\\[]*\\])|(\\\\)?(LTS|LT|LL?L?L?|l{1,4})/g,A={},E={};function L(e,t,n,r){var i=r;'string'==typeof r&&(i=function(){return this[r]()}),e&&(E[e]=i),t&&(E[t[0]]=function(){return F(i.apply(this,arguments),t[1],t[2])}),n&&(E[n]=function(){return this.localeData().ordinal(i.apply(this,arguments),e)})}function V(e){return e.match(/\\[[\\s\\S]/)?e.replace(/^\\[|\\]$/g,''):e.replace(/\\\\/g,'')}function I(e){var t,n,r=e.match(U);for(t=0,n=r.length;t=0&&H.test(e);)e=e.replace(H,r),H.lastIndex=0,n-=1;return e}var Z={LTS:'h:mm:ss A',LT:'h:mm A',L:'MM/DD/YYYY',LL:'MMMM D, YYYY',LLL:'MMMM D, YYYY h:mm A',LLLL:'dddd, MMMM D, YYYY h:mm A'};function z(e){var t=this._longDateFormat[e],n=this._longDateFormat[e.toUpperCase()];return t||!n?t:(this._longDateFormat[e]=n.match(U).map((function(e){return'MMMM'===e||'MM'===e||'DD'===e||'dddd'===e?e.slice(1):e})).join(''),this._longDateFormat[e])}var q='Invalid date';function $(){return this._invalidDate}var B='%d',J=/\\d{1,2}/;function Q(e){return this._ordinal.replace('%d',e)}var X={future:'in %s',past:'%s ago',s:'a few seconds',ss:'%d seconds',m:'a minute',mm:'%d minutes',h:'an hour',hh:'%d hours',d:'a day',dd:'%d days',w:'a week',ww:'%d weeks',M:'a month',MM:'%d months',y:'a year',yy:'%d years'};function K(e,t,n,r){var i=this._relativeTime[n];return x(i)?i(e,t,n,r):i.replace(/%d/i,e)}function ee(e,t){var n=this._relativeTime[e>0?'future':'past'];return x(n)?n(t):n.replace(/%s/i,t)}var te={D:'date',dates:'date',date:'date',d:'day',days:'day',day:'day',e:'weekday',weekdays:'weekday',weekday:'weekday',E:'isoWeekday',isoweekdays:'isoWeekday',isoweekday:'isoWeekday',DDD:'dayOfYear',dayofyears:'dayOfYear',dayofyear:'dayOfYear',h:'hour',hours:'hour',hour:'hour',ms:'millisecond',milliseconds:'millisecond',millisecond:'millisecond',m:'minute',minutes:'minute',minute:'minute',M:'month',months:'month',month:'month',Q:'quarter',quarters:'quarter',quarter:'quarter',s:'second',seconds:'second',second:'second',gg:'weekYear',weekyears:'weekYear',weekyear:'weekYear',GG:'isoWeekYear',isoweekyears:'isoWeekYear',isoweekyear:'isoWeekYear',w:'week',weeks:'week',week:'week',W:'isoWeek',isoweeks:'isoWeek',isoweek:'isoWeek',y:'year',years:'year',year:'year'};function ne(e){return'string'==typeof e?te[e]||te[e.toLowerCase()]:void 0}function re(e){var t,n,r={};for(n in e)o(e,n)&&(t=ne(n))&&(r[t]=e[n]);return r}var ie={date:9,day:11,weekday:11,isoWeekday:11,dayOfYear:4,hour:13,millisecond:16,minute:14,month:8,quarter:7,second:15,weekYear:1,isoWeekYear:1,week:5,isoWeek:5,year:1};function se(e){var t,n=[];for(t in e)o(e,t)&&n.push({unit:t,priority:ie[t]});return n.sort((function(e,t){return e.priority-t.priority})),n}var ae,oe=/\\d/,le=/\\d\\d/,ue=/\\d{3}/,de=/\\d{4}/,ce=/[+-]?\\d{6}/,he=/\\d\\d?/,fe=/\\d\\d\\d\\d?/,_e=/\\d\\d\\d\\d\\d\\d?/,me=/\\d{1,3}/,pe=/\\d{1,4}/,ye=/[+-]?\\d{1,6}/,ge=/\\d+/,ve=/[+-]?\\d+/,we=/Z|[+-]\\d\\d:?\\d\\d/gi,ke=/Z|[+-]\\d\\d(?::?\\d\\d)?/gi,De=/[+-]?\\d+(\\.\\d{1,3})?/,Me=/[0-9]{0,256}['a-z\\u00A0-\\u05FF\\u0700-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFF07\\uFF10-\\uFFEF]{1,256}|[\\u0600-\\u06FF\\/]{1,256}(\\s*?[\\u0600-\\u06FF]{1,256}){1,2}/i,Se=/^[1-9]\\d?/,Ye=/^([1-9]\\d|\\d)/;function be(e,t,n){ae[e]=x(t)?t:function(e,r){return e&&n?n:t}}function Oe(e,t){return o(ae,e)?ae[e](t._strict,t._locale):new RegExp(Te(e))}function Te(e){return xe(e.replace('\\\\','').replace(/\\\\(\\[)|\\\\(\\])|\\[([^\\]\\[]*)\\]|\\\\(.)/g,(function(e,t,n,r,i){return t||n||r||i})))}function xe(e){return e.replace(/[-\\/\\\\^$*+?.()|[\\]{}]/g,'\\\\$&')}function Ne(e){return e<0?Math.ceil(e)||0:Math.floor(e)}function Pe(e){var t=+e,n=0;return 0!==t&&isFinite(t)&&(n=Ne(t)),n}ae={};var Re={};function Ce(e,t){var n,r,i=t;for('string'==typeof e&&(e=[e]),d(t)&&(i=function(e,n){n[t]=Pe(e)}),r=e.length,n=0;n68?1900:2e3)};var qe,$e=Je('FullYear',!0);function Be(){return Ue(this.year())}function Je(e,t){return function(n){return null!=n?(Xe(this,e,n),r.updateOffset(this,t),this):Qe(this,e)}}function Qe(e,t){if(!e.isValid())return NaN;var n=e._d,r=e._isUTC;switch(t){case'Milliseconds':return r?n.getUTCMilliseconds():n.getMilliseconds();case'Seconds':return r?n.getUTCSeconds():n.getSeconds();case'Minutes':return r?n.getUTCMinutes():n.getMinutes();case'Hours':return r?n.getUTCHours():n.getHours();case'Date':return r?n.getUTCDate():n.getDate();case'Day':return r?n.getUTCDay():n.getDay();case'Month':return r?n.getUTCMonth():n.getMonth();case'FullYear':return r?n.getUTCFullYear():n.getFullYear();default:return NaN}}function Xe(e,t,n){var r,i,s,a,o;if(e.isValid()&&!isNaN(n)){switch(r=e._d,i=e._isUTC,t){case'Milliseconds':return void(i?r.setUTCMilliseconds(n):r.setMilliseconds(n));case'Seconds':return void(i?r.setUTCSeconds(n):r.setSeconds(n));case'Minutes':return void(i?r.setUTCMinutes(n):r.setMinutes(n));case'Hours':return void(i?r.setUTCHours(n):r.setHours(n));case'Date':return void(i?r.setUTCDate(n):r.setDate(n));case'FullYear':break;default:return}s=n,a=e.month(),o=29!==(o=e.date())||1!==a||Ue(s)?o:28,i?r.setUTCFullYear(s,a,o):r.setFullYear(s,a,o)}}function Ke(e){return x(this[e=ne(e)])?this[e]():this}function et(e,t){if('object'==typeof e){var n,r=se(e=re(e)),i=r.length;for(n=0;n=0?(o=new Date(e+400,t,n,r,i,s,a),isFinite(o.getFullYear())&&o.setFullYear(e)):o=new Date(e,t,n,r,i,s,a),o}function vt(e){var t,n;return e<100&&e>=0?((n=Array.prototype.slice.call(arguments))[0]=e+400,t=new Date(Date.UTC.apply(null,n)),isFinite(t.getUTCFullYear())&&t.setUTCFullYear(e)):t=new Date(Date.UTC.apply(null,arguments)),t}function wt(e,t,n){var r=7+t-n;return-(7+vt(e,0,r).getUTCDay()-t)%7+r-1}function kt(e,t,n,r,i){var s,a,o=1+7*(t-1)+(7+n-r)%7+wt(e,r,i);return o<=0?a=ze(s=e-1)+o:o>ze(e)?(s=e+1,a=o-ze(e)):(s=e,a=o),{year:s,dayOfYear:a}}function Dt(e,t,n){var r,i,s=wt(e.year(),t,n),a=Math.floor((e.dayOfYear()-s-1)/7)+1;return a<1?r=a+Mt(i=e.year()-1,t,n):a>Mt(e.year(),t,n)?(r=a-Mt(e.year(),t,n),i=e.year()+1):(i=e.year(),r=a),{week:r,year:i}}function Mt(e,t,n){var r=wt(e,t,n),i=wt(e+1,t,n);return(ze(e)-r+i)/7}function St(e){return Dt(e,this._week.dow,this._week.doy).week}L('w',['ww',2],'wo','week'),L('W',['WW',2],'Wo','isoWeek'),be('w',he,Se),be('ww',he,le),be('W',he,Se),be('WW',he,le),We(['w','ww','W','WW'],(function(e,t,n,r){t[r.substr(0,1)]=Pe(e)}));var Yt={dow:0,doy:6};function bt(){return this._week.dow}function Ot(){return this._week.doy}function Tt(e){var t=this.localeData().week(this);return null==e?t:this.add(7*(e-t),'d')}function xt(e){var t=Dt(this,1,4).week;return null==e?t:this.add(7*(e-t),'d')}function Nt(e,t){return'string'!=typeof e?e:isNaN(e)?'number'==typeof(e=t.weekdaysParse(e))?e:null:parseInt(e,10)}function Pt(e,t){return'string'==typeof e?t.weekdaysParse(e)%7||7:isNaN(e)?null:e}function Rt(e,t){return e.slice(t,7).concat(e.slice(0,t))}L('d',0,'do','day'),L('dd',0,0,(function(e){return this.localeData().weekdaysMin(this,e)})),L('ddd',0,0,(function(e){return this.localeData().weekdaysShort(this,e)})),L('dddd',0,0,(function(e){return this.localeData().weekdays(this,e)})),L('e',0,0,'weekday'),L('E',0,0,'isoWeekday'),be('d',he),be('e',he),be('E',he),be('dd',(function(e,t){return t.weekdaysMinRegex(e)})),be('ddd',(function(e,t){return t.weekdaysShortRegex(e)})),be('dddd',(function(e,t){return t.weekdaysRegex(e)})),We(['dd','ddd','dddd'],(function(e,t,n,r){var i=n._locale.weekdaysParse(e,r,n._strict);null!=i?t.d=i:p(n).invalidWeekday=e})),We(['d','e','E'],(function(e,t,n,r){t[r]=Pe(e)}));var Ct='Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday'.split('_'),Wt='Sun_Mon_Tue_Wed_Thu_Fri_Sat'.split('_'),Ft='Su_Mo_Tu_We_Th_Fr_Sa'.split('_'),Ut=Me,Ht=Me,At=Me;function Et(e,t){var n=s(this._weekdays)?this._weekdays:this._weekdays[e&&!0!==e&&this._weekdays.isFormat.test(t)?'format':'standalone'];return!0===e?Rt(n,this._week.dow):e?n[e.day()]:n}function Lt(e){return!0===e?Rt(this._weekdaysShort,this._week.dow):e?this._weekdaysShort[e.day()]:this._weekdaysShort}function Vt(e){return!0===e?Rt(this._weekdaysMin,this._week.dow):e?this._weekdaysMin[e.day()]:this._weekdaysMin}function It(e,t,n){var r,i,s,a=e.toLocaleLowerCase();if(!this._weekdaysParse)for(this._weekdaysParse=[],this._shortWeekdaysParse=[],this._minWeekdaysParse=[],r=0;r<7;++r)s=_([2e3,1]).day(r),this._minWeekdaysParse[r]=this.weekdaysMin(s,'').toLocaleLowerCase(),this._shortWeekdaysParse[r]=this.weekdaysShort(s,'').toLocaleLowerCase(),this._weekdaysParse[r]=this.weekdays(s,'').toLocaleLowerCase();return n?'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'dddd'===t?-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:'ddd'===t?-1!==(i=qe.call(this._shortWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._minWeekdaysParse,a))?i:null:-1!==(i=qe.call(this._minWeekdaysParse,a))||-1!==(i=qe.call(this._weekdaysParse,a))||-1!==(i=qe.call(this._shortWeekdaysParse,a))?i:null}function Gt(e,t,n){var r,i,s;if(this._weekdaysParseExact)return It.call(this,e,t,n);for(this._weekdaysParse||(this._weekdaysParse=[],this._minWeekdaysParse=[],this._shortWeekdaysParse=[],this._fullWeekdaysParse=[]),r=0;r<7;r++){if(i=_([2e3,1]).day(r),n&&!this._fullWeekdaysParse[r]&&(this._fullWeekdaysParse[r]=new RegExp('^'+this.weekdays(i,'').replace('.','\\\\.?')+'$','i'),this._shortWeekdaysParse[r]=new RegExp('^'+this.weekdaysShort(i,'').replace('.','\\\\.?')+'$','i'),this._minWeekdaysParse[r]=new RegExp('^'+this.weekdaysMin(i,'').replace('.','\\\\.?')+'$','i')),this._weekdaysParse[r]||(s='^'+this.weekdays(i,'')+'|^'+this.weekdaysShort(i,'')+'|^'+this.weekdaysMin(i,''),this._weekdaysParse[r]=new RegExp(s.replace('.',''),'i')),n&&'dddd'===t&&this._fullWeekdaysParse[r].test(e))return r;if(n&&'ddd'===t&&this._shortWeekdaysParse[r].test(e))return r;if(n&&'dd'===t&&this._minWeekdaysParse[r].test(e))return r;if(!n&&this._weekdaysParse[r].test(e))return r}}function jt(e){if(!this.isValid())return null!=e?this:NaN;var t=Qe(this,'Day');return null!=e?(e=Nt(e,this.localeData()),this.add(e-t,'d')):t}function Zt(e){if(!this.isValid())return null!=e?this:NaN;var t=(this.day()+7-this.localeData()._week.dow)%7;return null==e?t:this.add(e-t,'d')}function zt(e){if(!this.isValid())return null!=e?this:NaN;if(null!=e){var t=Pt(e,this.localeData());return this.day(this.day()%7?t:t-7)}return this.day()||7}function qt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysStrictRegex:this._weekdaysRegex):(o(this,'_weekdaysRegex')||(this._weekdaysRegex=Ut),this._weekdaysStrictRegex&&e?this._weekdaysStrictRegex:this._weekdaysRegex)}function $t(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex):(o(this,'_weekdaysShortRegex')||(this._weekdaysShortRegex=Ht),this._weekdaysShortStrictRegex&&e?this._weekdaysShortStrictRegex:this._weekdaysShortRegex)}function Bt(e){return this._weekdaysParseExact?(o(this,'_weekdaysRegex')||Jt.call(this),e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex):(o(this,'_weekdaysMinRegex')||(this._weekdaysMinRegex=At),this._weekdaysMinStrictRegex&&e?this._weekdaysMinStrictRegex:this._weekdaysMinRegex)}function Jt(){function e(e,t){return t.length-e.length}var t,n,r,i,s,a=[],o=[],l=[],u=[];for(t=0;t<7;t++)n=_([2e3,1]).day(t),r=xe(this.weekdaysMin(n,'')),i=xe(this.weekdaysShort(n,'')),s=xe(this.weekdays(n,'')),a.push(r),o.push(i),l.push(s),u.push(r),u.push(i),u.push(s);a.sort(e),o.sort(e),l.sort(e),u.sort(e),this._weekdaysRegex=new RegExp('^('+u.join('|')+')','i'),this._weekdaysShortRegex=this._weekdaysRegex,this._weekdaysMinRegex=this._weekdaysRegex,this._weekdaysStrictRegex=new RegExp('^('+l.join('|')+')','i'),this._weekdaysShortStrictRegex=new RegExp('^('+o.join('|')+')','i'),this._weekdaysMinStrictRegex=new RegExp('^('+a.join('|')+')','i')}function Qt(){return this.hours()%12||12}function Xt(){return this.hours()||24}function Kt(e,t){L(e,0,0,(function(){return this.localeData().meridiem(this.hours(),this.minutes(),t)}))}function en(e,t){return t._meridiemParse}function tn(e){return'p'===(e+'').toLowerCase().charAt(0)}L('H',['HH',2],0,'hour'),L('h',['hh',2],0,Qt),L('k',['kk',2],0,Xt),L('hmm',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)})),L('hmmss',0,0,(function(){return''+Qt.apply(this)+F(this.minutes(),2)+F(this.seconds(),2)})),L('Hmm',0,0,(function(){return''+this.hours()+F(this.minutes(),2)})),L('Hmmss',0,0,(function(){return''+this.hours()+F(this.minutes(),2)+F(this.seconds(),2)})),Kt('a',!0),Kt('A',!1),be('a',en),be('A',en),be('H',he,Ye),be('h',he,Se),be('k',he,Se),be('HH',he,le),be('hh',he,le),be('kk',he,le),be('hmm',fe),be('hmmss',_e),be('Hmm',fe),be('Hmmss',_e),Ce(['H','HH'],Le),Ce(['k','kk'],(function(e,t,n){var r=Pe(e);t[Le]=24===r?0:r})),Ce(['a','A'],(function(e,t,n){n._isPm=n._locale.isPM(e),n._meridiem=e})),Ce(['h','hh'],(function(e,t,n){t[Le]=Pe(e),p(n).bigHour=!0})),Ce('hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r)),p(n).bigHour=!0})),Ce('hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i)),p(n).bigHour=!0})),Ce('Hmm',(function(e,t,n){var r=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r))})),Ce('Hmmss',(function(e,t,n){var r=e.length-4,i=e.length-2;t[Le]=Pe(e.substr(0,r)),t[Ve]=Pe(e.substr(r,2)),t[Ie]=Pe(e.substr(i))}));var nn=/[ap]\\.?m?\\.?/i,rn=Je('Hours',!0);function sn(e,t,n){return e>11?n?'pm':'PM':n?'am':'AM'}var an,on={calendar:C,longDateFormat:Z,invalidDate:q,ordinal:B,dayOfMonthOrdinalParse:J,relativeTime:X,months:rt,monthsShort:it,week:Yt,weekdays:Ct,weekdaysMin:Ft,weekdaysShort:Wt,meridiemParse:nn},ln={},un={};function dn(e,t){var n,r=Math.min(e.length,t.length);for(n=0;n0;){if(r=_n(i.slice(0,t).join('-')))return r;if(n&&n.length>=t&&dn(i,n)>=t-1)break;t--}s++}return an}function fn(e){return!(!e||!e.match('^[^/\\\\\\\\]*$'))}function _n(t){var n=null;if(void 0===ln[t]&&e&&e.exports&&fn(t))try{n=an._abbr,Object(function(){var e=new Error('Cannot find module \\'undefined\\'');throw e.code='MODULE_NOT_FOUND',e}()),mn(n)}catch(e){ln[t]=null}return ln[t]}function mn(e,t){var n;return e&&((n=u(t)?gn(e):pn(e,t))?an=n:'undefined'!=typeof console&&console.warn&&console.warn('Locale '+e+' not found. Did you forget to load it?')),an._abbr}function pn(e,t){if(null!==t){var n,r=on;if(t.abbr=e,null!=ln[e])T('defineLocaleOverride','use moment.updateLocale(localeName, config) to change an existing locale. moment.defineLocale(localeName, config) should only be used for creating a new locale See http://momentjs.com/guides/#/warnings/define-locale/ for more info.'),r=ln[e]._config;else if(null!=t.parentLocale)if(null!=ln[t.parentLocale])r=ln[t.parentLocale]._config;else{if(null==(n=_n(t.parentLocale)))return un[t.parentLocale]||(un[t.parentLocale]=[]),un[t.parentLocale].push({name:e,config:t}),null;r=n._config}return ln[e]=new R(P(r,t)),un[e]&&un[e].forEach((function(e){pn(e.name,e.config)})),mn(e),ln[e]}return delete ln[e],null}function yn(e,t){if(null!=t){var n,r,i=on;null!=ln[e]&&null!=ln[e].parentLocale?ln[e].set(P(ln[e]._config,t)):(null!=(r=_n(e))&&(i=r._config),t=P(i,t),null==r&&(t.abbr=e),(n=new R(t)).parentLocale=ln[e],ln[e]=n),mn(e)}else null!=ln[e]&&(null!=ln[e].parentLocale?(ln[e]=ln[e].parentLocale,e===mn()&&mn(e)):null!=ln[e]&&delete ln[e]);return ln[e]}function gn(e){var t;if(e&&e._locale&&e._locale._abbr&&(e=e._locale._abbr),!e)return an;if(!s(e)){if(t=_n(e))return t;e=[e]}return hn(e)}function vn(){return b(ln)}function wn(e){var t,n=e._a;return n&&-2===p(e).overflow&&(t=n[Ae]<0||n[Ae]>11?Ae:n[Ee]<1||n[Ee]>nt(n[He],n[Ae])?Ee:n[Le]<0||n[Le]>24||24===n[Le]&&(0!==n[Ve]||0!==n[Ie]||0!==n[Ge])?Le:n[Ve]<0||n[Ve]>59?Ve:n[Ie]<0||n[Ie]>59?Ie:n[Ge]<0||n[Ge]>999?Ge:-1,p(e)._overflowDayOfYear&&(tEe)&&(t=Ee),p(e)._overflowWeeks&&-1===t&&(t=je),p(e)._overflowWeekday&&-1===t&&(t=Ze),p(e).overflow=t),e}var kn=/^\\s*((?:[+-]\\d{6}|\\d{4})-(?:\\d\\d-\\d\\d|W\\d\\d-\\d|W\\d\\d|\\d\\d\\d|\\d\\d))(?:(T| )(\\d\\d(?::\\d\\d(?::\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Dn=/^\\s*((?:[+-]\\d{6}|\\d{4})(?:\\d\\d\\d\\d|W\\d\\d\\d|W\\d\\d|\\d\\d\\d|\\d\\d|))(?:(T| )(\\d\\d(?:\\d\\d(?:\\d\\d(?:[.,]\\d+)?)?)?)([+-]\\d\\d(?::?\\d\\d)?|\\s*Z)?)?$/,Mn=/Z|[+-]\\d\\d(?::?\\d\\d)?/,Sn=[['YYYYYY-MM-DD',/[+-]\\d{6}-\\d\\d-\\d\\d/],['YYYY-MM-DD',/\\d{4}-\\d\\d-\\d\\d/],['GGGG-[W]WW-E',/\\d{4}-W\\d\\d-\\d/],['GGGG-[W]WW',/\\d{4}-W\\d\\d/,!1],['YYYY-DDD',/\\d{4}-\\d{3}/],['YYYY-MM',/\\d{4}-\\d\\d/,!1],['YYYYYYMMDD',/[+-]\\d{10}/],['YYYYMMDD',/\\d{8}/],['GGGG[W]WWE',/\\d{4}W\\d{3}/],['GGGG[W]WW',/\\d{4}W\\d{2}/,!1],['YYYYDDD',/\\d{7}/],['YYYYMM',/\\d{6}/,!1],['YYYY',/\\d{4}/,!1]],Yn=[['HH:mm:ss.SSSS',/\\d\\d:\\d\\d:\\d\\d\\.\\d+/],['HH:mm:ss,SSSS',/\\d\\d:\\d\\d:\\d\\d,\\d+/],['HH:mm:ss',/\\d\\d:\\d\\d:\\d\\d/],['HH:mm',/\\d\\d:\\d\\d/],['HHmmss.SSSS',/\\d\\d\\d\\d\\d\\d\\.\\d+/],['HHmmss,SSSS',/\\d\\d\\d\\d\\d\\d,\\d+/],['HHmmss',/\\d\\d\\d\\d\\d\\d/],['HHmm',/\\d\\d\\d\\d/],['HH',/\\d\\d/]],bn=/^\\/?Date\\((-?\\d+)/i,On=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),?\\s)?(\\d{1,2})\\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s(\\d{2,4})\\s(\\d\\d):(\\d\\d)(?::(\\d\\d))?\\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|([+-]\\d{4}))$/,Tn={UT:0,GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function xn(e){var t,n,r,i,s,a,o=e._i,l=kn.exec(o)||Dn.exec(o),u=Sn.length,d=Yn.length;if(l){for(p(e).iso=!0,t=0,n=u;tze(s)||0===e._dayOfYear)&&(p(e)._overflowDayOfYear=!0),n=vt(s,0,e._dayOfYear),e._a[Ae]=n.getUTCMonth(),e._a[Ee]=n.getUTCDate()),t=0;t<3&&null==e._a[t];++t)e._a[t]=a[t]=r[t];for(;t<7;t++)e._a[t]=a[t]=null==e._a[t]?2===t?1:0:e._a[t];24===e._a[Le]&&0===e._a[Ve]&&0===e._a[Ie]&&0===e._a[Ge]&&(e._nextDay=!0,e._a[Le]=0),e._d=(e._useUTC?vt:gt).apply(null,a),i=e._useUTC?e._d.getUTCDay():e._d.getDay(),null!=e._tzm&&e._d.setUTCMinutes(e._d.getUTCMinutes()-e._tzm),e._nextDay&&(e._a[Le]=24),e._w&&void 0!==e._w.d&&e._w.d!==i&&(p(e).weekdayMismatch=!0)}}function Ln(e){var t,n,r,i,s,a,o,l,u;null!=(t=e._w).GG||null!=t.W||null!=t.E?(s=1,a=4,n=Hn(t.GG,e._a[He],Dt(Bn(),1,4).year),r=Hn(t.W,1),((i=Hn(t.E,1))<1||i>7)&&(l=!0)):(s=e._locale._week.dow,a=e._locale._week.doy,u=Dt(Bn(),s,a),n=Hn(t.gg,e._a[He],u.year),r=Hn(t.w,u.week),null!=t.d?((i=t.d)<0||i>6)&&(l=!0):null!=t.e?(i=t.e+s,(t.e<0||t.e>6)&&(l=!0)):i=s),r<1||r>Mt(n,s,a)?p(e)._overflowWeeks=!0:null!=l?p(e)._overflowWeekday=!0:(o=kt(n,r,i,s,a),e._a[He]=o.year,e._dayOfYear=o.dayOfYear)}function Vn(e){if(e._f!==r.ISO_8601)if(e._f!==r.RFC_2822){e._a=[],p(e).empty=!0;var t,n,i,s,a,o,l,u=''+e._i,d=u.length,c=0;for(l=(i=j(e._f,e._locale).match(U)||[]).length,t=0;t0&&p(e).unusedInput.push(a),u=u.slice(u.indexOf(n)+n.length),c+=n.length),E[s]?(n?p(e).empty=!1:p(e).unusedTokens.push(s),Fe(s,n,e)):e._strict&&!n&&p(e).unusedTokens.push(s);p(e).charsLeftOver=d-c,u.length>0&&p(e).unusedInput.push(u),e._a[Le]<=12&&!0===p(e).bigHour&&e._a[Le]>0&&(p(e).bigHour=void 0),p(e).parsedDateParts=e._a.slice(0),p(e).meridiem=e._meridiem,e._a[Le]=In(e._locale,e._a[Le],e._meridiem),null!==(o=p(e).era)&&(e._a[He]=e._locale.erasConvertYear(o,e._a[He])),En(e),wn(e)}else Fn(e);else xn(e)}function In(e,t,n){var r;return null==n?t:null!=e.meridiemHour?e.meridiemHour(t,n):null!=e.isPM?((r=e.isPM(n))&&t<12&&(t+=12),r||12!==t||(t=0),t):t}function Gn(e){var t,n,r,i,s,a,o=!1,l=e._f.length;if(0===l)return p(e).invalidFormat=!0,void(e._d=new Date(NaN));for(i=0;ithis?this:e:g()}));function Xn(e,t){var n,r;if(1===t.length&&s(t[0])&&(t=t[0]),!t.length)return Bn();for(n=t[0],r=1;rthis.clone().month(0).utcOffset()||this.utcOffset()>this.clone().month(5).utcOffset()}function Dr(){if(!u(this._isDSTShifted))return this._isDSTShifted;var e,t={};return k(t,this),(t=zn(t))._a?(e=t._isUTC?_(t._a):Bn(t._a),this._isDSTShifted=this.isValid()&&ur(t._a,e.toArray())>0):this._isDSTShifted=!1,this._isDSTShifted}function Mr(){return!!this.isValid()&&!this._isUTC}function Sr(){return!!this.isValid()&&this._isUTC}function Yr(){return!!this.isValid()&&this._isUTC&&0===this._offset}r.updateOffset=function(){};var br=/^(-|\\+)?(?:(\\d*)[. ])?(\\d+):(\\d+)(?::(\\d+)(\\.\\d*)?)?$/,Or=/^(-|\\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/;function Tr(e,t){var n,r,i,s=e,a=null;return or(e)?s={ms:e._milliseconds,d:e._days,M:e._months}:d(e)||!isNaN(+e)?(s={},t?s[t]=+e:s.milliseconds=+e):(a=br.exec(e))?(n='-'===a[1]?-1:1,s={y:0,d:Pe(a[Ee])*n,h:Pe(a[Le])*n,m:Pe(a[Ve])*n,s:Pe(a[Ie])*n,ms:Pe(lr(1e3*a[Ge]))*n}):(a=Or.exec(e))?(n='-'===a[1]?-1:1,s={y:xr(a[2],n),M:xr(a[3],n),w:xr(a[4],n),d:xr(a[5],n),h:xr(a[6],n),m:xr(a[7],n),s:xr(a[8],n)}):null==s?s={}:'object'==typeof s&&('from'in s||'to'in s)&&(i=Pr(Bn(s.from),Bn(s.to)),(s={}).ms=i.milliseconds,s.M=i.months),r=new ar(s),or(e)&&o(e,'_locale')&&(r._locale=e._locale),or(e)&&o(e,'_isValid')&&(r._isValid=e._isValid),r}function xr(e,t){var n=e&&parseFloat(e.replace(',','.'));return(isNaN(n)?0:n)*t}function Nr(e,t){var n={};return n.months=t.month()-e.month()+12*(t.year()-e.year()),e.clone().add(n.months,'M').isAfter(t)&&--n.months,n.milliseconds=+t-+e.clone().add(n.months,'M'),n}function Pr(e,t){var n;return e.isValid()&&t.isValid()?(t=fr(t,e),e.isBefore(t)?n=Nr(e,t):((n=Nr(t,e)).milliseconds=-n.milliseconds,n.months=-n.months),n):{milliseconds:0,months:0}}function Rr(e,t){return function(n,r){var i;return null===r||isNaN(+r)||(T(t,'moment().'+t+'(period, number) is deprecated. Please use moment().'+t+'(number, period). See http://momentjs.com/guides/#/warnings/add-inverted-param/ for more info.'),i=n,n=r,r=i),Cr(this,Tr(n,r),e),this}}function Cr(e,t,n,i){var s=t._milliseconds,a=lr(t._days),o=lr(t._months);e.isValid()&&(i=null==i||i,o&&ht(e,Qe(e,'Month')+o*n),a&&Xe(e,'Date',Qe(e,'Date')+a*n),s&&e._d.setTime(e._d.valueOf()+s*n),i&&r.updateOffset(e,a||o))}Tr.fn=ar.prototype,Tr.invalid=sr;var Wr=Rr(1,'add'),Fr=Rr(-1,'subtract');function Ur(e){return'string'==typeof e||e instanceof String}function Hr(e){return M(e)||c(e)||Ur(e)||d(e)||Er(e)||Ar(e)||null==e}function Ar(e){var t,n,r=a(e)&&!l(e),i=!1,s=['years','year','y','months','month','M','days','day','d','dates','date','D','hours','hour','h','minutes','minute','m','seconds','second','s','milliseconds','millisecond','ms'],u=s.length;for(t=0;tn.valueOf():n.valueOf()9999?G(n,t?'YYYYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYYYY-MM-DD[T]HH:mm:ss.SSSZ'):x(Date.prototype.toISOString)?t?this.toDate().toISOString():new Date(this.valueOf()+60*this.utcOffset()*1e3).toISOString().replace('Z',G(n,'Z')):G(n,t?'YYYY-MM-DD[T]HH:mm:ss.SSS[Z]':'YYYY-MM-DD[T]HH:mm:ss.SSSZ')}function ei(){if(!this.isValid())return'moment.invalid(/* '+this._i+' */)';var e,t,n,r,i='moment',s='';return this.isLocal()||(i=0===this.utcOffset()?'moment.utc':'moment.parseZone',s='Z'),e='['+i+'(\"]',t=0<=this.year()&&this.year()<=9999?'YYYY':'YYYYYY',n='-MM-DD[T]HH:mm:ss.SSS',r=s+'[\")]',this.format(e+t+n+r)}function ti(e){e||(e=this.isUtc()?r.defaultFormatUtc:r.defaultFormat);var t=G(this,e);return this.localeData().postformat(t)}function ni(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({to:this,from:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function ri(e){return this.from(Bn(),e)}function ii(e,t){return this.isValid()&&(M(e)&&e.isValid()||Bn(e).isValid())?Tr({from:this,to:e}).locale(this.locale()).humanize(!t):this.localeData().invalidDate()}function si(e){return this.to(Bn(),e)}function ai(e){var t;return void 0===e?this._locale._abbr:(null!=(t=gn(e))&&(this._locale=t),this)}r.defaultFormat='YYYY-MM-DDTHH:mm:ssZ',r.defaultFormatUtc='YYYY-MM-DDTHH:mm:ss[Z]';var oi=Y('moment().lang() is deprecated. Instead, use moment().localeData() to get the language configuration. Use moment().locale() to change languages.',(function(e){return void 0===e?this.localeData():this.locale(e)}));function li(){return this._locale}var ui=1e3,di=60*ui,ci=60*di,hi=3506328*ci;function fi(e,t){return(e%t+t)%t}function _i(e,t,n){return e<100&&e>=0?new Date(e+400,t,n)-hi:new Date(e,t,n).valueOf()}function mi(e,t,n){return e<100&&e>=0?Date.UTC(e+400,t,n)-hi:Date.UTC(e,t,n)}function pi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year(),0,1);break;case'quarter':t=n(this.year(),this.month()-this.month()%3,1);break;case'month':t=n(this.year(),this.month(),1);break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday());break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1));break;case'day':case'date':t=n(this.year(),this.month(),this.date());break;case'hour':t=this._d.valueOf(),t-=fi(t+(this._isUTC?0:this.utcOffset()*di),ci);break;case'minute':t=this._d.valueOf(),t-=fi(t,di);break;case'second':t=this._d.valueOf(),t-=fi(t,ui)}return this._d.setTime(t),r.updateOffset(this,!0),this}function yi(e){var t,n;if(void 0===(e=ne(e))||'millisecond'===e||!this.isValid())return this;switch(n=this._isUTC?mi:_i,e){case'year':t=n(this.year()+1,0,1)-1;break;case'quarter':t=n(this.year(),this.month()-this.month()%3+3,1)-1;break;case'month':t=n(this.year(),this.month()+1,1)-1;break;case'week':t=n(this.year(),this.month(),this.date()-this.weekday()+7)-1;break;case'isoWeek':t=n(this.year(),this.month(),this.date()-(this.isoWeekday()-1)+7)-1;break;case'day':case'date':t=n(this.year(),this.month(),this.date()+1)-1;break;case'hour':t=this._d.valueOf(),t+=ci-fi(t+(this._isUTC?0:this.utcOffset()*di),ci)-1;break;case'minute':t=this._d.valueOf(),t+=di-fi(t,di)-1;break;case'second':t=this._d.valueOf(),t+=ui-fi(t,ui)-1}return this._d.setTime(t),r.updateOffset(this,!0),this}function gi(){return this._d.valueOf()-6e4*(this._offset||0)}function vi(){return Math.floor(this.valueOf()/1e3)}function wi(){return new Date(this.valueOf())}function ki(){var e=this;return[e.year(),e.month(),e.date(),e.hour(),e.minute(),e.second(),e.millisecond()]}function Di(){var e=this;return{years:e.year(),months:e.month(),date:e.date(),hours:e.hours(),minutes:e.minutes(),seconds:e.seconds(),milliseconds:e.milliseconds()}}function Mi(){return this.isValid()?this.toISOString():null}function Si(){return y(this)}function Yi(){return f({},p(this))}function bi(){return p(this).overflow}function Oi(){return{input:this._i,format:this._f,locale:this._locale,isUTC:this._isUTC,strict:this._strict}}function Ti(e,t){var n,i,s,a=this._eras||gn('en')._eras;for(n=0,i=a.length;n=0)return l[r]}function Ni(e,t){var n=e.since<=e.until?1:-1;return void 0===t?r(e.since).year():r(e.since).year()+(t-e.offset)*n}function Pi(){var e,t,n,r=this.localeData().eras();for(e=0,t=r.length;e(s=Mt(e,r,i))&&(t=s),Qi.call(this,e,t,n,r,i))}function Qi(e,t,n,r,i){var s=kt(e,t,n,r,i),a=vt(s.year,0,s.dayOfYear);return this.year(a.getUTCFullYear()),this.month(a.getUTCMonth()),this.date(a.getUTCDate()),this}function Xi(e){return null==e?Math.ceil((this.month()+1)/3):this.month(3*(e-1)+this.month()%3)}L('N',0,0,'eraAbbr'),L('NN',0,0,'eraAbbr'),L('NNN',0,0,'eraAbbr'),L('NNNN',0,0,'eraName'),L('NNNNN',0,0,'eraNarrow'),L('y',['y',1],'yo','eraYear'),L('y',['yy',2],0,'eraYear'),L('y',['yyy',3],0,'eraYear'),L('y',['yyyy',4],0,'eraYear'),be('N',Ai),be('NN',Ai),be('NNN',Ai),be('NNNN',Ei),be('NNNNN',Li),Ce(['N','NN','NNN','NNNN','NNNNN'],(function(e,t,n,r){var i=n._locale.erasParse(e,r,n._strict);i?p(n).era=i:p(n).invalidEra=e})),be('y',ge),be('yy',ge),be('yyy',ge),be('yyyy',ge),be('yo',Vi),Ce(['y','yy','yyy','yyyy'],He),Ce(['yo'],(function(e,t,n,r){var i;n._locale._eraYearOrdinalRegex&&(i=e.match(n._locale._eraYearOrdinalRegex)),n._locale.eraYearOrdinalParse?t[He]=n._locale.eraYearOrdinalParse(e,i):t[He]=parseInt(e,10)})),L(0,['gg',2],0,(function(){return this.weekYear()%100})),L(0,['GG',2],0,(function(){return this.isoWeekYear()%100})),Gi('gggg','weekYear'),Gi('ggggg','weekYear'),Gi('GGGG','isoWeekYear'),Gi('GGGGG','isoWeekYear'),be('G',ve),be('g',ve),be('GG',he,le),be('gg',he,le),be('GGGG',pe,de),be('gggg',pe,de),be('GGGGG',ye,ce),be('ggggg',ye,ce),We(['gggg','ggggg','GGGG','GGGGG'],(function(e,t,n,r){t[r.substr(0,2)]=Pe(e)})),We(['gg','GG'],(function(e,t,n,i){t[i]=r.parseTwoDigitYear(e)})),L('Q',0,'Qo','quarter'),be('Q',oe),Ce('Q',(function(e,t){t[Ae]=3*(Pe(e)-1)})),L('D',['DD',2],'Do','date'),be('D',he,Se),be('DD',he,le),be('Do',(function(e,t){return e?t._dayOfMonthOrdinalParse||t._ordinalParse:t._dayOfMonthOrdinalParseLenient})),Ce(['D','DD'],Ee),Ce('Do',(function(e,t){t[Ee]=Pe(e.match(he)[0])}));var Ki=Je('Date',!0);function es(e){var t=Math.round((this.clone().startOf('day')-this.clone().startOf('year'))/864e5)+1;return null==e?t:this.add(e-t,'d')}L('DDD',['DDDD',3],'DDDo','dayOfYear'),be('DDD',me),be('DDDD',ue),Ce(['DDD','DDDD'],(function(e,t,n){n._dayOfYear=Pe(e)})),L('m',['mm',2],0,'minute'),be('m',he,Ye),be('mm',he,le),Ce(['m','mm'],Ve);var ts=Je('Minutes',!1);L('s',['ss',2],0,'second'),be('s',he,Ye),be('ss',he,le),Ce(['s','ss'],Ie);var ns,rs,is=Je('Seconds',!1);for(L('S',0,0,(function(){return~~(this.millisecond()/100)})),L(0,['SS',2],0,(function(){return~~(this.millisecond()/10)})),L(0,['SSS',3],0,'millisecond'),L(0,['SSSS',4],0,(function(){return 10*this.millisecond()})),L(0,['SSSSS',5],0,(function(){return 100*this.millisecond()})),L(0,['SSSSSS',6],0,(function(){return 1e3*this.millisecond()})),L(0,['SSSSSSS',7],0,(function(){return 1e4*this.millisecond()})),L(0,['SSSSSSSS',8],0,(function(){return 1e5*this.millisecond()})),L(0,['SSSSSSSSS',9],0,(function(){return 1e6*this.millisecond()})),be('S',me,oe),be('SS',me,le),be('SSS',me,ue),ns='SSSS';ns.length<=9;ns+='S')be(ns,ge);function ss(e,t){t[Ge]=Pe(1e3*('0.'+e))}for(ns='S';ns.length<=9;ns+='S')Ce(ns,ss);function as(){return this._isUTC?'UTC':''}function os(){return this._isUTC?'Coordinated Universal Time':''}rs=Je('Milliseconds',!1),L('z',0,0,'zoneAbbr'),L('zz',0,0,'zoneName');var ls=D.prototype;function us(e){return Bn(1e3*e)}function ds(){return Bn.apply(null,arguments).parseZone()}function cs(e){return e}ls.add=Wr,ls.calendar=Ir,ls.clone=Gr,ls.diff=Jr,ls.endOf=yi,ls.format=ti,ls.from=ni,ls.fromNow=ri,ls.to=ii,ls.toNow=si,ls.get=Ke,ls.invalidAt=bi,ls.isAfter=jr,ls.isBefore=Zr,ls.isBetween=zr,ls.isSame=qr,ls.isSameOrAfter=$r,ls.isSameOrBefore=Br,ls.isValid=Si,ls.lang=oi,ls.locale=ai,ls.localeData=li,ls.max=Qn,ls.min=Jn,ls.parsingFlags=Yi,ls.set=et,ls.startOf=pi,ls.subtract=Fr,ls.toArray=ki,ls.toObject=Di,ls.toDate=wi,ls.toISOString=Kr,ls.inspect=ei,'undefined'!=typeof Symbol&&null!=Symbol.for&&(ls[Symbol.for('nodejs.util.inspect.custom')]=function(){return'Moment<'+this.format()+'>'}),ls.toJSON=Mi,ls.toString=Xr,ls.unix=vi,ls.valueOf=gi,ls.creationData=Oi,ls.eraName=Pi,ls.eraNarrow=Ri,ls.eraAbbr=Ci,ls.eraYear=Wi,ls.year=$e,ls.isLeapYear=Be,ls.weekYear=ji,ls.isoWeekYear=Zi,ls.quarter=ls.quarters=Xi,ls.month=ft,ls.daysInMonth=_t,ls.week=ls.weeks=Tt,ls.isoWeek=ls.isoWeeks=xt,ls.weeksInYear=$i,ls.weeksInWeekYear=Bi,ls.isoWeeksInYear=zi,ls.isoWeeksInISOWeekYear=qi,ls.date=Ki,ls.day=ls.days=jt,ls.weekday=Zt,ls.isoWeekday=zt,ls.dayOfYear=es,ls.hour=ls.hours=rn,ls.minute=ls.minutes=ts,ls.second=ls.seconds=is,ls.millisecond=ls.milliseconds=rs,ls.utcOffset=mr,ls.utc=yr,ls.local=gr,ls.parseZone=vr,ls.hasAlignedHourOffset=wr,ls.isDST=kr,ls.isLocal=Mr,ls.isUtcOffset=Sr,ls.isUtc=Yr,ls.isUTC=Yr,ls.zoneAbbr=as,ls.zoneName=os,ls.dates=Y('dates accessor is deprecated. Use date instead.',Ki),ls.months=Y('months accessor is deprecated. Use month instead',ft),ls.years=Y('years accessor is deprecated. Use year instead',$e),ls.zone=Y('moment().zone is deprecated, use moment().utcOffset instead. http://momentjs.com/guides/#/warnings/zone/',pr),ls.isDSTShifted=Y('isDSTShifted is deprecated. See http://momentjs.com/guides/#/warnings/dst-shifted/ for more information',Dr);var hs=R.prototype;function fs(e,t,n,r){var i=gn(),s=_().set(r,t);return i[n](s,e)}function _s(e,t,n){if(d(e)&&(t=e,e=void 0),e=e||'',null!=t)return fs(e,t,n,'month');var r,i=[];for(r=0;r<12;r++)i[r]=fs(e,r,n,'month');return i}function ms(e,t,n,r){'boolean'==typeof e?(d(t)&&(n=t,t=void 0),t=t||''):(n=t=e,e=!1,d(t)&&(n=t,t=void 0),t=t||'');var i,s=gn(),a=e?s._week.dow:0,o=[];if(null!=n)return fs(t,(n+a)%7,r,'day');for(i=0;i<7;i++)o[i]=fs(t,(i+a)%7,r,'day');return o}function ps(e,t){return _s(e,t,'months')}function ys(e,t){return _s(e,t,'monthsShort')}function gs(e,t,n){return ms(e,t,n,'weekdays')}function vs(e,t,n){return ms(e,t,n,'weekdaysShort')}function ws(e,t,n){return ms(e,t,n,'weekdaysMin')}hs.calendar=W,hs.longDateFormat=z,hs.invalidDate=$,hs.ordinal=Q,hs.preparse=cs,hs.postformat=cs,hs.relativeTime=K,hs.pastFuture=ee,hs.set=N,hs.eras=Ti,hs.erasParse=xi,hs.erasConvertYear=Ni,hs.erasAbbrRegex=Ui,hs.erasNameRegex=Fi,hs.erasNarrowRegex=Hi,hs.months=lt,hs.monthsShort=ut,hs.monthsParse=ct,hs.monthsRegex=pt,hs.monthsShortRegex=mt,hs.week=St,hs.firstDayOfYear=Ot,hs.firstDayOfWeek=bt,hs.weekdays=Et,hs.weekdaysMin=Vt,hs.weekdaysShort=Lt,hs.weekdaysParse=Gt,hs.weekdaysRegex=qt,hs.weekdaysShortRegex=$t,hs.weekdaysMinRegex=Bt,hs.isPM=tn,hs.meridiem=sn,mn('en',{eras:[{since:'0001-01-01',until:1/0,offset:1,name:'Anno Domini',narrow:'AD',abbr:'AD'},{since:'0000-12-31',until:-1/0,offset:1,name:'Before Christ',narrow:'BC',abbr:'BC'}],dayOfMonthOrdinalParse:/\\d{1,2}(th|st|nd|rd)/,ordinal:function(e){var t=e%10;return e+(1===Pe(e%100/10)?'th':1===t?'st':2===t?'nd':3===t?'rd':'th')}}),r.lang=Y('moment.lang is deprecated. Use moment.locale instead.',mn),r.langData=Y('moment.langData is deprecated. Use moment.localeData instead.',gn);var ks=Math.abs;function Ds(){var e=this._data;return this._milliseconds=ks(this._milliseconds),this._days=ks(this._days),this._months=ks(this._months),e.milliseconds=ks(e.milliseconds),e.seconds=ks(e.seconds),e.minutes=ks(e.minutes),e.hours=ks(e.hours),e.months=ks(e.months),e.years=ks(e.years),this}function Ms(e,t,n,r){var i=Tr(t,n);return e._milliseconds+=r*i._milliseconds,e._days+=r*i._days,e._months+=r*i._months,e._bubble()}function Ss(e,t){return Ms(this,e,t,1)}function Ys(e,t){return Ms(this,e,t,-1)}function bs(e){return e<0?Math.floor(e):Math.ceil(e)}function Os(){var e,t,n,r,i,s=this._milliseconds,a=this._days,o=this._months,l=this._data;return s>=0&&a>=0&&o>=0||s<=0&&a<=0&&o<=0||(s+=864e5*bs(xs(o)+a),a=0,o=0),l.milliseconds=s%1e3,e=Ne(s/1e3),l.seconds=e%60,t=Ne(e/60),l.minutes=t%60,n=Ne(t/60),l.hours=n%24,a+=Ne(n/24),o+=i=Ne(Ts(a)),a-=bs(xs(i)),r=Ne(o/12),o%=12,l.days=a,l.months=o,l.years=r,this}function Ts(e){return 4800*e/146097}function xs(e){return 146097*e/4800}function Ns(e){if(!this.isValid())return NaN;var t,n,r=this._milliseconds;if('month'===(e=ne(e))||'quarter'===e||'year'===e)switch(t=this._days+r/864e5,n=this._months+Ts(t),e){case'month':return n;case'quarter':return n/3;case'year':return n/12}else switch(t=this._days+Math.round(xs(this._months)),e){case'week':return t/7+r/6048e5;case'day':return t+r/864e5;case'hour':return 24*t+r/36e5;case'minute':return 1440*t+r/6e4;case'second':return 86400*t+r/1e3;case'millisecond':return Math.floor(864e5*t)+r;default:throw new Error('Unknown unit '+e)}}function Ps(e){return function(){return this.as(e)}}var Rs=Ps('ms'),Cs=Ps('s'),Ws=Ps('m'),Fs=Ps('h'),Us=Ps('d'),Hs=Ps('w'),As=Ps('M'),Es=Ps('Q'),Ls=Ps('y'),Vs=Rs;function Is(){return Tr(this)}function Gs(e){return e=ne(e),this.isValid()?this[e+'s']():NaN}function js(e){return function(){return this.isValid()?this._data[e]:NaN}}var Zs=js('milliseconds'),zs=js('seconds'),qs=js('minutes'),$s=js('hours'),Bs=js('days'),Js=js('months'),Qs=js('years');function Xs(){return Ne(this.days()/7)}var Ks=Math.round,ea={ss:44,s:45,m:45,h:22,d:26,w:null,M:11};function ta(e,t,n,r,i){return i.relativeTime(t||1,!!n,e,r)}function na(e,t,n,r){var i=Tr(e).abs(),s=Ks(i.as('s')),a=Ks(i.as('m')),o=Ks(i.as('h')),l=Ks(i.as('d')),u=Ks(i.as('M')),d=Ks(i.as('w')),c=Ks(i.as('y')),h=s<=n.ss&&['s',s]||s0,h[4]=r,ta.apply(null,h)}function ra(e){return void 0===e?Ks:'function'==typeof e&&(Ks=e,!0)}function ia(e,t){return void 0!==ea[e]&&(void 0===t?ea[e]:(ea[e]=t,'s'===e&&(ea.ss=t-1),!0))}function sa(e,t){if(!this.isValid())return this.localeData().invalidDate();var n,r,i=!1,s=ea;return'object'==typeof e&&(t=e,e=!1),'boolean'==typeof e&&(i=e),'object'==typeof t&&(s=Object.assign({},ea,t),null!=t.s&&null==t.ss&&(s.ss=t.s-1)),r=na(this,!i,s,n=this.localeData()),i&&(r=n.pastFuture(+this,r)),n.postformat(r)}var aa=Math.abs;function oa(e){return(e>0)-(e<0)||+e}function la(){if(!this.isValid())return this.localeData().invalidDate();var e,t,n,r,i,s,a,o,l=aa(this._milliseconds)/1e3,u=aa(this._days),d=aa(this._months),c=this.asSeconds();return c?(e=Ne(l/60),t=Ne(e/60),l%=60,e%=60,n=Ne(d/12),d%=12,r=l?l.toFixed(3).replace(/\\.?0+$/,''):'',i=c<0?'-':'',s=oa(this._months)!==oa(c)?'-':'',a=oa(this._days)!==oa(c)?'-':'',o=oa(this._milliseconds)!==oa(c)?'-':'',i+'P'+(n?s+n+'Y':'')+(d?s+d+'M':'')+(u?a+u+'D':'')+(t||e||l?'T':'')+(t?o+t+'H':'')+(e?o+e+'M':'')+(l?o+r+'S':'')):'P0D'}var ua=ar.prototype;return ua.isValid=ir,ua.abs=Ds,ua.add=Ss,ua.subtract=Ys,ua.as=Ns,ua.asMilliseconds=Rs,ua.asSeconds=Cs,ua.asMinutes=Ws,ua.asHours=Fs,ua.asDays=Us,ua.asWeeks=Hs,ua.asMonths=As,ua.asQuarters=Es,ua.asYears=Ls,ua.valueOf=Vs,ua._bubble=Os,ua.clone=Is,ua.get=Gs,ua.milliseconds=Zs,ua.seconds=zs,ua.minutes=qs,ua.hours=$s,ua.days=Bs,ua.weeks=Xs,ua.months=Js,ua.years=Qs,ua.humanize=sa,ua.toISOString=la,ua.toString=la,ua.toJSON=la,ua.locale=ai,ua.localeData=li,ua.toIsoString=Y('toIsoString() is deprecated. Please use toISOString() instead (notice the capitals)',la),ua.lang=oi,L('X',0,0,'unix'),L('x',0,0,'valueOf'),be('x',ve),be('X',De),Ce('X',(function(e,t,n){n._d=new Date(1e3*parseFloat(e))})),Ce('x',(function(e,t,n){n._d=new Date(Pe(e))})),r.version='2.30.1',i(Bn),r.fn=ls,r.min=Kn,r.max=er,r.now=tr,r.utc=_,r.unix=us,r.months=ps,r.isDate=c,r.locale=mn,r.invalid=g,r.duration=Tr,r.isMoment=M,r.weekdays=gs,r.parseZone=ds,r.localeData=gn,r.isDuration=or,r.monthsShort=ys,r.weekdaysMin=ws,r.defineLocale=pn,r.updateLocale=yn,r.locales=vn,r.weekdaysShort=vs,r.normalizeUnits=ne,r.relativeTimeRounding=ra,r.relativeTimeThreshold=ia,r.calendarFormat=Vr,r.prototype=ls,r.HTML5_FMT={DATETIME_LOCAL:'YYYY-MM-DDTHH:mm',DATETIME_LOCAL_SECONDS:'YYYY-MM-DDTHH:mm:ss',DATETIME_LOCAL_MS:'YYYY-MM-DDTHH:mm:ss.SSS',DATE:'YYYY-MM-DD',TIME:'HH:mm',TIME_SECONDS:'HH:mm:ss',TIME_MS:'HH:mm:ss.SSS',WEEK:'GGGG-[W]WW',MONTH:'YYYY-MM'},r}()},597:e=>{function t(e){return e?Array.isArray(e)?e:[e]:[]}function n(e,t){switch(typeof e){case'undefined':return!0;case'function':return e(t);default:return e}}function r(e,t,r){if(n(e.appliesIf,r)){var i='function'==typeof e.fields?e.fields(r):e.fields.filter((function(e){return n(e.appliesIf,r)})).map((function(e){var t={};return s(e,t,'label'),s(e,t,'value'),s(e,t,'translate'),s(e,t,'filter'),s(e,t,'width'),s(e,t,'icon'),e.context&&(t.context={},s(e.context,t.context,'count'),s(e.context,t.context,'total')),t}));return e.modifyContext&&e.modifyContext(t,r),{label:e.label,fields:i}}function s(e,t,n){switch(typeof e[n]){case'undefined':return;case'function':t[n]=e[n](r);break;default:t[n]=e[n]}}}e.exports=function(e,n,i){var s=e.fields||[],a=e.context||{},o=e.cards||[],l=n&&('contact'===n.type?n.contact_type:n.type),u={cards:[],fields:s.filter((function(e){var n=t(e.appliesToType),r=n.filter((function(e){return e&&'!'===e.charAt(0)}));if((0===n.length||n.includes(l)||r.length>0&&!r.includes('!'+l))&&(!e.appliesIf||e.appliesIf()))return delete e.appliesToType,delete e.appliesIf,!0}))};return o.forEach((function(e){var n,s,o,d,c=t(e.appliesToType);if(c.includes('report')&&c.length>1)throw new Error('You cannot set appliesToType to an array which includes the type \\'report\\' and another type.');if(c.includes('report'))for(n=0;n0)return;(o=r(e,a))&&u.cards.push(o)}})),u.context=a,u}},766:(e,t,n)=>{const r=n(420),i=r().startOf('day'),s=['pregnancy'],a=['pregnancy_home_visit'],o=['delivery'],l=['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregannacy_danger_sign_follow_up'],u=294,d=(e,t)=>['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t,n,r){return e.filter((function(e){return t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r}))}function h(e,t){let n;return e.forEach((function(e){(function(e){return!!(e.form&&e.fields&&e.reported_date)})(e)&&t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function f(e){return M(e)&&d(e,'lmp_date_8601')&&r(d(e,'lmp_date_8601'))}function _(e,t){let n=f(t),i=t.reported_date;return x(e,t).forEach((function(e){const t=S(s=e)&&d(s,'lmp_date_8601')&&r(d(s,'lmp_date_8601'));var s;e.reported_date>i&&'yes'===d(e,'lmp_updated')&&(i=e.reported_date,n=t)})),n}function m(e,t){const n=_(e,t);if(n)return n.clone().add(280,'days')}function p(e){return Y(e)&&d(e,'delivery_outcome.delivery_date')&&r(d(e,'delivery_outcome.delivery_date'))}function y(e){const t=[];if('yes'===d(e,'t_danger_signs_referral_follow_up')){const n=d(e,'danger_signs');if(n)for(const e in n)'yes'===n[e]&&'r_danger_sign_present'!==e&&t.push(e)}return t}function g(e){const t=[];if(!M(e))return[];if('yes'===d(e,'risk_factors.r_risk_factor_present')){'yes'===d(e,'risk_factors.risk_factors_history.first_pregnancy')&&t.push('first_pregnancy'),'yes'===d(e,'risk_factors.risk_factors_history.previous_miscarriage')&&t.push('previous_miscarriage');const n=d(e,'risk_factors.risk_factors_present.primary_condition'),r=d(e,'risk_factors.risk_factors_present.secondary_condition');n&&t.push(...n.split(' ')),r&&t.push(...r.split(' '))}return t}function v(e,t){const n=g(t);return x(e,t).forEach((function(e){n.push(...function(e){const t=[];if(!S(e))return[];if('yes'===d(e,'anc_visits_hf.risk_factors.r_risk_factor_present')){const n=d(e,'anc_visits_hf.risk_factors.new_risks');n&&t.push(...n.split(' '))}return t}(e))})),n}function w(e){let t;return e&&M(e)?t=d(e,'risk_factors.risk_factors_present.additional_risk'):e&&S(e)&&(t=d(e,'anc_visits_hf.risk_factors.additional_risk')),t}function k(e,t){const n=[],r=w(t);r&&n.push(r);return x(e,t).forEach((function(e){const t=w(e);t&&n.push(t)})),n}function D(e){return e&&!e.date_of_death}function M(e){return e&&s.includes(e.form)}function S(e){return e&&a.includes(e.form)}function Y(e){return e&&o.includes(e.form)}function b(e,t,n){if('person'!==e.type||!D(e)||!M(n))return!1;const r=(_(t,n)||n.reported_date)>i.clone().subtract(u,'day'),s=T(t,n,42).length>0,a=function(e,t){return e.filter((function(e){return M(e)&&e.reported_date>t.reported_date}))}(t,n).length>0;return r&&!s&&!a&&!O(t,n,'abortion')&&!O(t,n,'miscarriage')}function O(e,t,n){const r=h(x(e,t),a);if(r&&d(r,'pregnancy_summary.visit_option')===n)return r}function T(e,t,n){return e.filter((function(e){return Y(e)&&e.reported_date>t.reported_date&&(!n||e.reported_date>=i.clone().subtract(n,'days'))}))}function x(e,t){let n=f(t);n||(n=r(t.reported_date));return e.filter((function(e){return S(e)&&e.reported_date>t.reported_date&&r(e.reported_date)b(e)))},isActivePregnancy:b,countANCFacilityVisits:function(e,t){let n=0;const r=x(e,t);return d(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(d(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=d(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},knowsHIVStatusInPast3Months:function(e){let t=!1;return c(e,s,i.clone().subtract(3,'months'),i).forEach((function(e){'yes'===d(e,'pregnancy_new_or_current.hiv_status.hiv_status_know')&&(t=!0)})),t},getAllRiskFactors:v,getAllRiskFactorExtra:k,getDangerSignCodes:y,getLatestDangerSignsForPregnancy:function(e,t){if(!t)return[];let n=_(e,t);n||(n=r(t.reported_date));const i=c(e,l,n.toDate(),n.clone().add(u,'days').toDate()),s=[];i.forEach((e=>{S(e)?'yes'===d(e,'pregnancy_summary.visit_option')&&s.push(e):s.push(e)}));const a=h(s,l);return a?y(a):[]},getNextANCVisitDate:function(e,t){let n=d(t,'t_pregnancy_follow_up_date'),i=t.reported_date;return x(e,t).forEach((function(e){e.reported_date>i&&d(e,'t_pregnancy_follow_up_date')&&(i=e.reported_date,n=d(e,'t_pregnancy_follow_up_date'))})),r(n)},isReadyForNewPregnancy:function(e,t){if('person'!==e.type)return!1;const n=h(t,s),a=h(t,o);if(!n&&!a)return!0;if(n){if(!a||a.reported_daten.reported_date))return p(a){const r=n(420),i=n(766),{today:s,MAX_DAYS_IN_PREGNANCY:a,isHighRiskPregnancy:o,getNewestReport:l,getSubsequentPregnancyFollowUps:u,getSubsequentDeliveries:d,isAlive:c,isReadyForNewPregnancy:h,isReadyForDelivery:f,isActivePregnancy:_,countANCFacilityVisits:m,getAllRiskFactors:p,getLatestDangerSignsForPregnancy:y,getNextANCVisitDate:g,getMostRecentLMPDateForPregnancy:v,getMostRecentEDDForPregnancy:w,getDeliveryDate:k,getFormArraySubmittedInWindow:D,getRecentANCVisitWithEvent:M,getAllRiskFactorExtra:S,getField:Y}=i,b=contact,O=lineage,T=reports,x={alive:c(b),muted:!1,show_pregnancy_form:h(b,T),show_delivery_form:f(b,T)},N=[{appliesToType:'person',label:'patient_id',value:b.patient_id,width:4},{appliesToType:'person',label:'contact.age',value:b.date_of_birth,width:4,filter:'age'},{appliesToType:'person',label:'contact.sex',value:'contact.sex.'+b.sex,translate:!0,width:4},{appliesToType:'person',label:'person.field.phone',value:b.phone,width:4},{appliesToType:'person',label:'person.field.alternate_phone',value:b.phone_alternate,width:4},{appliesToType:'person',label:'External ID',value:b.external_id,width:4},{appliesToType:'person',label:'contact.parent',value:O,filter:'lineage'},{appliesToType:'!person',label:'contact',value:b.contact&&b.contact.name,width:4},{appliesToType:'!person',label:'contact.phone',value:b.contact&&b.contact.phone,width:4},{appliesToType:'!person',label:'External ID',value:b.external_id,width:4},{appliesToType:'!person',appliesIf:function(){return b.parent&&O[0]},label:'contact.parent',value:O,filter:'lineage'},{appliesToType:'person',label:'contact.notes',value:b.notes,width:12},{appliesToType:'!person',label:'contact.notes',value:b.notes,width:12}];b.short_name&&N.unshift({appliesToType:'person',label:'contact.short_name',value:b.short_name,width:4});const P=[{label:'contact.profile.pregnancy.active',appliesToType:'report',appliesIf:function(e){return _(b,T,e)},fields:function(e){const t=[],n=p(T,e),i=S(T,e),a=y(T,e),d=o(T,e),c=l(T,['pregnancy','pregnancy_home_visit']),h=r(c.reported_date),f=v(T,e),_=w(T,e),k=g(T,e),D=f?s.diff(f,'weeks'):null;let b=Y(e,'lmp_approx'),O=e.reported_date;u(T,e).forEach((function(e){e.reported_date>O&&'yes'===Y(e,'lmp_updated')&&(O=e.reported_date,Y(e,'lmp_method_approx')&&(b=Y(e,'lmp_method_approx')))}));const x=M(T,e,'migrated'),N=M(T,e,'refused'),P=x||N;if(P){const e='clear_all'===Y(P,'pregnancy_ended.clear_option');t.push({label:'contact.profile.change_care',value:x?'Migrated out of area':'Refusing care',width:6},{label:'contact.profile.tasks_on_off',value:e?'Off':'On',width:6})}if(t.push({label:'Weeks Pregnant',value:D||0===D?{number:D,approximate:'yes'===b}:'contact.profile.value.unknown',translate:!D&&0!==D,filter:D||0===D?'weeksPregnant':'',width:6},{label:'contact.profile.edd',value:_?_.valueOf():'contact.profile.value.unknown',translate:!_,filter:_?'simpleDate':'',width:6}),d){let e='';e=!n&&i?i.join(', '):n.length>1||n&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+n[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}return a.length>0&&t.push({label:'contact.profile.danger_signs.current',value:a.length>1?'contact.profile.danger_sign.multiple':'contact.profile.danger_sign.'+a[0],translate:!0,width:6}),t.push({label:'contact.profile.visit',value:'contact.profile.visits.of',context:{count:m(T,e),total:8},translate:!0,width:6},{label:'contact.profile.last_visited',value:h.valueOf(),filter:'relativeDay',width:6}),k&&k.isSameOrAfter(s)&&t.push({label:'contact.profile.anc.next',value:k.valueOf(),filter:'simpleDate',width:6}),t},modifyContext:function(e,t){let n=Y(t,'lmp_date_8601'),r=Y(t,'lmp_method_approx'),i=Y(t,'hiv_status_known'),s=Y(t,'deworming_med_received'),a=Y(t,'tt_received');const o=p(T,t),l=S(T,t);let d=Y(t,'t_pregnancy_follow_up_date');u(T,t).forEach((function(e){'yes'===Y(e,'lmp_updated')&&(n=Y(e,'lmp_date_8601'),r=Y(e,'lmp_method_approx')),i=Y(e,'hiv_status_known'),s=Y(e,'deworming_med_received'),a=Y(e,'tt_received'),'yes'===Y(e,'t_pregnancy_follow_up')&&(d=Y(e,'t_pregnancy_follow_up_date'))})),e.lmp_date_8601=n,e.lmp_method_approx=r,e.is_active_pregnancy=!0,e.deworming_med_received=s,e.hiv_tested_past=i,e.tt_received_past=a,e.risk_factor_codes=o.join(' '),e.risk_factor_extra=l.join('; '),e.pregnancy_follow_up_date_recent=d,e.pregnancy_uuid=t._id}},{label:'contact.profile.death.title',appliesToType:'person',appliesIf:function(){return!c(b)},fields:function(){const e=[];let t,n;const r=l(T,['death_report']);if(r){const e=Y(r,'death_details');e&&(t=e.date_of_death,n=e.place_of_death)}else b.date_of_death&&(t=b.date_of_death);return e.push({label:'contact.profile.death.date',value:t||'contact.profile.value.unknown',filter:t?'simpleDate':'',translate:!t,width:6},{label:'contact.profile.death.place',value:n||'contact.profile.value.unknown',translate:!0,width:6}),e}},{label:'contact.profile.pregnancy.past',appliesToType:'report',appliesIf:function(e){if('person'!==b.type)return!1;if('delivery'===e.form)return!0;if('pregnancy'===e.form){if(M(T,e,'abortion')||M(T,e,'miscarriage'))return!0;const t=v(T,e);return t&&s.isSameOrAfter(t.clone().add(42,'weeks'))&&0===d(T,e,a).length}return!1},fields:function(e){const t=[];let n,i,l='',u=0,c=0,h=0;if('delivery'===e.form){const s=r(e.reported_date);n=D(T,['pregnancy'],s.clone().subtract(a,'days').toDate(),s.toDate())[0],Y(e,'delivery_outcome')&&(i=k(e),l=Y(e,'delivery_outcome.delivery_place'),u=Y(e,'delivery_outcome.babies_delivered_num'),c=Y(e,'delivery_outcome.babies_deceased_num'),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'',filter:'simpleDate',width:6},{label:'contact.profile.delivery_place',value:l,translate:!0,width:6},{label:'contact.profile.delivered_babies',value:u,width:6}))}else if('pregnancy'===e.form){n=e;const o=v(T,n),l=M(T,n,'abortion'),u=M(T,n,'miscarriage');if(l||u){let e='',n=r(0),i=0;l?(e='abortion',n=r(Y(l,'pregnancy_ended.abortion_date'))):(e='miscarriage',n=r(Y(u,'pregnancy_ended.miscarriage_date'))),i=n.diff(o,'weeks'),t.push({label:'contact.profile.pregnancy.end_early',value:e,translate:!0,width:6},{label:'contact.profile.pregnancy.end_date',value:n.valueOf(),filter:'simpleDate',width:6},{label:'contact.profile.pregnancy.end_weeks',value:i>0?i:'contact.profile.value.unknown',translate:i<=0,width:6})}else o&&s.isSameOrAfter(o.clone().add(42,'weeks'))&&0===d(T,e,a).length&&(i=w(T,e),t.push({label:'contact.profile.delivery_date',value:i?i.valueOf():'contact.profile.value.unknown',filter:'simpleDate',translate:!i,width:6}))}if(c>0&&Y(e,'baby_death')){t.push({label:'contact.profile.deceased_babies',value:c,width:6});let n=Y(e,'baby_death.baby_death_repeat');n||(n=[]);let r=0;n.forEach((function(e){r>0&&t.push({label:'',value:'',width:6}),t.push({label:'contact.profile.newborn.death_date',value:e.baby_death_date,filter:'simpleDate',width:6},{label:'contact.profile.newborn.death_place',value:e.baby_death_place,translate:!0,width:6},{label:'contact.profile.delivery.stillbirthQ',value:e.stillbirth,translate:!0,width:6}),r++,r===n.length&&t.push({label:'',value:'',width:6})}))}if(n){h=m(T,n),t.push({label:'contact.profile.anc_visit',value:h,width:3});if(o(T,n)){let e='';const r=p(T,n),i=S(T,n);e=!r&&i?i.join(', '):r.length>1||r&&i?'contact.profile.risk.multiple':'contact.profile.danger_sign.'+r[0],t.push({label:'contact.profile.risk.high',value:e,translate:!0,icon:'icon-risk',width:6})}}return t}}];e.exports={context:x,cards:P,fields:N}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={id:r,loaded:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.loaded=!0,s.exports}return n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e),n(344)})())); return ContactSummary;", "tasks": { - "rules": "(()=>{var e={730(e){function t(e,n){var r=Object.keys(e);for(var i in r){var o=r[i];switch(typeof e[o]){case'object':t(e[o],n);break;case'function':e[o]=e[o].bind(n)}}}function n(e){var t=Object.assign({},e),r=Object.keys(t);for(var i in r){var o=r[i];if(Array.isArray(t[o])){t[o]=t[o].slice(0);for(var a=0;a['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&!e.deleted&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function p(e){if(!e)return new Date;const t=e.split(/\\D/),n=new Date(t[0],t[1]-1,t[2]);return function(e){return e instanceof Date&&!isNaN(e)}(n)?n:new Date}function l(e){const t=new Date(e);return t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t}function d(e){if('string'==typeof e){if(''===e)return null;e=p(e)}return l(e).getTime()}function _(e,t){const n=l(new Date(e));return n.setDate(n.getDate()+t),n}function u(e){return r.includes(e.form)}function f(e){return o.includes(e.form)}const g=function(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n},y=function(e){return u(e)&&d(s(e,'lmp_date_8601'))};function m(e,t){return e.reports.filter((function(e){let n=y(t);return n||(n=t.reported_date),f(e)&&e.reported_date>t.reported_date&&e.reported_date<_(n,294)}))}function v(e,t){let n=y(t),r=t.reported_date;return m(e,t).forEach((function(e){const t=function(e){return f(e)&&d(s(e,'lmp_date_8601'))}(e);e.reported_date>r&&''!==t&&t!==n&&(r=e.reported_date,n=t)})),n}e.exports={today:t,MS_IN_DAY:n,MAX_DAYS_IN_PREGNANCY:294,addDays:_,isAlive:function(e){return e&&e.contact&&!e.contact.date_of_death},getTimeForMidnight:l,isFormArraySubmittedInWindow:function(e,t,n,r,i){let o=!1,a=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(o=!0,i&&a++)})),i?a>=i:o},isFormArraySubmittedInWindowExcludingThisReport:function(e,t,n,r,i,o){let a=!1,s=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&e._id!==i._id&&(a=!0,o&&s++)})),o?s>=o:a},getDateMS:d,getDateISOLocal:p,isDeliveryForm:function(e){return i.includes(e.form)},getMostRecentReport:c,getNewestPregnancyTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'pregnancy');return t?t.reported_date:0},getNewestDeliveryTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'delivery');return t?t.reported_date:0},getReportsSubmittedInWindow:function(e,t,n,r,i){const o=[];return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o.push(e))})),o},countReportsSubmittedInWindow:function(e,t,n,r,i){let o=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o++)})),o},countANCFacilityVisits:function(e,t){let n=0;const r=m(e,t);return s(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=s(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},isFacilityDelivery:function(e,t){return!!e&&(1===arguments.length&&(t=e),'yes'===s(t,'facility_delivery'))},getMostRecentLMPDateForPregnancy:v,getNewestReport:g,getSubsequentPregnancyFollowUps:m,isActivePregnancy:function(e,r){if(!u(r))return!1;const i=(v(e,r)||r.reported_date)>t-254016e5,a=function(e,r,i){return e.reports.filter((function(e){return'delivery'===e.form&&e.reported_date>r.reported_date&&(!i||r.reported_date>=t-i*n)}))}(e,r,42).length>0,c=function(e,t){return e.reports.filter((function(e){return u(e)&&e.reported_date>t.reported_date}))}(e,r).length>0;return i&&!a&&!c&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'abortion'===s(r,'pregnancy_summary.visit_option')}(e,r)&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'miscarriage'===s(r,'pregnancy_summary.visit_option')}(e,r)},getRecentANCVisitWithEvent:function(e,t,n){const r=m(e,t),i=g(r,o);if(i&&s(i,'pregnancy_summary.visit_option')===n)return i},isPregnancyTaskMuted:function(e){const t=g(e.reports,a);return t&&f(t)&&'clear_all'===s(t,'pregnancy_ended.clear_option')},getField:s}},931(e,t,n){const r=n(190),{isAlive:i,getSubsequentPregnancyFollowUps:o,getMostRecentLMPDateForPregnancy:a,isActivePregnancy:s,countANCFacilityVisits:c,getField:p}=r;e.exports=[{id:'deaths-this-month',type:'count',icon:'icon-death-general',goal:0,translation_key:'targets.death_reporting.deaths.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return!i(e)},date:e=>e.contact.date_of_death},{id:'pregnancy-registrations-this-month',type:'count',icon:'icon-pregnancy',goal:20,translation_key:'targets.anc.new_pregnancy_registrations.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return!!t&&a(e,t)},date:'reported',idType:'contact'},{id:'births-this-month',type:'count',icon:'icon-infant',goal:-1,translation_key:'targets.births.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e&&e.contact&&e.contact.date_of_birth},date:e=>e.contact.date_of_birth,dhis:{dataElement:'kB0ZBFisE0e'}},{id:'active-pregnancies',type:'count',icon:'icon-pregnancy',goal:-1,translation_key:'targets.anc.active_pregnancies.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return s(e,t)},date:'now',idType:'contact'},{id:'active-pregnancies-1+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_1p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>0},date:'now',idType:'contact'},{id:'facility-deliveries',type:'percent',icon:'icon-mother-child',goal:-1,translation_key:'targets.anc.facility_deliveries.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['delivery'],appliesIf:function(e,t){return p(t,'delivery_outcome.delivery_place')},passesIf:function(e,t){return'health_facility'===p(t,'delivery_outcome.delivery_place')},date:'now',idType:'contact',dhis:{dataElement:'e22tIwy1nKR',categoryOptionCombo:'HllvX50cXC0',attributeOptionCombo:'HllvX50cXC0'}},{id:'active-pregnancies-4+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_4p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>3},date:'now',idType:'contact'},{id:'active-pregnancies-8+-contacts',type:'count',icon:'icon-follow-up',goal:-1,translation_key:'targets.anc.active_pregnancies_8p_contacts.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return 1+(o(e,t).length||0)+(c(e,t)||0)>7},date:'now',idType:'contact'}]},991(e,t,n){const r=n(190),{MAX_DAYS_IN_PREGNANCY:i,today:o,getNewestPregnancyTimestamp:a,getNewestDeliveryTimestamp:s,isAlive:c,isFormArraySubmittedInWindow:p,getDateISOLocal:l,getTimeForMidnight:d,isDeliveryForm:_,getMostRecentLMPDateForPregnancy:u,addDays:f,getRecentANCVisitWithEvent:g,isPregnancyTaskMuted:y,getField:m}=r,v=(e,t,n)=>({id:`pregnancy-home-visit-week${e}`,start:t,end:n,dueDate:function(t,n,r){const i=u(n,r);return f(i||r.reported_date,7*e)}});function h(e,t,n,r){if(t.reported_date=o},resolvedIf:h,actions:[{type:'report',form:'pregnancy_home_visit',label:'Pregnancy home visit'}],events:[...Array(21).keys()].map((e=>v(2*(e+1),6,7)))},{name:'anc.facility_reminder',icon:'icon-pregnancy',title:'task.anc.facility_reminder.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit'],appliesIf:function(e,t){return m(t,'t_pregnancy_follow_up_date')},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_facility_visit_reminder'],i,o)},actions:[{type:'report',form:'pregnancy_facility_visit_reminder',label:'Pregnancy facility visit reminder',modifyContent:function(e,t,n){e.source_visit_date=m(n,'t_pregnancy_follow_up_date')}}],events:[{id:'pregnancy-facility-visit-reminder',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_pregnancy_follow_up_date'))}}]},{name:'anc.pregnancy_danger_sign_followup',icon:'icon-pregnancy-danger',title:'task.anc.pregnancy_danger_sign_followup.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregnancy_danger_sign_follow_up'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_danger_sign_follow_up'],i,o)},actions:[{type:'report',form:'pregnancy_danger_sign_follow_up'}],events:[{id:'pregnancy-danger-sign-follow-up',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'anc.delivery',icon:'icon-mother-child',title:'task.anc.delivery.title',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){const n=u(e,t);return n&&f(n,336)>=o&&c(e)},resolvedIf:function(e,t,n,r){if(g(e,t,'abortion')||g(e,t,'miscarriage'))return!0;if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['delivery'],i,o)},actions:[{type:'report',form:'delivery'}],events:[{id:'delivery-reminder',start:28,end:42,dueDate:function(e,t,n){return f(u(t,n),i)}}]},{name:'pnc.danger_sign_followup_mother',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_mother.title',appliesTo:'reports',appliesToType:['delivery','pnc_danger_sign_follow_up_mother'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_mother'],i,o)},actions:[{type:'report',form:'pnc_danger_sign_follow_up_mother',modifyContent:function(e,t,n){_(n)?e.delivery_uuid=n._id:e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-mother',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'pnc.danger_sign_followup_baby.from_contact',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e.contact&&'yes'===e.contact.t_danger_signs_referral_follow_up&&c(e)},resolvedIf:function(e,t,n,r){const i=Math.max(f(r,-n.start).getTime(),e.contact.reported_date),o=f(r,n.end).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t){e.delivery_uuid=t.contact.created_by_doc}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t){return l(t.contact.t_danger_signs_referral_follow_up_date)}}]},{name:'pnc.danger_sign_followup_baby.from_report',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'reports',appliesToType:['pnc_danger_sign_follow_up_baby'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t,n){e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]}]}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}var r=n(991),i=n(931),o=n(85);n(945)(i,c,Utils,Target,emit),o(r,c,Utils,Task,emit),emit('_complete',{_id:!0})})();", + "rules": "(()=>{var e={85:(e,t,n)=>{var r=n(730),i=n(721);function o(e,t,n,r,i,o){var a;if(e.appliesToType){var s;if('contacts'===e.appliesTo){if(!i.contact)return;s='contact'===i.contact.type?i.contact.contact_type:i.contact.type}else{if(!o)return;s=o.form}if(-1===e.appliesToType.indexOf(s))return}if('scheduled_tasks'===e.appliesTo||!e.appliesIf||e.appliesIf(i,o))if('scheduled_tasks'===e.appliesTo){if(o&&e.appliesIf){if(!o.scheduled_tasks)return;for(a=0;a{const t=d(Date.now()),n=864e5,r=['pregnancy'],i=['delivery'],o=['pregnancy_home_visit'],a=['pregnancy','pregnancy_home_visit','pregnancy_facility_visit_reminder','pregnancy_danger_sign','pregnancy_danger_sign_follow_up','delivery'];const s=(e,t)=>['fields',...(t||'').split('.')].reduce(((e,t)=>{if(void 0!==e)return e[t]}),e);function c(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&!e.deleted&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n}function p(e){if(!e)return new Date;const t=e.split(/\\D/),n=new Date(t[0],t[1]-1,t[2]);return function(e){return e instanceof Date&&!isNaN(e)}(n)?n:new Date}function l(e){const t=new Date(e);return t.setHours(0),t.setMinutes(0),t.setSeconds(0),t.setMilliseconds(0),t}function d(e){if('string'==typeof e){if(''===e)return null;e=p(e)}return l(e).getTime()}function _(e,t){const n=l(new Date(e));return n.setDate(n.getDate()+t),n}function u(e){return r.includes(e.form)}function f(e){return o.includes(e.form)}const g=function(e,t){let n;return e.forEach((function(e){t.includes(e.form)&&(!n||e.reported_date>n.reported_date)&&(n=e)})),n},y=function(e){return u(e)&&d(s(e,'lmp_date_8601'))};function m(e,t){return e.reports.filter((function(e){let n=y(t);return n||(n=t.reported_date),f(e)&&e.reported_date>t.reported_date&&e.reported_date<_(n,294)}))}function v(e,t){let n=y(t),r=t.reported_date;return m(e,t).forEach((function(e){const t=function(e){return f(e)&&d(s(e,'lmp_date_8601'))}(e);e.reported_date>r&&''!==t&&t!==n&&(r=e.reported_date,n=t)})),n}e.exports={today:t,MS_IN_DAY:n,MAX_DAYS_IN_PREGNANCY:294,addDays:_,isAlive:function(e){return e&&e.contact&&!e.contact.date_of_death},getTimeForMidnight:l,isFormArraySubmittedInWindow:function(e,t,n,r,i){let o=!1,a=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(o=!0,i&&a++)})),i?a>=i:o},isFormArraySubmittedInWindowExcludingThisReport:function(e,t,n,r,i,o){let a=!1,s=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&e._id!==i._id&&(a=!0,o&&s++)})),o?s>=o:a},getDateMS:d,getDateISOLocal:p,isDeliveryForm:function(e){return i.includes(e.form)},getMostRecentReport:c,getNewestPregnancyTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'pregnancy');return t?t.reported_date:0},getNewestDeliveryTimestamp:function(e){if(!e.contact)return;const t=c(e.reports,'delivery');return t?t.reported_date:0},getReportsSubmittedInWindow:function(e,t,n,r,i){const o=[];return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o.push(e))})),o},countReportsSubmittedInWindow:function(e,t,n,r,i){let o=0;return e.forEach((function(e){t.includes(e.form)&&e.reported_date>=n&&e.reported_date<=r&&(i&&!i(e)||o++)})),o},countANCFacilityVisits:function(e,t){let n=0;const r=m(e,t);return s(t,'anc_visits_hf.anc_visits_hf_past')&&!isNaN(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))&&(n+=parseInt(s(t,'anc_visits_hf.anc_visits_hf_past.visited_hf_count'))),n+=r.reduce((function(e,t){const n=s(t,'anc_visits_hf.anc_visits_hf_past');return n?(e+='yes'===n.last_visit_attended&&1,isNaN(n.visited_hf_count)?e:e+('yes'===n.report_other_visits&&parseInt(n.visited_hf_count))):0}),0),n},isFacilityDelivery:function(e,t){return!!e&&(1===arguments.length&&(t=e),'yes'===s(t,'facility_delivery'))},getMostRecentLMPDateForPregnancy:v,getNewestReport:g,getSubsequentPregnancyFollowUps:m,isActivePregnancy:function(e,r){if(!u(r))return!1;const i=(v(e,r)||r.reported_date)>t-254016e5,a=function(e,r,i){return e.reports.filter((function(e){return'delivery'===e.form&&e.reported_date>r.reported_date&&(!i||r.reported_date>=t-i*n)}))}(e,r,42).length>0,c=function(e,t){return e.reports.filter((function(e){return u(e)&&e.reported_date>t.reported_date}))}(e,r).length>0;return i&&!a&&!c&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'abortion'===s(r,'pregnancy_summary.visit_option')}(e,r)&&!function(e,t){const n=m(e,t),r=g(n,o);return r&&'miscarriage'===s(r,'pregnancy_summary.visit_option')}(e,r)},getRecentANCVisitWithEvent:function(e,t,n){const r=m(e,t),i=g(r,o);if(i&&s(i,'pregnancy_summary.visit_option')===n)return i},isPregnancyTaskMuted:function(e){const t=g(e.reports,a);return t&&f(t)&&'clear_all'===s(t,'pregnancy_ended.clear_option')},getField:s}},721:e=>{e.exports={defaultResolvedIf:function(e,t,n,r,i){var o,a;i||(i=Utils);var s=function(e){var t;if(!e||!e.actions)return;return(t=e.actions.find((function(e){return!e.type||'report'===e.type})))&&t.form}(this.definition);if(!s)throw new Error('Could not find the default resolving form!');return o=0,o=t?Math.max(i.addDate(r,-n.start).getTime(),t.reported_date+1):i.addDate(r,-n.start).getTime(),a=i.addDate(r,n.end+1).getTime(),i.isFormSubmittedInWindow(e.reports,s,o,a)}}},730:e=>{function t(e,n){var r=Object.keys(e);for(var i in r){var o=r[i];switch(typeof e[o]){case'object':t(e[o],n);break;case'function':e[o]=e[o].bind(n)}}}function n(e){var t=Object.assign({},e),r=Object.keys(t);for(var i in r){var o=r[i];if(Array.isArray(t[o])){t[o]=t[o].slice(0);for(var a=0;a{const r=n(190),{isAlive:i,getSubsequentPregnancyFollowUps:o,getMostRecentLMPDateForPregnancy:a,isActivePregnancy:s,countANCFacilityVisits:c,getField:p}=r;e.exports=[{id:'deaths-this-month',type:'count',icon:'icon-death-general',goal:0,translation_key:'targets.death_reporting.deaths.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return!i(e)},date:e=>e.contact.date_of_death},{id:'pregnancy-registrations-this-month',type:'count',icon:'icon-pregnancy',goal:20,translation_key:'targets.anc.new_pregnancy_registrations.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return!!t&&a(e,t)},date:'reported',idType:'contact'},{id:'births-this-month',type:'count',icon:'icon-infant',goal:-1,translation_key:'targets.births.title',subtitle_translation_key:'targets.this_month.subtitle',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e&&e.contact&&e.contact.date_of_birth},date:e=>e.contact.date_of_birth,dhis:{dataElement:'kB0ZBFisE0e'}},{id:'active-pregnancies',type:'count',icon:'icon-pregnancy',goal:-1,translation_key:'targets.anc.active_pregnancies.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){return s(e,t)},date:'now',idType:'contact'},{id:'active-pregnancies-1+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_1p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>0},date:'now',idType:'contact'},{id:'facility-deliveries',type:'percent',icon:'icon-mother-child',goal:-1,translation_key:'targets.anc.facility_deliveries.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['delivery'],appliesIf:function(e,t){return p(t,'delivery_outcome.delivery_place')},passesIf:function(e,t){return'health_facility'===p(t,'delivery_outcome.delivery_place')},date:'now',idType:'contact',dhis:{dataElement:'e22tIwy1nKR',categoryOptionCombo:'HllvX50cXC0',attributeOptionCombo:'HllvX50cXC0'}},{id:'active-pregnancies-4+-visits',type:'count',icon:'icon-clinic',goal:-1,translation_key:'targets.anc.active_pregnancies_4p_visits.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return c(e,t)>3},date:'now',idType:'contact'},{id:'active-pregnancies-8+-contacts',type:'count',icon:'icon-follow-up',goal:-1,translation_key:'targets.anc.active_pregnancies_8p_contacts.title',subtitle_translation_key:'targets.all_time.subtitle',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){if(!s(e,t))return!1;return 1+(o(e,t).length||0)+(c(e,t)||0)>7},date:'now',idType:'contact'}]},945:(e,t,n)=>{var r=n(730);function i(e,t,n,r,i,o){var a=!!o;if(i.contact){var s='contact'===i.contact.type?i.contact.contact_type:i.contact.type,c=a?o.form:s;if(!(e.appliesToType&&e.appliesToType.indexOf(c)<0)&&(!e.appliesIf||e.appliesIf(i,o)))for(var p=a?o:i.contact,l=function(e,t,n){var r;return r='function'==typeof e.idType?e.idType(t,n):'report'===e.idType?n&&n._id:t.contact&&t.contact._id,Array.isArray(r)||(r=[r]),r}(e,i,o),d=!e.passesIf||!!e.passesIf(i,o),_=function(e,t,n,r){if('function'==typeof e.date)return e.date(n,r)||t.now().getTime();if(void 0===e.date||null===e.date||'now'===e.date)return t.now().getTime();if('reported'===e.date)return r?r.reported_date:n.contact.reported_date;throw new Error('Unrecognised value for target.date: '+e.date)}(e,n,i,o),u=e.groupBy&&e.groupBy(i,o),f=0;f{const r=n(190),{MAX_DAYS_IN_PREGNANCY:i,today:o,getNewestPregnancyTimestamp:a,getNewestDeliveryTimestamp:s,isAlive:c,isFormArraySubmittedInWindow:p,getDateISOLocal:l,getTimeForMidnight:d,isDeliveryForm:_,getMostRecentLMPDateForPregnancy:u,addDays:f,getRecentANCVisitWithEvent:g,isPregnancyTaskMuted:y,getField:m}=r,v=(e,t,n)=>({id:`pregnancy-home-visit-week${e}`,start:t,end:n,dueDate:function(t,n,r){const i=u(n,r);return f(i||r.reported_date,7*e)}});function h(e,t,n,r){if(t.reported_date=o},resolvedIf:h,actions:[{type:'report',form:'pregnancy_home_visit',label:'Pregnancy home visit'}],events:[...Array(21).keys()].map((e=>v(2*(e+1),6,7)))},{name:'anc.facility_reminder',icon:'icon-pregnancy',title:'task.anc.facility_reminder.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit'],appliesIf:function(e,t){return m(t,'t_pregnancy_follow_up_date')},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_facility_visit_reminder'],i,o)},actions:[{type:'report',form:'pregnancy_facility_visit_reminder',label:'Pregnancy facility visit reminder',modifyContent:function(e,t,n){e.source_visit_date=m(n,'t_pregnancy_follow_up_date')}}],events:[{id:'pregnancy-facility-visit-reminder',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_pregnancy_follow_up_date'))}}]},{name:'anc.pregnancy_danger_sign_followup',icon:'icon-pregnancy-danger',title:'task.anc.pregnancy_danger_sign_followup.title',appliesTo:'reports',appliesToType:['pregnancy','pregnancy_home_visit','pregnancy_danger_sign','pregnancy_danger_sign_follow_up'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pregnancy_danger_sign_follow_up'],i,o)},actions:[{type:'report',form:'pregnancy_danger_sign_follow_up'}],events:[{id:'pregnancy-danger-sign-follow-up',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'anc.delivery',icon:'icon-mother-child',title:'task.anc.delivery.title',appliesTo:'reports',appliesToType:['pregnancy'],appliesIf:function(e,t){const n=u(e,t);return n&&f(n,336)>=o&&c(e)},resolvedIf:function(e,t,n,r){if(g(e,t,'abortion')||g(e,t,'miscarriage'))return!0;if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date),o=f(r,n.end+1).getTime();return p(e.reports,['delivery'],i,o)},actions:[{type:'report',form:'delivery'}],events:[{id:'delivery-reminder',start:28,end:42,dueDate:function(e,t,n){return f(u(t,n),i)}}]},{name:'pnc.danger_sign_followup_mother',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_mother.title',appliesTo:'reports',appliesToType:['delivery','pnc_danger_sign_follow_up_mother'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_mother'],i,o)},actions:[{type:'report',form:'pnc_danger_sign_follow_up_mother',modifyContent:function(e,t,n){_(n)?e.delivery_uuid=n._id:e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-mother',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]},{name:'pnc.danger_sign_followup_baby.from_contact',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'contacts',appliesToType:['person'],appliesIf:function(e){return e.contact&&'yes'===e.contact.t_danger_signs_referral_follow_up&&c(e)},resolvedIf:function(e,t,n,r){const i=Math.max(f(r,-n.start).getTime(),e.contact.reported_date),o=f(r,n.end).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t){e.delivery_uuid=t.contact.created_by_doc}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t){return l(t.contact.t_danger_signs_referral_follow_up_date)}}]},{name:'pnc.danger_sign_followup_baby.from_report',icon:'icon-follow-up',title:'task.pnc.danger_sign_followup_baby.title',appliesTo:'reports',appliesToType:['pnc_danger_sign_follow_up_baby'],appliesIf:function(e,t){return'yes'===m(t,'t_danger_signs_referral_follow_up')&&c(e)},resolvedIf:function(e,t,n,r){if(y(e))return!0;const i=Math.max(f(r,-n.start).getTime(),t.reported_date+1),o=f(r,n.end+1).getTime();return p(e.reports,['pnc_danger_sign_follow_up_baby'],i,o)},priority:function(){return{level:10,label:'High'}},actions:[{type:'report',form:'pnc_danger_sign_follow_up_baby',modifyContent:function(e,t,n){e.delivery_uuid=m(n,'inputs.delivery_uuid')}}],events:[{id:'pnc-danger-sign-follow-up-baby',start:3,end:7,dueDate:function(e,t,n){return l(m(n,'t_danger_signs_referral_follow_up_date'))}}]}]}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}var r=n(991),i=n(931),o=n(85);n(945)(i,c,Utils,Target,emit),o(r,c,Utils,Task,emit),emit('_complete',{_id:!0})})();", "isDeclarative": true, "targets": { "enabled": true, From a6c4af3b23fdb0dc76dce73c8b33cd27014c55ec Mon Sep 17 00:00:00 2001 From: Tom Wier Date: Wed, 5 Aug 2026 13:29:10 +0300 Subject: [PATCH 3/3] fix(#10748): sonar --- shared-libs/lineage/src/hydration.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/shared-libs/lineage/src/hydration.js b/shared-libs/lineage/src/hydration.js index 275106d54e3..b17cdd8c06e 100644 --- a/shared-libs/lineage/src/hydration.js +++ b/shared-libs/lineage/src/hydration.js @@ -22,6 +22,13 @@ const extractParentIds = current => selfAndParents(current) .map(parent => parent._id) .filter(id => id); +// One entry per id, in the given order. Ids with no matching doc yield undefined so that positions in the +// lineage - and therefore ancestor depth - are preserved. +const orderDocsByIds = (ids, docs) => { + const docsById = new Map(docs.map(doc => [ doc._id, doc ])); + return ids.map(id => docsById.get(id)); +}; + const getContactById = (contacts, id) => id && contacts.find(contact => contact && contact._id === id); const getContactIds = (contacts) => { @@ -238,10 +245,8 @@ module.exports = function(Promise, DB) { if (!parentIds.length) { return [doc]; } - return fetchDocs(parentIds).then(function(ancestors) { - const ancestorsById = new Map(ancestors.map(ancestor => [ancestor._id, ancestor])); - return [doc, ...parentIds.map(parentId => ancestorsById.get(parentId))]; - }); + return fetchDocs(parentIds) + .then(ancestors => [ doc, ...orderDocsByIds(parentIds, ancestors) ]); }) .catch(function(err) { if (err.status === 404) {