Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bkretz/feature/celcius temp #275

Merged
merged 13 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions client/src/EMS/BloodPressureField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FormInput from '../Components/FormInput';
import { useForm } from '../Components/Form';

import './BloodPressureField.scss';
kretzbryan marked this conversation as resolved.
Show resolved Hide resolved
import FormMultiField from './FormMultiField';

function BPInput({ metadata, unit }) {
const { data, onChange } = useForm();
Expand All @@ -18,7 +19,7 @@ function BPInput({ metadata, unit }) {
// grouped with its input in a div because the fields are arranged horizontally
// in a row. since the errors are absolutely positioned, they'd both shift to
// the left margin of the .bpfield without this extra div, causing an overlap.
<div className="bpfield__input">
<>
kretzbryan marked this conversation as resolved.
Show resolved Hide resolved
<FormInput
type="number"
property={name}
Expand All @@ -29,7 +30,7 @@ function BPInput({ metadata, unit }) {
max={max}
onChange={onChange}
/>
</div>
</>
);
}

Expand All @@ -39,15 +40,16 @@ export default function BloodPressureField({ systolicMetadata, diastolicMetadata
const hasError = validations.includes(ValidationState.RANGE_ERROR);

return (
<>
<label htmlFor={systolicMetadata.name} className={classNames('usa-label', { 'usa-label--error': hasError })}>
Blood pressure
</label>
<div className="bpfield">
<BPInput metadata={systolicMetadata} unit="/" />
<BPInput metadata={diastolicMetadata} unit="mmHG" />
</div>
</>
<FormMultiField
label={
<label htmlFor={systolicMetadata.name} className={classNames('usa-label', { 'usa-label--error': hasError })}>
Blood pressure
</label>
}
>
<BPInput metadata={systolicMetadata} unit="/" />
<BPInput metadata={diastolicMetadata} unit="mmHG" />
</FormMultiField>
);
}

Expand Down
17 changes: 17 additions & 0 deletions client/src/EMS/FormMultiField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import './FormMultiField.scss';

const FormMultiField = ({ label, children }) => {
return (
<>
{label}
<div className="multi-field">
{children.map((child) => {
return <div className="multi-field__input">{child}</div>;
})}
</div>
</>
);
};

export default FormMultiField;
22 changes: 22 additions & 0 deletions client/src/EMS/FormMultiField.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@import '../theme/base';

.multi-field {
display: flex;
gap: 0.6rem;
position: relative;
}

.multi-field__input {
.grid-row {
flex-wrap: nowrap;
}

.usa-input {
width: 13ex;
}

.usa-error-message {
top: 3rem;
max-width: 9rem;
}
}
15 changes: 14 additions & 1 deletion client/src/EMS/PatientFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Ringdown from '../Models/Ringdown';
import ApiService from '../ApiService';
import Context from '../Context';
import patient from '../../../shared/metadata/patient';
import TemperatureField from './TemperatureField';

const Patient = patient.getFieldHash();

Expand Down Expand Up @@ -157,7 +158,19 @@ function PatientFields({ ringdown, onChange }) {
/>
</FormRadioFieldSet>
</div>
<FormField metadata={Patient.temperature} />
{/* <FormField metadata={Patient.temperature} /> */}
<TemperatureField temperatureMetadata={Patient.temperature} />
{/* <FormField
metadata={Patient.temperature}
label="Temperature"
>
<span className="usa-hint usa-hint--unit">&nbsp;&nbsp;</span>
<FormField
metadata={Patient.temperature.conversion}
isWrapped={false}
label={false}
/>
</FormField> */}
kretzbryan marked this conversation as resolved.
Show resolved Hide resolved
</fieldset>
</div>
<Heading title="Additional notes" subtitle="optional" />
Expand Down
63 changes: 63 additions & 0 deletions client/src/EMS/TemperatureField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { useState } from 'react';
import { useForm } from '../Components/Form';
import FormInput from '../Components/FormInput';

import { ValidationState } from '../Models/PatientFieldData';
import classNames from 'classnames';

import FormMultiField from './FormMultiField';

const TemperatureInput = ({ metadata, unit, onChange, value }) => {
const { data } = useForm();
const { name, range = {} } = metadata || {};
const { min, max } = range;

return (
<>
<FormInput
type="number"
property={name}
value={data[name] || value}
validationState={data.getValidationState(name)}
unit={unit || metadata?.unit}
min={min}
max={max}
onChange={onChange}
/>
</>
);
};

const TemperatureField = ({ temperatureMetadata }) => {
const { data, onChange } = useForm();
const [celsius, setCelsius] = useState('');
const celsiusMetadata = { name: 'celsius', unit: '°C', range: { min: 26.5, max: 65.5 } };

const hasError = data.getValidationState(temperatureMetadata.name) === ValidationState.RANGE_ERROR;

const handleOnChange = (name, value) => {
if (name === 'celsius') {
onChange('temperature', (parseFloat(value) * 1.8 + 32).toFixed(2));
setCelsius(value);
} else {
onChange(name, value);
setCelsius(((parseFloat(value) - 32) / 1.8).toFixed(2));
}
};
return (
<>
<FormMultiField
label={
<label htmlFor={temperatureMetadata.name} className={classNames('usa-label', { 'usa-label--error': hasError })}>
Temperature
</label>
}
>
<TemperatureInput metadata={temperatureMetadata} onChange={handleOnChange} />
<TemperatureInput metadata={celsiusMetadata} value={celsius} onChange={handleOnChange} />
</FormMultiField>
</>
);
};

export default TemperatureField;
14 changes: 11 additions & 3 deletions client/src/Models/Ringdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const fieldHashes = {
// array order should be the same as the field order in PatientFields.

const handleInputValidation = (name, value) => {
const { type = null, required = false } = fieldHashes[name];
const { type = null, required = false } = fieldHashes[name] || {};

let isValidType = false;
switch (type) {
Expand Down Expand Up @@ -80,7 +80,7 @@ const payloadModels = [
[['emergencyMedicalServiceCall', 'emsCall'], ['dispatchCallNumber']],
// we want to expose the hospital id field under a different name, so we'll define it in the class below instead of here
['hospital', []],
['patient', metadata.patient.getObjectFields()],
['patient', [...metadata.patient.getObjectFields()]],
['patientDelivery', ['etaMinutes', 'currentDeliveryStatus']],
];

Expand Down Expand Up @@ -274,9 +274,17 @@ class Ringdown {

setValidationStateForInput(fieldName, currentState, inputValue) {
const isInputValueEmpty = isValueEmpty(inputValue);
const { range, required = false } = fieldHashes[fieldName];
const {
range,
required = false,
// conversion = null, originColumn
} = fieldHashes[fieldName];
const isInRange = range && handleRange(inputValue, range.max, range.min);

// if (conversion || originColumn) {
// this.setConvertedField(conversion?.name || originColumn, inputValue);
// }
kretzbryan marked this conversation as resolved.
Show resolved Hide resolved

switch (currentState) {
case ValidationState.REQUIRED_ERROR:
case ValidationState.EMPTY_REQUIRED_INPUT:
Expand Down