avniproject / AKRSPI

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

Aga Khan: Restrict forms from being filled twice in the same month. #19

Open kameshbhariya opened 3 weeks ago

kameshbhariya commented 3 weeks ago

Make the changes in UAT.

vedfordev commented 2 weeks ago

Dev Note:

I've added below rule in mentioned encounter.

Validation Rule:

'use strict';
({params, imports}) => {
  const encounter = params.entity;
  const moment = imports.moment;
  const validationResults = [];

     const scheduledOrCompletedEncountersOfType = (encounterType, encounterDateTime) => {
        const month = moment(encounterDateTime).month();
        const year = moment(encounterDateTime).year();     

        const data = encounter.individual.encounters.filter((enc) =>
            enc.encounterType.name === encounterType &&
            enc.voided == false &&
            enc.uuid != encounter.uuid && 
            enc.cancelDateTime == null &&
            moment(enc.encounterDateTime).year() == year &&
            moment(enc.encounterDateTime).month() == month
        );
        return data;
    }

   const condition11 = scheduledOrCompletedEncountersOfType(encounter.encounterType.name,encounter.encounterDateTime).length != 0; 

  if(condition11 ){
    validationResults.push(imports.common.createValidationError("same form cannot be filled twice in the same month"));  
}

  return validationResults;
};
vedfordev commented 2 weeks ago

@nupoorkhandelwal moving card to review lane.