Skip to content

Commit

Permalink
avniproject/avni-models#48 | Minor Code refactoring to create and use…
Browse files Browse the repository at this point in the history
… getAffiliatedGroups()
  • Loading branch information
himeshr committed Aug 11, 2023
1 parent 3089d58 commit b586abe
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
14 changes: 7 additions & 7 deletions packages/openchs-android/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ class IndividualRegistrationState extends AbstractDataEntryState {
getEntityContext() {
return {
group: this.group,
affiliatedGroups: this.groupAffiliation ?
_.map(this.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : []
affiliatedGroups: this.getAffiliatedGroups()
}
}

getAffiliatedGroups() {
return this.groupAffiliation ?
_.map(this.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : [];
}

static createLoadState(form, genders, individual, workLists, minLevelTypeUUIDs, saveDrafts, groupAffiliationState, isNewEntity, group) {
const wizard = new Wizard(_.isNil(form) ? 1 : form.numberOfPages + 1, 2);
const individualRegistrationState = new IndividualRegistrationState([],
Expand Down
10 changes: 7 additions & 3 deletions packages/openchs-android/src/state/ProgramEnrolmentState.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ class ProgramEnrolmentState extends AbstractDataEntryState {

getEntityContext() {
return {
affiliatedGroups: this.groupAffiliation ?
_.map(this.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : []
};
affiliatedGroups: this.getAffiliatedGroups()
}
}

getAffiliatedGroups() {
return this.groupAffiliation ?
_.map(this.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : [];
}

get staticFormElementIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@ class SubjectRegistrationState extends AbstractDataEntryState {
getEntityContext() {
return {
group: this.group,
affiliatedGroups: this.groupAffiliation ?
_.map(this.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : []
affiliatedGroups: this.getAffiliatedGroups()
}
}

getAffiliatedGroups() {
return this.groupAffiliation ?
_.map(this.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : [];
}

static createOnLoad(subject, form, isNewEntity, formElementGroup, filteredFormElements, formElementStatuses, workLists, minLevelTypeUUIDs, isSaveDraftOn, groupAffiliationState, context, group) {
let indexOfGroup = _.findIndex(form.getFormElementGroups(), (feg) => feg.uuid === formElementGroup.uuid) + 1;
const timerState = formElementGroup.timed && isNewEntity ? new TimerState(formElementGroup.startTime, formElementGroup.stayTime) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class Mixin {
});
const registrationTitle = view.I18n.t(view.registrationType) + view.I18n.t('registration');
const headerMessage = `${registrationTitle} - ${view.I18n.t('summaryAndRecommendations')}`;
const affiliatedGroups = state.groupAffiliation ?
_.map(state.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : [];
CHSNavigator.navigateToSystemsRecommendationView(view, decisions, ruleValidationErrors, state.individual, state.individual.observations, Actions.SAVE, onSaveCallback, headerMessage, null, nextScheduledVisits, state.form, state.workListState,null, state.saveDrafts, popVerificationVew, state.individual.isRejectedEntity(), state.individual.latestEntityApprovalStatus, undefined, affiliatedGroups);
CHSNavigator.navigateToSystemsRecommendationView(view, decisions, ruleValidationErrors, state.individual,
state.individual.observations, Actions.SAVE, onSaveCallback, headerMessage, null,
nextScheduledVisits, state.form, state.workListState,null, state.saveDrafts,
popVerificationVew, state.individual.isRejectedEntity(), state.individual.latestEntityApprovalStatus,
undefined, state.getAffiliatedGroups());
},
movedNext: (state) => {
if (state.wizard.isFirstFormPage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ class SubjectRegisterView extends AbstractComponent {
};
const registrationTitle = this.I18n.t(this.registrationType) + this.I18n.t('registration');
const headerMessage = `${registrationTitle} - ${this.I18n.t('summaryAndRecommendations')}`;
const affiliatedGroups = state.groupAffiliation ?
_.map(state.groupAffiliation.groupSubjectObservations, ({groupSubject}) => groupSubject) : [];
CHSNavigator.navigateToSystemsRecommendationView(this, decisions, ruleValidationErrors, state.subject, observations, Actions.SAVE, onSaveCallback, headerMessage,
null, nextScheduledVisits, state.form, state.workListState, null, this.state.saveDrafts, popVerificationVew, state.subject.isRejectedEntity(), this.state.subject.latestEntityApprovalStatus, undefined, affiliatedGroups);
CHSNavigator.navigateToSystemsRecommendationView(this, decisions, ruleValidationErrors, state.subject,
observations, Actions.SAVE, onSaveCallback, headerMessage,
null, nextScheduledVisits, state.form, state.workListState, null,
this.state.saveDrafts, popVerificationVew, state.subject.isRejectedEntity(),
this.state.subject.latestEntityApprovalStatus, undefined, state.getAffiliatedGroups());
},
popVerificationVewFunc: () => TypedTransition.from(this).popToBookmark(),
phoneNumberObservation,
Expand Down

0 comments on commit b586abe

Please sign in to comment.