Skip to content

Commit

Permalink
Merge pull request cds-hooks#157 from cqframework/patient-select-drop…
Browse files Browse the repository at this point in the history
…down

Fix Issues from Enhanced Patient Selection PR
  • Loading branch information
jmandel authored Nov 30, 2024
2 parents 049b3fa + ac36753 commit cb1f754
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 228 deletions.
21 changes: 10 additions & 11 deletions src/components/PatientEntry/patient-entry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,10 @@ export class PatientEntry extends Component {
try {
const data = await retrieveAllPatientIds();
const patients = [];
data.forEach((patient) => patients.push({ value: patient.id, label: patient.name + ', ' + patient.dob }));
this.setState({ patients: patients });
data.forEach((patient) => patients.push({ value: patient.id, label: `${patient.name}, ${patient.dob}` }));
this.setState({ patients });
} catch (error) {
this.setState({ shouldDisplayError: true, errorMessage: 'Error fetching patients from FHIR Server' });
return;
}
}

Expand Down Expand Up @@ -160,14 +159,14 @@ export class PatientEntry extends Component {
onClose={this.props.isEntryRequired ? null : this.handleCloseModal}
>
<PatientSelect
currentFhirServer={this.props.currentFhirServer}
formFieldLabel="Select a Patient"
shouldDisplayError={this.state.shouldDisplayError}
errorMessage={this.state.errorMessage}
placeholderText={this.state.currentPatient}
inputOnChange={this.handleChange}
inputName="patient-input"
patients={this.state.patients}
currentFhirServer={this.props.currentFhirServer}
formFieldLabel="Select a Patient"
shouldDisplayError={this.state.shouldDisplayError}
errorMessage={this.state.errorMessage}
placeholderText={this.state.currentPatient}
inputOnChange={this.handleChange}
inputName="patient-input"
patients={this.state.patients}
/>
</Dialog>
</Modal>
Expand Down
8 changes: 2 additions & 6 deletions src/components/PatientSelect/patient-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,10 @@ const propTypes = {
* If the value in the Input component changes (i.e user selects option), pass in a function callback to handle the text
*/
inputOnChange: PropTypes.func.isRequired,
/**
* The name attribute for the Input component
*/
inputName: PropTypes.string,
/**
* A list of the Patient identifiers that populate the select options
*/
patients: PropTypes.array.isRequired
patients: PropTypes.instanceOf(Array).isRequired,
};

/**
Expand All @@ -53,7 +49,7 @@ const propTypes = {
*/
const PatientSelect = ({
currentFhirServer, formFieldLabel, shouldDisplayError,
errorMessage, placeholderText, inputOnChange, inputName,
errorMessage, placeholderText, inputOnChange,
patients,
}) => {
let fhirServerDisplay;
Expand Down
7 changes: 5 additions & 2 deletions src/reducers/patient-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const patientReducers = (state = initialState, action) => {
// Store Patient resource from successful connection to patient in context from FHIR server
case types.GET_PATIENT_SUCCESS: {
const { patient } = action;
const familyName = (Array.isArray(patient.name[0].family)) ? patient.name[0].family.join(' ') : patient.name[0].family;
const fullName = `${patient.name[0].given.join(' ')} ${familyName}`;
let fullName = 'Unknown';
if (Array.isArray(patient.name)) {
const familyName = (Array.isArray(patient.name[0].family)) ? patient.name[0].family.join(' ') : patient.name[0].family;
fullName = `${patient.name[0].given.join(' ')} ${familyName}`;
}
const newPatient = {
id: patient.id,
name: fullName,
Expand Down
19 changes: 10 additions & 9 deletions src/retrieve-data-helpers/all-patient-retrieval.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ function retrieveAllPatientIds() {
}).then((result) => {
if (result.data && result.data.resourceType === 'Bundle'
&& Array.isArray(result.data.entry) && result.data.entry.length) {
for (const patient of result.data.entry) {
let patientInfo = {id: '', name: 'Unknown', dob: ''};
patientInfo.id = patient.resource.id;
const familyName = (Array.isArray(patient.resource.name[0].family)) ? patient.resource.name[0].family.join(' ') : patient.resource.name[0].family;
result.data.entry.forEach((patient) => {
const patientInfo = { id: '', name: 'Unknown', dob: '' };
patientInfo.id = patient.resource.id;
if (Array.isArray(patient.resource.name)) {
const familyName = Array.isArray(patient.resource.name[0].family) ? patient.resource.name[0].family.join(' ') : patient.resource.name[0].family;
patientInfo.name = `${patient.resource.name[0].given.join(' ')} ${familyName}`;
patientInfo.dob = patient.resource.birthDate;
patientInfoList.push(patientInfo);
}
return resolve(patientInfoList);
} else {
return reject();
patientInfo.dob = patient.resource.birthDate;
patientInfoList.push(patientInfo);
});
return resolve(patientInfoList);
}
return reject();
}).catch((err) => {
console.error('Could not retrieve patients from current FHIR server', err);
return reject(err);
Expand Down
Loading

0 comments on commit cb1f754

Please sign in to comment.