Skip to content

Commit

Permalink
#426 | Ability to pass value from the rule for coded datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
vindeolal committed Feb 1, 2021
1 parent 77211b2 commit b306d62
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/openchs-android/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"lodash": "4.17.11",
"moment": "2.19.3",
"native-base": "2.12.1",
"openchs-models": "0.2.60",
"openchs-models": "0.2.61",
"prop-types": "15.7.2",
"react": "16.8.3",
"react-native": "0.59.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ObservationsHolderActions {
const formElementStatuses = ObservationsHolderActions._getFormElementStatuses(newState, context);
const ruleValidationErrors = ObservationsHolderActions.getRuleValidationErrors(formElementStatuses);
const hiddenFormElementStatus = _.filter(formElementStatuses, (form) => form.visibility === false);
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
newState.removeHiddenFormValidationResults(hiddenFormElementStatus);
const validationResult = action.formElement.validate(action.value);
newState.handleValidationResults(ObservationsHolderActions.addPreviousValidationErrors(ruleValidationErrors, validationResult, newState.validationResults), context);
Expand Down Expand Up @@ -57,7 +57,7 @@ class ObservationsHolderActions {
const formElementStatuses = ObservationsHolderActions._getFormElementStatuses(newState, context);
const ruleValidationErrors = ObservationsHolderActions.getRuleValidationErrors(formElementStatuses);
const hiddenFormElementStatus = _.filter(formElementStatuses, (form) => form.visibility === false);
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
const validationResult = action.formElement.validate(_.isNil(observation) ? null : observation.getValueWrapper());
newState.handleValidationResults(ObservationsHolderActions.addPreviousValidationErrors(ruleValidationErrors, validationResult, newState.validationResults), context);
newState.removeHiddenFormValidationResults(hiddenFormElementStatus);
Expand All @@ -80,7 +80,7 @@ class ObservationsHolderActions {
const ruleValidationErrors = ObservationsHolderActions.getRuleValidationErrors(formElementStatuses);
const hiddenFormElementStatus = _.filter(formElementStatuses, (form) => form.visibility === false);
const validationResult = action.formElement.validate(_.isNil(observation) ? null : observation.getValueWrapper());
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
newState.handleValidationResults(ObservationsHolderActions.addPreviousValidationErrors(ruleValidationErrors, validationResult, newState.validationResults), context);
newState.removeHiddenFormValidationResults(hiddenFormElementStatus);
return newState;
Expand All @@ -100,7 +100,7 @@ class ObservationsHolderActions {
const formElementStatuses = ObservationsHolderActions._getFormElementStatuses(newState, context);
const ruleValidationErrors = ObservationsHolderActions.getRuleValidationErrors(formElementStatuses);
const hiddenFormElementStatus = _.filter(formElementStatuses, (form) => form.visibility === false);
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
const validationResult = action.formElement.validate(dateValue);
newState.handleValidationResults(ObservationsHolderActions.addPreviousValidationErrors(ruleValidationErrors, validationResult, newState.validationResults), context);
newState.removeHiddenFormValidationResults(hiddenFormElementStatus);
Expand All @@ -115,7 +115,7 @@ class ObservationsHolderActions {
const formElementStatuses = ObservationsHolderActions._getFormElementStatuses(newState, context);
const ruleValidationErrors = ObservationsHolderActions.getRuleValidationErrors(formElementStatuses);
const hiddenFormElementStatus = _.filter(formElementStatuses, (form) => form.visibility === false);
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
const validationResult = action.formElement.validate(_.isNil(observation) ? null : observation.getValueWrapper());
newState.handleValidationResults(ObservationsHolderActions.addPreviousValidationErrors(ruleValidationErrors, validationResult, newState.validationResults), context);
newState.removeHiddenFormValidationResults(hiddenFormElementStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ChecklistItemActions {
newState.checklistItem.completionDate = action.value;
const formElementStatuses = ObservationsHolderActions.updateFormElements(newState.formElementGroup, newState, context);
newState.observationsHolder.removeNonApplicableObs(newState.formElementGroup.getFormElements(), newState.filteredFormElements);
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
return newState;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ProgramEncounterActions {
newState.handleValidationResults(newState.programEncounter.validate(), context);
const formElementStatuses = ObservationsHolderActions.updateFormElements(newState.formElementGroup, newState, context);
newState.observationsHolder.removeNonApplicableObs(newState.formElementGroup.getFormElements(), newState.filteredFormElements);
newState.observationsHolder.updatePrimitiveObs(newState.filteredFormElements, formElementStatuses);
newState.observationsHolder.updatePrimitiveCodedObs(newState.filteredFormElements, formElementStatuses);
return newState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ProgramEnrolmentActions {
action.workLists
);
programEnrolmentState = programEnrolmentState.clone();
programEnrolmentState.observationsHolder.updatePrimitiveObs(filteredElements, formElementStatuses);
programEnrolmentState.observationsHolder.updatePrimitiveCodedObs(filteredElements, formElementStatuses);
return programEnrolmentState;
} else {
return state.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class AbstractDataEntryState {
this.moveNext();
const formElementStatuses = ObservationHolderActions.updateFormElements(this.formElementGroup, this, context);
this.observationsHolder.removeNonApplicableObs(this.formElementGroup.getFormElements(), this.filteredFormElements);
this.observationsHolder.updatePrimitiveObs(this.filteredFormElements, formElementStatuses);
this.observationsHolder.updatePrimitiveCodedObs(this.filteredFormElements, formElementStatuses);
if (this.hasNoFormElements()) {
General.logDebug("No form elements here. Moving to next screen");
return this.handleNext(action, context);
Expand Down
2 changes: 1 addition & 1 deletion packages/openchs-android/src/state/EncounterActionState.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class EncounterActionState extends AbstractDataEntryState {
static createOnLoadState(encounter, form, isNewEntity, formElementGroup, filteredFormElements, formElementStatuses, workLists, messageDisplayed) {
let indexOfGroup = _.findIndex(form.getFormElementGroups(), (feg) => feg.uuid === formElementGroup.uuid) + 1;
let state = new EncounterActionState([], formElementGroup, new Wizard(form.numberOfPages, indexOfGroup, indexOfGroup), isNewEntity, encounter, filteredFormElements, workLists, messageDisplayed);
state.observationsHolder.updatePrimitiveObs(filteredFormElements, formElementStatuses);
state.observationsHolder.updatePrimitiveCodedObs(filteredFormElements, formElementStatuses);
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProgramEncounterState extends AbstractDataEntryState {
static createOnLoad(programEncounter, form, isNewEntity, formElementGroup, filteredFormElements, formElementStatuses, workLists, messageDisplayed) {
let indexOfGroup = _.findIndex(form.getFormElementGroups(), (feg) => feg.uuid === formElementGroup.uuid) + 1;
let state = new ProgramEncounterState(formElementGroup, new Wizard(form.numberOfPages, indexOfGroup, indexOfGroup), isNewEntity, programEncounter, filteredFormElements, workLists, messageDisplayed);
state.observationsHolder.updatePrimitiveObs(filteredFormElements, formElementStatuses);
state.observationsHolder.updatePrimitiveCodedObs(filteredFormElements, formElementStatuses);
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SubjectRegistrationState extends AbstractDataEntryState {
);
state.form = form;
state.minLevelTypeUUIDs = minLevelTypeUUIDs;
state.observationsHolder.updatePrimitiveObs(filteredFormElements, formElementStatuses);
state.observationsHolder.updatePrimitiveCodedObs(filteredFormElements, formElementStatuses);
return state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class SelectFormElement extends AbstractFormElement {
}

render() {
const disabled = this.props.element.editable === false;
const valueLabelPairs = this.props.element.getAnswers()
.map((answer) => new RadioLabelValue(answer.concept.name, answer.concept.uuid, answer.abnormal));
return (
Expand All @@ -38,10 +39,12 @@ class SelectFormElement extends AbstractFormElement {
labelKey={this.props.element.name}
mandatory={this.props.element.mandatory}
validationError={this.props.validationResult}
labelValuePairs={valueLabelPairs}/>
labelValuePairs={valueLabelPairs}
disabled={disabled}
/>
</View>);
}

}

export default SelectFormElement;
export default SelectFormElement;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import General from "../../utility/General";
class PresetOptionItem extends AbstractComponent {

static defaultProps = {
chunked: false
chunked: false,
disabled: false,
};

static propTypes = {
Expand All @@ -39,10 +40,10 @@ class PresetOptionItem extends AbstractComponent {

getSelectComponent() {
if (this.props.multiSelect)
return (<CheckBox checked={this.props.checked}
return (<CheckBox disabled={this.props.disabled} checked={this.props.checked}
onPress={() => this.props.onPress()}/>);
else
return (<Radio selected={this.props.checked}
return (<Radio disabled={this.props.disabled} selected={this.props.checked}
onPress={() => this.props.onPress()} color={Colors.AccentColor}/>);
}

Expand Down Expand Up @@ -73,7 +74,7 @@ class PresetOptionItem extends AbstractComponent {
};
const ToRender = this.props.chunked ? chunked : single;
return (
<TouchableOpacity onPress={() => this.props.onPress()} style={ToRender.container}>
<TouchableOpacity onPress={() => this.props.onPress()} style={ToRender.container} disabled={this.props.disabled}>
<View style={{flexDirection: 'row', alignItems: 'center', justifyContent: 'flex-start', alignSelf: 'flex-start'}}>
<View>
{this.getSelectComponent()}
Expand Down
8 changes: 6 additions & 2 deletions packages/openchs-android/src/views/primitives/RadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class RadioGroup extends AbstractComponent {
borderStyle: {},
inPairs: false,
multiSelect: false,
disabled: false,
};

static propTypes = {
Expand Down Expand Up @@ -60,7 +61,8 @@ class RadioGroup extends AbstractComponent {
style={{
paddingVertical: Distances.VerticalSpacingBetweenOptionItems,
paddingRight: Distances.HorizontalSpacingBetweenOptionItems
}}/>
}}
disabled={this.props.disabled}/>
)}
</View>);
}
Expand All @@ -76,7 +78,9 @@ class RadioGroup extends AbstractComponent {
style={{
paddingVertical: Distances.VerticalSpacingBetweenOptionItems,
paddingRight: Distances.HorizontalSpacingBetweenOptionItems
}}/>)
}}
disabled={this.props.disabled}
/>)
}

renderSingleValue() {
Expand Down

0 comments on commit b306d62

Please sign in to comment.