avniproject / AKRSPI

Aga Khan Rural Support Program
GNU Affero General Public License v3.0
0 stars 0 forks source link

Aga Khan: Changes in Log book record Encounter form. #17

Closed kameshbhariya closed 1 month ago

kameshbhariya commented 2 months ago

Make the changes in UAT.


Analysis Link

Note

There is already a validation which is not working, try to debug why is it failing. And fix the same.

adamsanadi6 commented 2 months ago

Backup: 1. Reporting Year

'use strict';
({params, imports}) => {
    const encounter = params.entity;
    const moment = imports.moment;
    const formElement = params.formElement;
    const _ = imports.lodash;
    let visibility = true;
    let value = null;
    let answersToSkip = [];
    let validationErrors = [];

    function isYearValid(yearString) {
      const yearValidation = /^(19\d{2}|20\d{2})$/;
      const fourDigitValidation = /^\d{4}$/;
      if (!yearValidation.test(yearString)) {
          validationErrors.push("Enter a valid year");
          return false;
      }
      return true;
    }

    let reportingYear = encounter.getObservationValue("7cafd024-e7c8-4de0-b6fc-6511db23b4ca");
    reportingYear = moment(reportingYear, 'YYYY').year();

    const isDefined = new imports.rulesConfig.RuleCondition({
        encounter,
        formElement
    }).when.valueInEncounter("7cafd024-e7c8-4de0-b6fc-6511db23b4ca").defined.matches();

    if (isDefined && isYearValid(reportingYear) && (reportingYear > moment().year())) {
        validationErrors.push('Reporting year must be less than current year');
    }

    return new imports.rulesConfig.FormElementStatus(formElement.uuid, visibility, value, answersToSkip, validationErrors);
};
  1. Reporting Month

    'use strict';
    ({params, imports}) => {
    const encounter = params.entity;
    const moment = imports.moment;
    const formElement = params.formElement;
    const _ = imports.lodash;
    let visibility = true;
    let value = null;
    let answersToSkip = [];
    let validationErrors = [];
    
    const currentDate = moment();
    
    let reportingYear = encounter.getObservationValue("7cafd024-e7c8-4de0-b6fc-6511db23b4ca");
    reportingYear = moment(reportingYear, 'YYYY').year();
    
    let reportingMonth = encounter.getObservationReadableValue("634f0447-3f29-4ec2-95bd-e3ed59aad349");
    reportingMonth = moment(reportingMonth, 'MMM').month(); 
    
    const condition11 = new imports.rulesConfig.RuleCondition({encounter, formElement}).when.valueInEncounter("7cafd024-e7c8-4de0-b6fc-6511db23b4ca").defined.matches();
    
    const condition21 = new imports.rulesConfig.RuleCondition({encounter, formElement}).when.valueInEncounter("634f0447-3f29-4ec2-95bd-e3ed59aad349").defined.matches();
    
    if (condition11 && condition21) {
    if (reportingYear >  currentDate.year() || (reportingYear ==  currentDate.year() && reportingMonth >= currentDate.month())){
    validationErrors.push(`Reporting month must be before ${moment().month(currentDate.month()).format('MMMM')}`);
    }  
    }
    return new imports.rulesConfig.FormElementStatus(formElement.uuid, visibility, value, answersToSkip, validationErrors);
    };
Dinesh2019 commented 2 months ago

QA Reference video :

https://api.zenhub.com/attachedFiles/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBBOHlBQmc9PSIsImV4cCI6bnVsbCwicHVyIjoiYmxvYl9pZCJ9fQ==--b616131775c4c51dd896b171325689df6d0ba4b6/Screen%20Recording%202024-08-23%20at%2012.31.51%E2%80%AFPM.mov