Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Added custom-form component
Browse files Browse the repository at this point in the history
Replaced custom philippines social form with generic component, driven
by db configuration.  For #90, but we still need to do more work here.
  • Loading branch information
jkleinsc committed May 25, 2016
1 parent e6777ad commit c40091f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 64 deletions.
38 changes: 38 additions & 0 deletions app/components/custom-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ember from 'ember';
import SelectValues from 'hospitalrun/utils/select-values';
export default Ember.Component.extend(SelectValues, {
classNames: 'detail-section-content',
fieldsByRow: function() {
let rows = [];
const form = this.get('form');
if (!Ember.isEmpty(form)) {
const fields = form.fields;
const numberOfColumns = this.getWithDefault('form.columns', 1);
let currentRow = [];

let colCount = 0;
let colWidth = (12 / numberOfColumns);
fields.forEach((field) => {
if (!field.classNames) {
field.classNames = '';
}
let colSpan = field.colSpan || 1;
if (colCount === numberOfColumns || (colCount + colSpan) > numberOfColumns) {
rows.push(currentRow.slice());
currentRow = [];
colCount = 0;
}
field.classNames += ' col-sm-' + (colWidth * colSpan);
if (field.type === 'select') {
field.mappedValues = field.values.map(this.selectValuesMap);
}
currentRow.push(field);
colCount += colSpan;
});
if (colCount > 0) {
rows.push(currentRow);
}
}
return rows;
}.property('form')
});
27 changes: 1 addition & 26 deletions app/patients/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,11 @@ export default AbstractEditController.extend(BloodTypes, ReturnTo, UserSession,
return this.currentUserCan('delete_visit');
}.property(),

economicClassificationTypes: [
'A',
'B',
'C1',
'C2',
'C3',
'D'
].map(SelectValues.selectValuesMap),

livingArrangementList: [
'Homeless',
'Institution',
'Owned',
'Rent',
'Shared'
],

patientTypes: [
'Charity',
'Private'
],

philhealthTypes: [
'Employed: Government',
'Employed: Non Paying Member/Lifetime',
'Employed: OWWA/OFW',
'Employed: Private',
'Employed: Sponsored/Indigent',
'Self Employed'
].map(SelectValues.selectValuesMap),

filesystem: Ember.inject.service(),
database: Ember.inject.service(),
patientController: Ember.inject.controller('patients'),
Expand All @@ -118,6 +92,7 @@ export default AbstractEditController.extend(BloodTypes, ReturnTo, UserSession,

clinicList: Ember.computed.alias('patientController.clinicList'),
countryList: Ember.computed.alias('patientController.countryList'),
customSocialForm: Ember.computed.alias('patientController.customSocialForm.value'),
isFileSystemEnabled: Ember.computed.alias('filesystem.isFileSystemEnabled'),

pricingProfiles: Ember.computed.map('patientController.pricingProfiles', SelectValues.selectObjectMap),
Expand Down
39 changes: 1 addition & 38 deletions app/patients/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -477,44 +477,7 @@
</tr>
{{/if}}
</table>
<div class="row">
<div class="form-group col-sm-6">
<label>Living Arrangement</label>
{{ext-radio
name="livingArrangement"
content=livingArrangementList
value=model.livingArrangement
includeOtherOption=true
otherOptionLabel="Other"
radioLabelPath="content"
radioValuePath="content"
}}
</div>
<div class="form-group col-sm-6">
<label>Family Support System</label>
{{em-checkbox label="Family members are living together" property="familySupport1"}}
{{em-checkbox label="Family members listen, care and help one another" property="familySupport2"}}
{{em-checkbox label="Spend time together in prayer especially in difficult times" property="familySupport3"}}
{{em-checkbox label="Family and closest relatives have open communication" property="familySupport4"}}
{{em-checkbox label="Has relatives around who are responsive to families needs" property="familySupport5"}}
</div>
</div>
{{em-text label="Assessment/Findings" property="notes"}}
{{em-text label="Recommendation" property="socialRecommendation"}}
{{em-text label="Action Taken" property="socialActionTaken"}}
<div class="row">
{{em-select label="Philhealth"
property="insurance" content=philhealthTypes
selected=model.insurance
class="col-sm-6"
}}
{{em-select label="Classification"
property="economicClassification" content=economicClassificationTypes
selected=model.economicClassification
class="col-sm-6"
prompt=" "
}}
</div>
{{custom-form model=model form=customSocialForm}}
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions app/patients/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export default AbstractModuleRoute.extend(PatientId, {
}, {
name: 'countryList',
findArgs: ['lookup', 'country_list']
}, {
name: 'customSocialForm',
findArgs: ['option', 'custom_form_social']
}, {
name: 'diagnosisList',
findArgs: ['lookup', 'diagnosis_list']
Expand Down
41 changes: 41 additions & 0 deletions app/templates/components/custom-form.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{{#each fieldsByRow as |row|}}
<div class="row form-group">
{{#each row as |field|}}
{{#if (eq field.type 'radio')}}
<div class="form-group {{field.classNames}}">
<label>{{field.label}}</label>
{{ext-radio
content=field.values
value=(get model field.property)
includeOtherOption=field.includeOtherOption
otherOptionLabel=field.otherOptionLabel
radioLabelPath="content"
radioValuePath="content"
}}
</div>
{{/if}}
{{#if (eq field.type 'checkbox')}}
<div class="form-group {{field.classNames}}">
<label>{{field.label}}</label>
{{#each field.checkboxes as |checkbox|}}
{{em-checkbox label=checkbox.label property=checkbox.property}}
{{/each}}
</div>
{{/if}}
{{#if (eq field.type 'textarea')}}
{{em-text label=field.label property=field.property class=field.classNames}}
{{/if}}
{{#if (eq field.type 'text')}}
{{em-input label=field.label property=field.property class=field.classNames}}
{{/if}}
{{#if (eq field.type 'select')}}
{{em-select label=field.label
property=field.property
content=field.mappedValues
class=field.classNames
prompt=field.prompt
}}
{{/if}}
{{/each}}
</div>
{{/each}}

0 comments on commit c40091f

Please sign in to comment.