Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Updated workflows, forms and condition cards #23

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"form:children_under_5_follow_up": {
"localhost/medic": "IDa16DfUYHzNj41sx4LkFg=="
"localhost/medic": "lKXjBSjwFp5FMleorEJ+Zg=="
},
"form:children_under_assessment": {
"localhost/medic": "zOVPS305MV6F+apuAocwLA=="
"localhost/medic": "Kj0YDovwDz0+4/HjVjSlLQ=="
},
"form:household_assessment": {
"localhost/medic": "3W6urE8MpIawdeoCIiFHEA=="
Expand All @@ -12,61 +12,61 @@
"localhost/medic": "w06a8nMtwvLDOw84+vm1Yw=="
},
"form:contact:area_community_health_supervisor:create": {
"localhost/medic": "in9SyvVEWe41h9dwsMK34w=="
"localhost/medic": "vPKGgd2scQqovIg1+jr5PA=="
},
"form:contact:area_community_health_supervisor:edit": {
"localhost/medic": "NA5eDQybVtvfozDOQ1N8eA=="
"localhost/medic": "jq9ZxcjFVJY6DWk7lmHoIw=="
},
"form:contact:area_health_facility:create": {
"localhost/medic": "JffaXrO0t+d7UE3I5C2Vjw=="
"localhost/medic": "rVmvlB+0oNRb/qG3843S9w=="
},
"form:contact:area_health_facility:edit": {
"localhost/medic": "FLa2Cco0aNQnuR2JAnOD8g=="
"localhost/medic": "xdZP3wrMFiNZJEs3aK+H1A=="
},
"form:contact:area_health_facility_nurse:create": {
"localhost/medic": "lWgl3dqPqRkjzd+/7ZXzrg=="
},
"form:contact:area_health_facility_nurse:edit": {
"localhost/medic": "aik3H7Cg8iMNlQJlQn+Pew=="
"localhost/medic": "sDESjHGng5kHRdo5shXvmw=="
},
"form:contact:area_supervisor_region:create": {
"localhost/medic": "a4sfXqz/xvBR1RloxO0C3A=="
"localhost/medic": "TKrEUopnGtahqCUnwACuUg=="
},
"form:contact:area_supervisor_region:edit": {
"localhost/medic": "M6uzism2uuTVCUKo7O9bVw=="
"localhost/medic": "dbyGJHA4xL8G3YzJO3nm/w=="
},
"form:contact:community_health_area:create": {
"localhost/medic": "oF0fuIvE8p0VJNirp8faLA=="
"localhost/medic": "ra5aaYTjehQX6TBXP9RZiw=="
},
"form:contact:community_health_area:edit": {
"localhost/medic": "W0nx79H4JK2TrI4jkM8/Xw=="
"localhost/medic": "uBI6UuqUOIOqD+/Png2v7Q=="
},
"form:contact:community_health_volunteer:create": {
"localhost/medic": "m2DJUPLt1ez1Dh3Tduf+ZQ=="
"localhost/medic": "baXz+iddHS169ye1wKLXOQ=="
},
"form:contact:community_health_volunteer:edit": {
"localhost/medic": "HUW517l2EE2te85Z+rww4g=="
},
"form:contact:household:create": {
"localhost/medic": "cIvpbnj6SFSlReFnf13fyA=="
"localhost/medic": "plUTOlZEvdgErBMHiOJDlw=="
},
"form:contact:household:edit": {
"localhost/medic": "nG6l1N/EQzN3fRBYuBM1nQ=="
},
"form:contact:household_member:create": {
"localhost/medic": "UGG0kuUSE+8axtnLL8MqMQ=="
"localhost/medic": "Vk+Q+I31rLdS+dY7yjmO4A=="
},
"form:contact:household_member:edit": {
"localhost/medic": "HEsMdVWKlhsZpFGFZ7h+5A=="
"localhost/medic": "hf53chw5XAcEUSiyFWRMtQ=="
},
"form:death_report": {
"localhost/medic": "DT1oGLL2rm/ZmpkEU3bk9g=="
"localhost/medic": "nsD8cecXbYglp9rHr4bXoA=="
},
"form:household_member_assessment": {
"localhost/medic": "R7TCYKVonOiSQ7TXDzdceQ=="
"localhost/medic": "klwT4IUMwnh4fsFHF0BTgg=="
},
"form:household_member_follow_up": {
"localhost/medic": "pqFR/8qE3ZyeZFHKMngpNg=="
"localhost/medic": "enHJrQX3rGlBYkbtRsZSIw=="
},
"form:mute_household": {
"localhost/medic": "R+dqCh9M8S/VQH1HmHsf9w=="
Expand All @@ -75,12 +75,12 @@
"localhost/medic": "nGlcgxLlKUlE08i52FpXNA=="
},
"form:mute_household_member": {
"localhost/medic": "nEjxunO4pNcXkLnEEEHT3Q=="
"localhost/medic": "WZuKiSHjmUE8XPGl2+wZNw=="
},
"form:pregnancy_registration": {
"localhost/medic": "Nhq0vVRDfLHYJo7N5M6DiQ=="
"localhost/medic": "/Asrp8YDH0oizR/M3I8mIQ=="
},
"form:unmute_household": {
"localhost/medic": "rxcgoKfM1oPNflU25+JKTQ=="
"localhost/medic": "VGeVxzYTHtjrsYdnsHZzjw=="
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"permissions": {
"can_access_gateway_api": ["gateway"],
"can_create_chw": ["program_officer", "chw_supervisor", "crfo"],
"can_bulk_delete_reports": ["program_officer", "chw_supervisor", "chw"],
"can_configure": ["program_officer", "crfo"],
"can_create_people": ["program_officer", "chw_supervisor", "chw"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { FORMS } = require('./shared-extras');


const MAX_DAYS_IN_PREGNANCY = 42 * 7;

const isPregnancyForm = report => {
return report && [FORMS.PREGNANCY_REGISTRATION].includes(report.form);
};

const isActivePregnancy = (thisContact, allReports, report) => {
if (thisContact.type !== 'person' || !isPregnancyForm(report)) { return false; }
};

const isPregnant = (allReports) => {
return allReports.some(report => isActivePregnancy(report));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also have to check that:

  • there's no subsequent delivery
  • the pregnancy age does not exceed 40-42 weeks
  • the pregnancy has not been terminated

A potential example might look like this

};


module.exports = {

MAX_DAYS_IN_PREGNANCY,
isPregnant,
isActivePregnancy,
isPregnancyForm
};
Original file line number Diff line number Diff line change
@@ -1,14 +1,52 @@
const { CONTACT_TYPES, FORMS } = require('./shared-extras');
const {DateTime} = require('luxon');
const { getField } = require('cht-nootils')();
const { getField, getMostRecentReport,isFirstReportNewer } = require('cht-nootils')();
const { getMostRecentReportForm, ageInMonths, isPregnancyBeforeDelivery, isContactStillPregnant } = require('./nools-extras');

const thisContact = contact;
const thisLineage = lineage;
const allReports = reports;
const householdAssessmentReport = getMostRecentReportForm(reports, [FORMS.HOUSEHOLD_ASSESSMENT]);
const householdAssessmentFollowUpReport = getMostRecentReportForm(reports, [FORMS.HOUSEHOLD_ASSESSMENT_FOLLOWUP]);
const under5AssessmentReport = getMostRecentReportForm(reports, [FORMS.CHILD_ASSESSMENT]);
const memberAssessmentReport = getMostRecentReportForm(reports, [FORMS.HOUSEHOLD_MEMBER_ASSESSMENT]);

const fields = [
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, translate: true, label: 'contact.name', value: thisContact.name, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, translate: true, label: 'contact.name', value: thisContact.contact && thisContact.contact.name, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, translate: true, label: 'contact.phone', value: thisContact.contact && thisContact.contact.primary_phone_number, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, label: 'contact.parent', value: thisLineage, filter: 'lineage' }
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, translate: true, label: 'Household Head', value: thisContact.contact && thisContact.contact.name, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, label: 'contact.sex', value: thisContact.contact && thisContact.contact.sex, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, label:'contact.age', value: thisContact.contact && thisContact.contact.date_of_birth, width: 4, filter: 'age'},
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, translate: true, label: 'contact.phone', value: thisContact.contact && thisContact.contact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD, label: 'contact.parent', value: thisLineage, filter: 'lineage' },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER, label:'patient_id', value: thisContact.patient_id, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER, label:'contact.age', value: thisContact.date_of_birth, width: 4, filter: 'age'},
{ appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER, label: 'contact.sex', value: thisContact.sex, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER, label: 'contact.phone', value: thisContact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER, label: 'Relationship to Household Head', value: thisContact.relationship_to_primary_caregiver, width: 8 },
{ appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER, label: 'contact.parent', value: thisLineage, filter: 'lineage' },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY, translate: true, label: 'contact.name', value: thisContact.contact && thisContact.contact.name, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY, translate: true, label: 'contact.phone', value: thisContact.contact && thisContact.contact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY, translate: true, label: 'Alternative Phone', value: thisContact.contact && thisContact.contact.phone_alternate, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY, label: 'Notes', value: thisContact.contact && thisContact.notes, width: 12 },
{ appliesToType: CONTACT_TYPES.AREA_SUPERVISOR_REGION, label: 'contact.name', value: thisContact.contact && thisContact.contact.name, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_SUPERVISOR_REGION, label: 'contact.phone', value: thisContact.contact && thisContact.contact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_SUPERVISOR_REGION, label: 'Alternative Phone', value: thisContact.contact && thisContact.contact.phone_alternate, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_SUPERVISOR_REGION, label: 'contact.parent', value: thisLineage, filter: 'lineage' },
{ appliesToType: CONTACT_TYPES.AREA_SUPERVISOR_REGION, label: 'Notes', value: thisContact.contact && thisContact.contact.notes, width: 12 },
{ appliesToType: CONTACT_TYPES.AREA_COMMUNITY_HEALTH_SUPERVISOR, label: 'contact.phone', value: thisContact.phone, width: 4 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a name needed for the 'area supervisor region'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there was consistency in the way place / person contacts were rendered, this code block could be significantly reduced.

const fields = [];


if (person_type) {
   fields.push(...)
   fields.push(..)
} else {
 fields.push(...)
 fields.push(...)
}

{ appliesToType: CONTACT_TYPES.AREA_COMMUNITY_HEALTH_SUPERVISOR, label: 'Alternative Phone', value: thisContact.phone_alternate, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_COMMUNITY_HEALTH_SUPERVISOR, label: 'contact.parent', value: thisLineage, filter: 'lineage' },
{ appliesToType: CONTACT_TYPES.AREA_COMMUNITY_HEALTH_SUPERVISOR, label: 'Notes', value: thisContact.notes, width: 12 },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY_NURSE, label: 'contact.phone', value: thisContact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY_NURSE, label: 'Alternative Phone', value: thisContact.phone_alternate, width: 4 },
{ appliesToType: CONTACT_TYPES.AREA_HEALTH_FACILITY_NURSE, label: 'contact.parent', value: thisLineage, filter: 'lineage' },
{ appliesToType: CONTACT_TYPES.COMMUNITY_HEALTH_AREA, translate: true, label: 'Primary Contact', value: thisContact.contact && thisContact.contact.name, width: 4 },
{ appliesToType: CONTACT_TYPES.COMMUNITY_HEALTH_AREA, label: 'contact.phone', value: thisContact.contact && thisContact.contact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.COMMUNITY_HEALTH_AREA, label: 'contact.parent', value: thisLineage, filter: 'lineage' },
{ appliesToType: CONTACT_TYPES.COMMUNITY_HEALTH_VOLUNTEER, label: 'contact.phone', value: thisContact.phone, width: 4 },
{ appliesToType: CONTACT_TYPES.COMMUNITY_HEALTH_VOLUNTEER, label: 'contact.parent', value: thisLineage, filter: 'lineage' }

];

const cards = [
Expand All @@ -18,43 +56,153 @@ const cards = [
icon: 'household-summary',
appliesToType: 'report',
appliesIf: function(report) {
return report.form === FORMS.HOUSEHOLD_ASSESSMENT;
return report.form === FORMS.HOUSEHOLD_ASSESSMENT && report.reported_date === householdAssessmentReport.reported_date;
},
fields: [
{
label: 'contact.profile.malaria_prone',
icon: 'household-summary',
value: function(report) {
return getField(report, 'malaria_prone') ? 'Yes' : 'No';
value: function() {
if(householdAssessmentFollowUpReport){
return getField(householdAssessmentFollowUpReport, 'malaria_prone') ? 'Yes' : 'No';
}
return getField(householdAssessmentReport, 'malaria_prone') ? 'Yes' : 'No';
}
},
},
{
label: 'contact.profile.next_visit',
translate: true,
icon: 'next-visit',
value: function(report) {
const ammendmentDate = getField(report, 'household_assessment.amendment_date');
value: function() {
const ammendmentDate = getField(householdAssessmentReport, 'household_assessment.amendment_date');
return DateTime.fromISO(ammendmentDate).isValid ? ammendmentDate : null;
},
filter: 'simpleDate',
},
],
},
{
label: 'contact.profile.household_prevention',
appliesToType: 'report',
appliesIf: function(report) {
return report.form === FORMS.HOUSEHOLD_ASSESSMENT;
label: 'contact.profile.child_health',
appliesToType: [CONTACT_TYPES.HOUSEHOLD_MEMBER],
appliesIf: function() {
return ageInMonths(thisContact.date_of_birth) < 60 && !!under5AssessmentReport;
},
fields: [
{
label: 'contact.profile.household_prevention',
icon: 'malaria-prone',
translate: true,
value: 'malaria.prevention.message'
},
label: 'contact.profile.sleeps_under_llin',
icon: 'sleeps_under_llin',
value: function() {
return getField(under5AssessmentReport, 'children_under_assessment.nets_treated');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getField isnt null-safe. Consider adding some defensive checks as outlined earlier

},
},
{
label: 'contact.profile.suspected_malaria',
icon: function() {
return getField(under5AssessmentReport, 'children_under_assessment.suspected_of_malaria') === 'Yes' ? 'danger' : 'suspected_malaria';
},
value: function() {
return getField(under5AssessmentReport, 'children_under_assessment.suspected_of_malaria');
},
}
],
}
},
{
label: 'contact.profile.assessment_history',
appliesToType: [CONTACT_TYPES.HOUSEHOLD_MEMBER],
appliesIf: function() {
return ageInMonths(thisContact.date_of_birth) > 60 && !!memberAssessmentReport;
},
fields: [
{
label: 'contact.profile.last_assessment_date',
icon: 'date',
value: function() {
const assessDate = getField(memberAssessmentReport, 'referral_follow_up_date');
return assessDate !== null ? assessDate : 'N/A';
},
filter: 'simpleDate',
},
{
label: 'contact.profile.suspected_malaria',
icon: 'suspected_malaria',
value: function() {
return getField(memberAssessmentReport, 'group_household_member_assessment.suspected_of_malaria');
}
},
{
label: 'contact.profile.symptoms_experienced',
icon: 'symptoms',
value: function() {
return getField(memberAssessmentReport, 'group_household_member_assessment.symptoms');
}
}
],
},
{
label: 'contact.profile.given_treatment',
appliesToType: [CONTACT_TYPES.HOUSEHOLD_MEMBER],
appliesIf: function() {
return ageInMonths(thisContact.date_of_birth) > 60 && getMostRecentReportForm(reports, [FORMS.MEMBER_FOLLOW_UP]);
},
fields: [
{
label: 'contact.profile.patient_given_treatment',
icon: 'treatment',
value: function() {
const memberFollowUpReport = getMostRecentReportForm(reports, [FORMS.MEMBER_FOLLOW_UP]);
return memberFollowUpReport ? getField(memberFollowUpReport, 'group_household_member_follow_up.given_treatment') : 'N/A';
}
}
],
},
{
label: 'contact.profile.pregnancy.active',
appliesToType: CONTACT_TYPES.HOUSEHOLD_MEMBER,
appliesIf: function() {
const report = getMostRecentReport(allReports, FORMS.PREGNANCY_REGISTRATION);
const malariaReport = getMostRecentReport(allReports, FORMS.MALARIA_ASSESSMENT_FOR_PREGNANT_MOTHERS);
/* eslint-disable no-console */
console.log(report);
console.log(malariaReport);
console.log(report && malariaReport && thisContact.age_years > 12 && thisContact.age_years < 50 && thisContact.sex === 'female');

if(report !== null &&
report.fields.group_pregnancy_registration_form.is_pregnancy_confirmed==='yes' && thisContact.age_years > 12 && thisContact.age_years < 50 && thisContact.sex === 'female'){
/* eslint-disable no-console */
console.log(thisContact);
console.log(thisContact.age_years > 12 && thisContact.age_years < 50 && thisContact.sex === 'female');
if(malariaReport && report && isFirstReportNewer(malariaReport, report)) {
return isContactStillPregnant(allReports);
}
return isPregnancyBeforeDelivery(report);
}
},
fields: function () {
const report = getMostRecentReport(allReports, FORMS.PREGNANCY_REGISTRATION);
//const malariaReport = getMostRecentReport(allReports, FORMS.MALARIA_ASSESSMENT_FOR_PREGNANT_MOTHERS);

const fields = [];
const dateTime = DateTime.fromMillis(report.reported_date);

const targetDate = new Date(report.fields.group_pregnancy_registration_form.estimated_delivery_date);
const today = new Date();

const timeDifference = targetDate - today;
const weeksDifference = timeDifference / (1000 * 60 * 60 * 24 * 7);
const roundedWeeksDifference = Math.round(weeksDifference);

fields.push(
{ label: 'Approximate Weeks before delivery', value: roundedWeeksDifference },
{label: 'Pregnancy Registration Date', value : dateTime.toFormat('yyyy-MM-dd HH:mm:ss')},
{label: 'Number of ANC Visits', value : report.fields.group_pregnancy_registration_form.no_of_antenatal_visits}
);

return fields;
},
modifyContext: function (ctx){
ctx.is_active_pregnancy = true;
}
},
];

module.exports = {
Expand Down
Binary file not shown.
Loading