Skip to content

Commit

Permalink
Move Urgency field up into Incident info section
Browse files Browse the repository at this point in the history
Refactor and simplify creation of validationData in Ringdown.js.
Update section labels in ringdown form.
Fix Form.children prop type.
  • Loading branch information
fwextensions committed Aug 31, 2022
1 parent 2d9d881 commit c8dc2d5
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Form.propTypes = {
// eslint-disable-next-line react/forbid-prop-types
data: PropTypes.object.isRequired,
onChange: PropTypes.func,
children: Promise.node,
children: PropTypes.node,
};

Form.defaultProps = {
Expand Down
28 changes: 14 additions & 14 deletions src/EMS/PatientFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function PatientFields({ ringdown, onChange }) {

return (
<div className="usa-accordion">
<Heading title="Unit Info" />
<Heading title="Incident info" />
<div className="usa-accordion__content">
<fieldset className="usa-fieldset">
<FormComboBox
Expand All @@ -71,8 +71,19 @@ function PatientFields({ ringdown, onChange }) {
value={ringdown.dispatchCallNumber}
/>
</fieldset>
<FormRadioFieldSet
label="Urgency"
property="emergencyServiceResponseType"
value={ringdown.emergencyServiceResponseType}
validationState={ringdown.getValidationState('emergencyServiceResponseType')}
required
onChange={handleUserInput}
>
<FormRadio label="Code 2" value="CODE 2" />
<FormRadio label="Code 3" value="CODE 3" disabled={window.env.REACT_APP_DISABLE_CODE_3 === 'true'} />
</FormRadioFieldSet>
</div>
<Heading title="Patient Info" />
<Heading title="Patient info" />
<div className="usa-accordion__content">
<fieldset className="usa-fieldset">
<FormField metadata={Patient.age} />
Expand All @@ -89,17 +100,6 @@ function PatientFields({ ringdown, onChange }) {
<FormRadio label="Female" value="FEMALE" />
<FormRadio label="Non-binary" value="NON-BINARY" />
</FormRadioFieldSet>
<FormRadioFieldSet
label="Urgency"
property="emergencyServiceResponseType"
value={ringdown.emergencyServiceResponseType}
validationState={ringdown.getValidationState('emergencyServiceResponseType')}
required
onChange={handleUserInput}
>
<FormRadio label="Code 2" value="CODE 2" />
<FormRadio label="Code 3" value="CODE 3" disabled={window.env.REACT_APP_DISABLE_CODE_3 === 'true'} />
</FormRadioFieldSet>
<fieldset className="usa-fieldset">
<FormField metadata={Patient.chiefComplaintDescription}>
<div className="usa-hint usa-hint--important">
Expand Down Expand Up @@ -167,7 +167,7 @@ function PatientFields({ ringdown, onChange }) {
<FormField metadata={Patient.temperature} />
</fieldset>
</div>
<Heading title="Additional Notes" subtitle="optional" />
<Heading title="Additional notes" subtitle="optional" />
<div className="usa-accordion__content">
<fieldset className="usa-fieldset">
<FormField metadata={Patient.treatmentNotes} />
Expand Down
60 changes: 29 additions & 31 deletions src/Models/Ringdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ function overrideSetter(target, key, setter) {
});
}

// specify the fields that must all have valid input to make the ringdown valid. the second array item is an optional function to determine
// whether the field's current value is valid as input. the array order should be the same as the field order in PatientFields.
const validatedFields = [
['ambulanceIdentifier'],
['dispatchCallNumber'],
['emergencyServiceResponseType'],
['age'],
['sex'],
['chiefComplaintDescription'],
['stableIndicator', (value) => typeof value === 'boolean'],
['all', () => ValidationState.NO_INPUT],
];

class Ringdown {
static get Status() {
return DeliveryStatus;
Expand All @@ -48,7 +61,8 @@ class Ringdown {
this.payload.emsCall = this.payload.emsCall || {};
this.payload.hospital = this.payload.hospital || {};
// default the urgency to Code 2 for a new ringdown
this.payload.patient = this.payload.patient || { emergencyServiceResponseType: 'CODE 2' };
this.payload.patient =
this.payload.patient || (window.env.REACT_APP_DISABLE_CODE_3 && { emergencyServiceResponseType: 'CODE 2' }) || {};
this.payload.patientDelivery = this.payload.patientDelivery || {};

// add getters/setters for patient fields
Expand All @@ -66,36 +80,7 @@ class Ringdown {
this.restraintIndicator = newValue && this.restraintIndicator;
});

this.validationData = validationData || {
ambulanceIdentifier: new PatientFieldData(
'ambulanceIdentifier',
0,
this.ambulanceIdentifier ? ValidationState.INPUT : ValidationState.NO_INPUT
),
dispatchCallNumber: new PatientFieldData(
'dispatchCallNumber',
1,
this.dispatchCallNumber ? ValidationState.INPUT : ValidationState.NO_INPUT
),
age: new PatientFieldData('age', 2, this.age ? ValidationState.INPUT : ValidationState.NO_INPUT),
sex: new PatientFieldData('sex', 3, this.sex ? ValidationState.INPUT : ValidationState.NO_INPUT),
emergencyServiceResponseType: new PatientFieldData(
'emergencyServiceResponseType',
4,
this.emergencyServiceResponseType ? ValidationState.INPUT : ValidationState.NO_INPUT
),
chiefComplaintDescription: new PatientFieldData(
'chiefComplaintDescription',
5,
this.chiefComplaintDescription ? ValidationState.INPUT : ValidationState.NO_INPUT
),
stableIndicator: new PatientFieldData(
'stableIndicator',
6,
typeof this.stableIndicator === 'boolean' ? ValidationState.INPUT : ValidationState.NO_INPUT
),
all: new PatientFieldData('all', 7, ValidationState.NO_INPUT),
};
this.validationData = validationData || this.createValidationData(validatedFields);
}

clone() {
Expand Down Expand Up @@ -253,6 +238,19 @@ class Ringdown {
return 1;
}

createValidationData(fields) {
return fields.reduce((result, field, i) => {
const [name, validator] = field;
const fieldValue = this[name];
const value = typeof validator === 'function' ? validator(fieldValue) : fieldValue;
const state = value ? ValidationState.INPUT : ValidationState.NO_INPUT;

result[name] = new PatientFieldData(name, i, state);

return result;
}, {});
}

validatePatientFields(updatedField, inputValue) {
const updatedFieldHasValidations = updatedField in this.validationData;

Expand Down
12 changes: 6 additions & 6 deletions src/metadata/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ const fields = [
allowNull: false,
unique: true,
},
{
name: 'emergencyServiceResponseType',
type: 'enum',
enumValues: ['CODE 2', 'CODE 3'],
required: true,
},
{
name: 'age',
type: 'integer',
Expand All @@ -29,12 +35,6 @@ const fields = [
enumValues: ['MALE', 'FEMALE', 'NON-BINARY'],
required: true,
},
{
name: 'emergencyServiceResponseType',
type: 'enum',
enumValues: ['CODE 2', 'CODE 3'],
required: true,
},
{
name: 'chiefComplaintDescription',
type: 'text',
Expand Down

0 comments on commit c8dc2d5

Please sign in to comment.