Skip to content

Commit

Permalink
Revert "Implement search by location form in the encounter tab (#68)"
Browse files Browse the repository at this point in the history
This reverts commit 33c3877.
  • Loading branch information
dkayiwa committed May 10, 2017
1 parent 33c3877 commit e02ff8b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 110 deletions.
111 changes: 1 addition & 110 deletions app/js/components/tabs/tabcomponents/encounterComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ class EncounterComponent extends Component {
currentPage: 1,
toDisplay: [],
totalPage: 0,
perPage: 10,
location: '',
method: 'ANY'
perPage: 10
};
this.searchByEncounter = this.searchByEncounter.bind(this);
this.getFormValues = this.getFormValues.bind(this);
this.handleSelectOption = this.handleSelectOption.bind(this);
this.searchByLocation = this.searchByLocation.bind(this);
}

componentWillMount(){
Expand Down Expand Up @@ -150,84 +146,6 @@ class EncounterComponent extends Component {
return label;
}

/**
* Function to generate a location search description based on the search values
*/
getLocationSearchDescription() {
// find the location name since we only have it's uuid
const selectedLocation = this.state.locations.find((item) => {
return item.id === this.state.location;
});
let searchDescription = `Patients in ${selectedLocation.value}`;
switch (this.state.method) {
case 'FIRST':
searchDescription += ' (by method EARLIEST_ENCOUNTER).';
break;
case 'LAST':
searchDescription += ' (by method LATEST_ENCOUNTER).';
break;
default :
searchDescription += ' (by method ANY_ENCOUNTER).';
break;
}
return searchDescription;
}

/**
* Method to handle search by location submit events and search for patients
* from the back end using location and method selected
* @param {Object} event - Object containing data about the triggered event
* @return {undefined}
*/
searchByLocation(event) {
event.preventDefault();
const searchParameters = {
encounterSearchAdvanced : [
{ name: 'locationList', value: [this.state.location] },
{ name: 'timeQualifier', value: this.state.method },
]
};
this.props.search(searchParameters).then(results => {
const allEncounterTypes = results.rows || [];
this.props.addToHistory(this.getLocationSearchDescription(), allEncounterTypes, results.query);
// reset fields to default
this.setState({ location: '', method: 'ANY' });
});
}

/**
* Method to handle option selection in select fields. It sets the selected option
* value to the property in state (referred to by the option id)
* @param {Object} event - Object contatining data about the triggered event
* @return {undefined}
*/
handleSelectOption(event) {
event.preventDefault();
this.setState({ [event.target.id]: event.target.value });
}

/**
* Method to get an array of <option> element items from locations in the state
* @return {Array} - An array containing option elements of availaible methods
*/
getLocationOptions() {
return this.state.locations.map((item) => {
return <option value={item.id} key={shortId.generate()}>{item.value}</option>;
});
}

/**
* Method to get an array of <option> element items from methods in the state
* @return {Array} - An array containing option elements of availaible methods
*/
getMethodOptions() {
return [
<option key={shortId.generate()} value={'ANY'}>Any Encounter</option>,
<option key={shortId.generate()} value={'LAST'}>Most Recent Encounter</option>,
<option key={shortId.generate()} value={'FIRST'}>Earliest Encounter</option>
];
}

render(){
return (
<div className="encounter-component">
Expand Down Expand Up @@ -302,33 +220,6 @@ class EncounterComponent extends Component {
</div>
</form>
<hr/>
<h3>Search By Location</h3>
<form className="form-horizontal" onSubmit={this.searchByLocation}>
<div className="form-group">
<label htmlFor="gender" className="col-sm-2 control-label">Patients belonging to?:</label>
<div className="col-sm-6">
<select className="form-control" id="location" onChange={this.handleSelectOption} value={this.state.location}>
<option value="">--Select Location--</option>
{this.getLocationOptions()}
</select>
</div>
</div>

<div className="form-group">
<label htmlFor="gender" className="col-sm-2 control-label">According to Method:</label>
<div className="col-sm-6">
<select className="form-control" id="method" onChange={this.handleSelectOption} value={this.state.method}>
{this.getMethodOptions()}
</select>
</div>
</div>

<div className="form-group">
<div className="col-sm-offset-2 col-sm-6">
<button type="submit" className="btn btn-success">Search</button>
</div>
</div>
</form>
</div>
</div>
);
Expand Down
46 changes: 46 additions & 0 deletions app/js/components/tabs/tabcomponents/programmeComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class ProgrammeComponent extends Component {
programs: [],
workflows: [],
states: [],
locations: [],
methods: [],
minAge: '',
maxAge: '',
enrolledStartDate: '',
Expand All @@ -32,6 +34,11 @@ class ProgrammeComponent extends Component {
programs: data.results
});
});
this.props.fetchData('/location').then(location => {
this.setState({
locations: location.results
});
});
}

/**
Expand Down Expand Up @@ -240,6 +247,16 @@ class ProgrammeComponent extends Component {
// States will be loaded from this.state.states when populated from backend
let states = "<option> </option>";

let locations = this.state.locations.map((location) => {
return (
<option key={location.uuid} value={location.uuid}>
{location.display}
</option>
);
});

// Methods will be loadd from this.state.methods populated from the backend.
let methods = "<option> </option>";
return (
<div className="programme-component">
<h3>Search By Program Enrollement and Status</h3>
Expand Down Expand Up @@ -340,6 +357,35 @@ class ProgrammeComponent extends Component {
</div>
</div>
</form>

<h3>Search By Location</h3>
<form className="form-horizontal">
<div className="form-group">
<label htmlFor="gender" className="col-sm-2 control-label">Patients belonging to:</label>
<div className="col-sm-6">
<select className="form-control" id="location">
<option value="">Select Location </option>
{ locations }
</select>
</div>
</div>

<div className="form-group">
<label htmlFor="gender" className="col-sm-2 control-label">According to Method:</label>
<div className="col-sm-6">
<select className="form-control" id="method">
<option value="">Select Method </option>
{ methods }
</select>
</div>
</div>

<div className="form-group">
<div className="col-sm-offset-2 col-sm-6">
<button type="submit" className="btn btn-success">Search</button>
</div>
</div>
</form>
</div>
);
}
Expand Down

0 comments on commit e02ff8b

Please sign in to comment.