Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
refactor(routes/preferences/user): removed unused branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Jan 11, 2021
1 parent c306093 commit f7e7d32
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/routes/preferences/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function route(server, options) {

let priorityCount = 0;

// Build preference objects, merging in results from preference list query
// Build preference objects, merging in results from preferenceValueOptions query
preferenceTypeOptions.forEach((preferenceType) => {
const preferenceObj = {
type: {
Expand Down
78 changes: 33 additions & 45 deletions src/routes/preferences/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,72 +29,60 @@ async function route(server, options) {
})
);

const patientPreferenceTypes = recordsets[0];
const patientPreferences = recordsets[0];
const patientPreferencesValues = recordsets[1];

if (
patientPreferenceTypes &&
patientPreferenceTypes.length !== 0
) {
if (patientPreferences && patientPreferences.length !== 0) {
// Build patient object
const patientObj = {
id: patientPreferenceTypes[0].id,
id: patientPreferences[0].id,
meta: {
created: patientPreferenceTypes[0].meta_created,
lastupdated:
patientPreferenceTypes[0].meta_lastupdated,
created: patientPreferences[0].meta_created,
lastupdated: patientPreferences[0].meta_lastupdated,
},
preferences: [],
};

// Build preference objects, merging in results from preferenceList query
patientPreferenceTypes.forEach((preferenceType) => {
// Build preference objects, merging in results from patientPreferencesValues query
patientPreferences.forEach((patientPreference) => {
const preferenceObj = {
type: {
display: preferenceType.preference_type_display,
id: preferenceType.preference_type_id,
display:
patientPreference.preference_type_display,
id: patientPreference.preference_type_id,
priority:
preferenceType.preference_type_priority,
patientPreference.preference_type_priority,
selected: undefined,
options: [],
},
};

// Build option objects to populate options array
if (
patientPreferencesValues &&
patientPreferencesValues.length !== 0
) {
patientPreferencesValues.forEach(
(preferenceValue) => {
if (
preferenceValue.preference_type_id ===
preferenceType.preference_type_id
) {
const optionObj = {
display:
preferenceValue.preference_option_display,
value:
preferenceValue.preference_option_value,
};
patientPreferencesValues.forEach((preferenceValue) => {
if (
preferenceValue.preference_type_id ===
patientPreference.preference_type_id
) {
const optionObj = {
display:
preferenceValue.preference_option_display,
value:
preferenceValue.preference_option_value,
};

if (
preferenceType.preferenceValueId ===
preferenceValue.preference_option_value
) {
preferenceObj.type.selected =
preferenceValue.preference_option_value;
}

preferenceObj.type.options.push(
optionObj
);
}
if (
patientPreference.preferenceValueId ===
preferenceValue.preference_option_value
) {
preferenceObj.type.selected =
preferenceValue.preference_option_value;
}
);

patientObj.preferences.push(preferenceObj);
}
preferenceObj.type.options.push(optionObj);
}
});

patientObj.preferences.push(preferenceObj);
});

res.send(clean(patientObj));
Expand Down

0 comments on commit f7e7d32

Please sign in to comment.