Skip to content

Commit

Permalink
Merge branch 'dev' into issue-138
Browse files Browse the repository at this point in the history
  • Loading branch information
francisli committed Nov 1, 2024
2 parents 0b09a1e + 2b053fb commit 2d2160a
Show file tree
Hide file tree
Showing 16 changed files with 579 additions and 43 deletions.
13 changes: 13 additions & 0 deletions client/src/pages/patients/LifelineAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,23 @@ export default class LifelineAPI {
return {
...item,
name: `${item.firstName} ${item.lastName}`,
hospital: item.hospitals[0]?.name,
};
});
}

static async registerPhysician(data) {
const response = await fetch(`${SERVER_BASE_URL}/physicians`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});

return response;
}

static async getHospitals(query) {
const response = await fetch(
`${SERVER_BASE_URL}/hospitals?hospital=${query}`,
Expand Down
16 changes: 11 additions & 5 deletions client/src/pages/patients/register/PatientRegistration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ export default function PatientRegistration() {
},
contactData: {
phone: (value) =>
value.length === 0 || value.match(/^\(\d{3}\)-\d{3}-\d{4}$/)
value.length === 0 || value.match(/^\(\d{3}\) \d{3}-\d{4}$/)
? null
: 'Phone number is not in XXX-XXX-XXXX format',
: 'Phone number is not in (XXX) XXX-XXXX format',
},
},
validateInputOnBlur: true,
Expand Down Expand Up @@ -172,9 +172,15 @@ export default function PatientRegistration() {

setInitialHospitalData(hospital ? hospital.name : '');

setInitialPhysicianData(
physician ? `${physician.firstName} ${physician.lastName}` : '',
);
if (physician) {
const fullName = `${physician.firstName}${physician.middleName ? ` ${physician.middleName}` : ''} ${physician.lastName}`;
const hospital = physician.hospitals[0]
? physician.hospitals[0].name
: '';
const phone = physician.phone ? `${physician.phone} ` : '';
const physicianDetails = `${fullName}${hospital ? ` (${hospital})` : ''}${phone ? ` - ${phone}` : ''}`;
setInitialPhysicianData(physicianDetails);
}

const patientData = {
firstName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export default function PatientRegistrationAccordion({
<InputBase
label="Phone Number"
component={IMaskInput}
mask="(000)-000-0000"
placeholder="(000)-000-0000"
mask="(000) 000-0000"
placeholder="(000) 000-0000"
key={form.key('contactData.phone')}
{...form.getInputProps('contactData.phone')}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import PropTypes from 'prop-types';

import { useState, useRef, useEffect } from 'react';
import { Combobox, useCombobox, ScrollArea } from '@mantine/core';
import { Combobox, useCombobox, ScrollArea, Text } from '@mantine/core';
import { notifications } from '@mantine/notifications';
import { useDebouncedCallback } from '@mantine/hooks';
import { useDebouncedCallback, useDisclosure } from '@mantine/hooks';

import SearchDatabaseInputField from './SearchDatabaseInputField';
import RegisterPhysician from './RegisterPhysician';

import LifelineAPI from '../../LifelineAPI.js';

Expand All @@ -24,6 +25,10 @@ export default function HealthcareChoicesSearch({ form, choice, initialData }) {
const [data, setData] = useState([]);
const [empty, setEmpty] = useState(false);
const [search, setSearch] = useState('');
const [
registerPhysicianOpened,
{ open: openRegisterPhysician, close: closeRegisterPhysician },
] = useDisclosure(false);

const abortController = useRef();

Expand Down Expand Up @@ -70,8 +75,10 @@ export default function HealthcareChoicesSearch({ form, choice, initialData }) {
};

const handleSelectValue = (id, key) => {
const name = key.children;
// setValue({ id, name });
if (id === '$register') {
return;
}
const name = key?.children?.join('') ?? key;
setSearch(name);
form.setFieldValue(`healthcareChoices.${choice}Id`, id);
combobox.closeDropdown();
Expand All @@ -80,6 +87,8 @@ export default function HealthcareChoicesSearch({ form, choice, initialData }) {
const options = (data || []).map((item) => (
<Combobox.Option value={item.id} key={item.id}>
{item.name}
{item.hospital ? ` (${item.hospital})` : ''}
{item.phone ? ` - ${item.phone}` : ''}
</Combobox.Option>
));

Expand All @@ -89,7 +98,18 @@ export default function HealthcareChoicesSearch({ form, choice, initialData }) {
*/
function renderComboxContent() {
if (empty) {
return <Combobox.Empty>No results found</Combobox.Empty>;
return choice === 'physician' ? (
<>
<Combobox.Empty> No results found</Combobox.Empty>
<Combobox.Option value="$register" onClick={openRegisterPhysician}>
<Text fw={700} size="sm">
+ Register new physician
</Text>
</Combobox.Option>
</>
) : (
<Combobox.Empty>No results found</Combobox.Empty>
);
}

if (data.length === 0) {
Expand All @@ -99,24 +119,43 @@ export default function HealthcareChoicesSearch({ form, choice, initialData }) {
return (
<ScrollArea.Autosize type="scroll" mah={200}>
{options}
{choice === 'physician' && (
<Combobox.Option value="$register" onClick={openRegisterPhysician}>
<Text fw={700} size="sm">
+ Register new physician
</Text>
</Combobox.Option>
)}
</ScrollArea.Autosize>
);
}

return (
<SearchDatabaseInputField
data={data}
loading={loading}
combobox={combobox}
label={
choice === 'hospital' ? 'Hospital of Choice' : 'Preferred Care Provider'
}
searchQuery={search}
handleSelectValue={handleSelectValue}
fetchOptions={fetchOptions}
comboboxOptions={renderComboxContent}
handleSearch={handleSearch}
/>
<>
<SearchDatabaseInputField
data={data}
loading={loading}
combobox={combobox}
label={
choice === 'hospital'
? 'Hospital of Choice'
: 'Preferred Care Provider'
}
searchQuery={search}
handleSelectValue={handleSelectValue}
fetchOptions={fetchOptions}
comboboxOptions={renderComboxContent}
handleSearch={handleSearch}
/>
{choice === 'physician' && (
<RegisterPhysician
setPhysician={handleSelectValue}
registerPhysicianOpened={registerPhysicianOpened}
closeRegisterPhysician={closeRegisterPhysician}
fetchOptions={fetchOptions}
/>
)}
</>
);
}

Expand Down
Loading

0 comments on commit 2d2160a

Please sign in to comment.