All Fields Wired

This commit is contained in:
Ben Mitchinson committed 2020-04-24 05:22:07 -05:00
1 parent 97ce9e95f9
commit 6b8a191ab0
7 files changed
+400 -258

No files matched your search

+5 -1
View File
@@ -11,6 +11,7 @@ import PatientInfoForm from './components/PatientInfoForm'
import './scss/App.scss'
import './antd-mobile.css'
import DebugShowEasyPeasy from './components/DebugShowEasyPeasy'
const App: React.FunctionComponent = () => {
return (
@@ -29,9 +30,12 @@ const App: React.FunctionComponent = () => {
leftArrowText="Home"
leftArrowRoute="/"
>
<PatientInfoPlaceholder />
<PatientInfoForm />
</Wrapper>
</Route>
<Route path="/easy-peasy">
<DebugShowEasyPeasy />
</Route>
<Route path="/">
<Login />
</Route>
+12
View File
@@ -0,0 +1,12 @@
import React, { ReactElement } from 'react'
import { useStoreState } from '../state/storeIndex'
export default function DebugShowEasyPeasy(): ReactElement {
const patientInfoFormData = useStoreState(
(state) => state.patientInfoFormModel.fields,
)
console.log(patientInfoFormData)
return <div>patientInfoFormData: {JSON.stringify(patientInfoFormData)}</div>
}
+365 -253
View File
@@ -1,282 +1,394 @@
import React, { ReactElement, useState } from "react";
import React, { ReactElement, useState } from 'react'
import { useStoreActions } from '../state/storeIndex'
import { SEX, Y_N } from '../state/enums'
import {
InputItem,
List,
TextareaItem,
Button,
Radio,
WhiteSpace,
} from "antd-mobile";
import "../scss/PatientInfoForm.scss";
InputItem,
List,
TextareaItem,
Button,
Radio,
WhiteSpace,
} from 'antd-mobile'
import '../scss/PatientInfoForm.scss'
const RadioItem = Radio.RadioItem;
const RadioItem = Radio.RadioItem
export default function Form(): ReactElement {
// State Hooks for Radio Buttons
// useState returns a value, and a function to set that value
const [sex, setSex] = useState(null as Number); // Default: null
const [albendazole, setAlbendazole] = useState(0); // Default: No
const [firstVisit, setFirstVisit] = useState(0); // Default: No
const [pregnant, setPregnant] = useState(0); // Default: No
const [planning, setPlanning] = useState(0); // Default: No
const [bloodPressureValue, setBloodPressureValue] = useState("");
// State Hooks for Radio Buttons
// useState returns a value, and a function to set that value
const [sex, setSex] = useState(null as number) // Default: null
const [albendazole, setAlbendazole] = useState(0) // Default: No
const [firstVisit, setFirstVisit] = useState(0) // Default: No
const [pregnant, setPregnant] = useState(0) // Default: No
const [planning, setPlanning] = useState(0) // Default: No
const [bloodPressureValue, setBloodPressureValue] = useState('')
const updateCentralState = useStoreActions(
(actions) => actions.patientInfoFormModel.updateFields,
)
// Data for Radio Buttons
const sexValues = [
{ value: 0, label: "Male" },
{ value: 1, label: "Female" },
];
// Data for Radio Buttons
const sexValues = [
{ value: 0, label: 'Male' },
{ value: 1, label: 'Female' },
]
const radioYesNo = [
{ value: 0, label: "No" },
{ value: 1, label: "Yes" },
];
const radioYesNo = [
{ value: 0, label: 'No' },
{ value: 1, label: 'Yes' },
]
/* istanbul ignore next */
const onSubmit = () => {
if (process.env.NODE_ENV === "development") {
// This shows how to access the values of the form
const firstNameField: HTMLInputElement = document.getElementById(
"firstname"
) as HTMLInputElement;
const lastNameField: HTMLInputElement = document.getElementById(
"lastname"
) as HTMLInputElement;
const nicknameField: HTMLInputElement = document.getElementById(
"nickname"
) as HTMLInputElement;
const birthdateField: HTMLInputElement = document.getElementById(
"birthdate"
) as HTMLInputElement;
const complaintField1: HTMLInputElement = document.getElementById(
"complaint1"
) as HTMLInputElement;
const complaintField2: HTMLInputElement = document.getElementById(
"complaint2"
) as HTMLInputElement;
const complaintField3: HTMLInputElement = document.getElementById(
"complaint3"
) as HTMLInputElement;
/* istanbul ignore next */
const onSubmit = () => {
const firstNameField: HTMLInputElement = document.getElementById(
'firstname',
) as HTMLInputElement
const lastNameField: HTMLInputElement = document.getElementById(
'lastname',
) as HTMLInputElement
const nicknameField: HTMLInputElement = document.getElementById(
'nickname',
) as HTMLInputElement
const birthdateField: HTMLInputElement = document.getElementById(
'birthdate',
) as HTMLInputElement
const age: HTMLInputElement = document.getElementById(
'age',
) as HTMLInputElement
const phone: HTMLInputElement = document.getElementById(
'phone',
) as HTMLInputElement
const town: HTMLInputElement = document.getElementById(
'town',
) as HTMLInputElement
const gravida: HTMLInputElement = document.getElementById(
'gravida',
) as HTMLInputElement
const para: HTMLInputElement = document.getElementById(
'para',
) as HTMLInputElement
const abortus: HTMLInputElement = document.getElementById(
'abortus',
) as HTMLInputElement
const lmp: HTMLInputElement = document.getElementById(
'lmp',
) as HTMLInputElement
const weight: HTMLInputElement = document.getElementById(
'weight',
) as HTMLInputElement
const height: HTMLInputElement = document.getElementById(
'height',
) as HTMLInputElement
const temp: HTMLInputElement = document.getElementById(
'temp',
) as HTMLInputElement
const pulse: HTMLInputElement = document.getElementById(
'pulse',
) as HTMLInputElement
const zScore: HTMLInputElement = document.getElementById(
'z-score',
) as HTMLInputElement
const alergies: HTMLInputElement = document.getElementById(
'alergies',
) as HTMLInputElement
const medicines: HTMLInputElement = document.getElementById(
'medicines',
) as HTMLInputElement
const complaintField1: HTMLInputElement = document.getElementById(
'complaint1',
) as HTMLInputElement
const complaintField2: HTMLInputElement = document.getElementById(
'complaint2',
) as HTMLInputElement
const complaintField3: HTMLInputElement = document.getElementById(
'complaint3',
) as HTMLInputElement
const history: HTMLInputElement = document.getElementById(
'history',
) as HTMLInputElement
const exam: HTMLInputElement = document.getElementById(
'exam',
) as HTMLInputElement
updateCentralState({
firstName: firstNameField.value,
lastName: lastNameField.value,
nickname: nicknameField.value,
sex: sex ? SEX.female : SEX.male,
birthDate: new Date(birthdateField.value),
age: parseInt(age.value),
phone: phone.value,
town: town.value,
firstVisit: firstVisit,
pregnant: pregnant,
G: parseInt(gravida.value),
P: parseInt(para.value),
A: parseInt(abortus.value),
LMP: new Date(lmp.value),
wantsPlanning: planning,
weight: parseFloat(weight.value),
height: parseFloat(height.value),
bloodPressure: bloodPressureValue,
temperature: parseFloat(temp.value),
pulse: parseFloat(pulse.value),
zScore: parseFloat(zScore.value),
albendazole: albendazole,
alergies: alergies.value,
medicines: medicines.value,
chiefComplaint: [
complaintField1.value,
complaintField2.value,
complaintField3.value,
],
history: history.value,
exam: exam.value,
})
console.log("First name:", firstNameField.value);
console.log("Last name:", lastNameField.value);
console.log("Nickname:", nicknameField.value);
console.log("Birth Date:", birthdateField.value);
console.log(
"Complaints: ",
complaintField1.value +
" " +
complaintField2.value +
" " +
complaintField3.value
);
console.log("Wants Planning?: " + planning);
if (process.env.NODE_ENV === 'development') {
console.log(
'bday?: ' + birthdateField.value,
new Date(birthdateField.value),
)
console.log('lmp?: ' + lmp.value, new Date(lmp.value))
}
}
};
const validateAndSetBloodPressure = (value: string) => {
const newChar = value.slice(-1);
if (newChar.match(/[0-9]|\/|^$/) && value.length < 8) {
setBloodPressureValue(value);
const validateAndSetBloodPressure = (value: string) => {
const newChar = value.slice(-1)
if (newChar.match(/[0-9]|\/|^$/) && value.length < 8) {
setBloodPressureValue(value)
}
}
};
return (
<div id="patient-info-wrapper">
<TextareaItem
title="First Name"
placeholder="First Name"
autoHeight
id="firstname"
/>
return (
<div id="patient-info-wrapper">
<TextareaItem
title="First Name"
placeholder="First Name"
autoHeight
id="firstname"
/>
<TextareaItem
title="Last Name"
placeholder="Last Name"
id="lastname"
autoHeight
/>
<TextareaItem
title="Last Name"
placeholder="Last Name"
id="lastname"
autoHeight
/>
<TextareaItem
title="Nickname"
placeholder="Nickname"
id="nickname"
autoHeight
/>
<TextareaItem
title="Nickname"
placeholder="Nickname"
id="nickname"
autoHeight
/>
<List renderHeader={() => "Sex"}>
{sexValues.map((i) => (
<RadioItem
data-testid={`${i.label.toLowerCase()}-button`}
id={`${i.label.toLowerCase()}-button`}
key={i.value}
name="sex"
checked={sex === i.value}
onClick={() => setSex(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<List renderHeader={() => 'Sex'}>
{sexValues.map((i) => (
<RadioItem
data-testid={`${i.label.toLowerCase()}-button`}
id={`${i.label.toLowerCase()}-button`}
key={i.value}
name="sex"
checked={sex === i.value}
onClick={() => setSex(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<WhiteSpace />
<WhiteSpace />
<InputItem placeholder="YYYY-MM-DD" id="birthdate" type="digit" maxLength={10}>
Birth Date
</InputItem>
<InputItem placeholder="YYYY-MM-DD" id="birthdate" maxLength={10}>
Birth Date
</InputItem>
<InputItem type="number" placeholder="Age" id="age" maxLength={3}>
Age{" "}
</InputItem>
<InputItem type="number" placeholder="Age" id="age" maxLength={3}>
Age{' '}
</InputItem>
<InputItem type="number" placeholder="Phone" id="phone">
Phone
</InputItem>
<InputItem type="number" placeholder="Phone" id="phone">
Phone
</InputItem>
<TextareaItem title="Town" placeholder="Town" id="town" autoHeight />
<TextareaItem
title="Town"
placeholder="Town"
id="town"
autoHeight
/>
<List renderHeader={() => "First Visit?"}>
{radioYesNo.map((i) => (
<RadioItem
key={i.value}
data-testid={`first-visit-${i.label}`}
name="visit"
checked={firstVisit === i.value}
onClick={() => setFirstVisit(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<List renderHeader={() => 'First Visit?'}>
{radioYesNo.map((i) => (
<RadioItem
key={i.value}
data-testid={`first-visit-${i.label}`}
name="visit"
checked={firstVisit === i.value}
onClick={() => setFirstVisit(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
{/* Only display the 'female-only' div if the patient is female */}
{sex ? (
<div id="female-only">
<WhiteSpace />
<List renderHeader={() => "Pregnant?"}>
{radioYesNo.map((i) => (
<RadioItem
data-testid={`pregnant-${i.label}`}
key={i.value}
name="pregnant"
checked={pregnant === i.value}
onClick={() => setPregnant(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
{/* Only display the 'female-only' div if the patient is female */}
{sex ? (
<div id="female-only">
<WhiteSpace />
<List renderHeader={() => 'Pregnant?'}>
{radioYesNo.map((i) => (
<RadioItem
data-testid={`pregnant-${i.label}`}
key={i.value}
name="pregnant"
checked={pregnant === i.value}
onClick={() => setPregnant(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<InputItem title="G" type="number" id="gravida" placeholder="0">
G
</InputItem>
<InputItem
title="G"
type="number"
id="gravida"
placeholder="0"
>
G
</InputItem>
<InputItem title="P" type="number" id="para" placeholder="0">
P
</InputItem>
<InputItem
title="P"
type="number"
id="para"
placeholder="0"
>
P
</InputItem>
<InputItem title="A" type="number" id="abortus" placeholder="0">
A
</InputItem>
<InputItem
title="A"
type="number"
id="abortus"
placeholder="0"
>
A
</InputItem>
<InputItem placeholder="YYYY-MM-DD" id="lmp" type="digit" maxLength={10}>
LMP
</InputItem>
<InputItem placeholder="YYYY-MM-DD" id="lmp" maxLength={10}>
LMP
</InputItem>
<List renderHeader={() => "Wants Planning?"}>
{radioYesNo.map((i) => (
<RadioItem
data-testid={`planning-${i.label}`}
key={i.value}
name="planning"
checked={planning === i.value}
onClick={() => setPlanning(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<List renderHeader={() => 'Wants Planning?'}>
{radioYesNo.map((i) => (
<RadioItem
data-testid={`planning-${i.label}`}
key={i.value}
name="planning"
checked={planning === i.value}
onClick={() => setPlanning(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
</div>
) : null}
<WhiteSpace />
<InputItem
type="number"
placeholder="Weight"
id="weight"
maxLength={3}
>
Weight (kg)
</InputItem>
<InputItem
type="number"
placeholder="Height"
id="height"
maxLength={3}
>
Height (cm)
</InputItem>
<InputItem
placeholder="Blood Pressure"
id="bp"
value={bloodPressureValue}
onChange={validateAndSetBloodPressure}
>
BP
</InputItem>
<InputItem type="number" placeholder="Temp" id="temp" maxLength={3}>
Temp (F)
</InputItem>
<InputItem
type="number"
placeholder="Pulse"
id="pulse"
maxLength={3}
>
Pulse
</InputItem>
<InputItem type="number" placeholder="Z-Score" id="z-score">
Z-Score
</InputItem>
<List renderHeader={() => 'Albendazole?'}>
{radioYesNo.map((i) => (
<RadioItem
data-testid={`albendazole-${i.label}`}
key={i.value}
checked={albendazole === i.value}
onClick={() => setAlbendazole(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<List renderHeader={() => 'Alergies'}>
<TextareaItem autoHeight id="alergies" />
</List>
<List renderHeader={() => 'Medicines'}>
<TextareaItem autoHeight id="medicines" />
</List>
<List renderHeader={() => 'Chief Complaint'}>
<TextareaItem
placeholder="1."
// autoHeight
autoHeight
id="complaint1"
/>
<TextareaItem placeholder="2." autoHeight id="complaint2" />
<TextareaItem placeholder="3." autoHeight id="complaint3" />
</List>
<List renderHeader={() => 'History'}>
<TextareaItem autoHeight id="history" />
</List>
<List renderHeader={() => 'Exam'}>
<TextareaItem autoHeight id="exam" />
</List>
<WhiteSpace />
<div className="submit-button">
<List>
<Button onClick={onSubmit}>Submit</Button>
</List>
</div>
</div>
) : null}
<WhiteSpace />
<InputItem type="number" placeholder="Weight" id="weight" maxLength={3}>
Weight (kg)
</InputItem>
<InputItem type="number" placeholder="Height" id="height" maxLength={3}>
Height (cm)
</InputItem>
<InputItem
placeholder="Blood Pressure"
id="bp"
value={bloodPressureValue}
onChange={validateAndSetBloodPressure}
>
BP
</InputItem>
<InputItem type="number" placeholder="Temp" id="temp" maxLength={3}>
Temp (F)
</InputItem>
<InputItem type="number" placeholder="Pulse" id="pulse" maxLength={3}>
Pulse
</InputItem>
<InputItem type="number" placeholder="Z-Score" id="z-score">
Z-Score
</InputItem>
<List renderHeader={() => "Albendazole?"}>
{radioYesNo.map((i) => (
<RadioItem
data-testid={`albendazole-${i.label}`}
key={i.value}
checked={albendazole === i.value}
onClick={() => setAlbendazole(i.value)}
>
{i.label}
</RadioItem>
))}
</List>
<List renderHeader={() => "Alergies"}>
<TextareaItem autoHeight id="alergies" />
</List>
<List renderHeader={() => "Medicines"}>
<TextareaItem autoHeight id="medicines" />
</List>
<List renderHeader={() => "Chief Complaint"}>
<TextareaItem
placeholder="1."
// autoHeight
autoHeight
id="complaint1"
/>
<TextareaItem placeholder="2." autoHeight id="complaint2" />
<TextareaItem placeholder="3." autoHeight id="complaint3" />
</List>
<List renderHeader={() => "History"}>
<TextareaItem autoHeight id="history" />
</List>
<List renderHeader={() => "Exam"}>
<TextareaItem autoHeight id="exam" />
</List>
<WhiteSpace />
<div className="submit-button">
<List>
<Button onClick={onSubmit}>Submit</Button>
</List>
</div>
</div>
);
)
}
+2
View File
@@ -1,3 +1,5 @@
/* istanbul ignore file */
export enum SEX {
male = 'male',
female = 'female',
+11 -2
View File
@@ -11,6 +11,12 @@ interface PatientInfoFormFields {
phone?: string
town?: string
firstVisit?: Y_N
pregnant?: Y_N
G?: number
P?: number
A?: number
LMP?: Date
wantsPlanning?: Y_N
weight?: number
height?: number
bloodPressure?: string
@@ -32,8 +38,11 @@ export interface PatientInfoFormModel {
const patientInfoFormModel: PatientInfoFormModel = {
fields: {},
updateFields: action((state, payload) => {
state.fields = payload
updateFields: action((state, formObject) => {
console.log('updating with: ', formObject)
console.log('state pre', state)
state.fields = formObject
console.log('state post', state)
}),
}
+4 -2
View File
@@ -1,6 +1,8 @@
import { createStore } from 'easy-peasy'
/* istanbul ignore file */
import { createStore, persist } from 'easy-peasy'
import storeIndex from './storeIndex'
const store = createStore(storeIndex)
const store = createStore(persist(storeIndex))
export default store
+1
View File
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import { createTypedHooks } from 'easy-peasy'
import patientInfoFormModel from './models/newPatientFormModels'