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

Commit

Permalink
Merge f7e7d32 into c5708cf
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Jan 11, 2021
2 parents c5708cf + f7e7d32 commit d81e1b8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/routes/documents/register/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ const registerGetSchema = {
},
};

module.exports = registerGetSchema;
module.exports = { registerGetSchema };
2 changes: 1 addition & 1 deletion src/routes/healthcheck/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ const healthcheckGetSchema = {
},
};

module.exports = healthcheckGetSchema;
module.exports = { healthcheckGetSchema };
55 changes: 29 additions & 26 deletions src/routes/preferences/options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,53 +26,56 @@ async function route(server, options) {
})
);

const prefType = recordsets[0];
const prefList = recordsets[1];
const preferenceTypeOptions = recordsets[0];
const preferenceValueOptions = recordsets[1];

if (prefType && prefType.length !== 0) {
if (
preferenceTypeOptions &&
preferenceTypeOptions.length !== 0
) {
// Build patient object
const patientObj = {
preferences: [],
};

let priorityCount = 0;

// Build preference objects, merging in results from preference list query
prefType.forEach((element) => {
// Build preference objects, merging in results from preferenceValueOptions query
preferenceTypeOptions.forEach((preferenceType) => {
const preferenceObj = {
type: {
display: element.preference_type_display,
id: element.preference_type_id,
display: preferenceType.preference_type_display,
id: preferenceType.preference_type_id,
priority: priorityCount,
selected: 2,
options: [],
},
};

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

if (
preferenceValueOptions &&
preferenceValueOptions.length !== 0
) {
preferenceValueOptions.forEach(
(preferenceValue) => {
if (
element.preferenceValueId ===
option.preference_option_value
preferenceValue.preference_type_id ===
preferenceType.preference_type_id
) {
preferenceObj.type.selected =
option.preference_option_value;
}
const optionObj = {
display:
preferenceValue.preference_option_display,
value:
preferenceValue.preference_option_value,
};

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

patientObj.preferences.push(preferenceObj);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/preferences/options/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ const optionsGetSchema = {
},
};

module.exports = optionsGetSchema;
module.exports = { optionsGetSchema };
71 changes: 36 additions & 35 deletions src/routes/preferences/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,59 +29,60 @@ async function route(server, options) {
})
);

const prefType = recordsets[0];
const prefList = recordsets[1];
const patientPreferences = recordsets[0];
const patientPreferencesValues = recordsets[1];

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

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

// Build option objects to populate options array
if (prefList && prefList.length !== 0) {
prefList.forEach((option) => {
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 (
option.preference_type_id ===
element.preference_type_id
patientPreference.preferenceValueId ===
preferenceValue.preference_option_value
) {
const optionObj = {
display:
option.preference_option_display,
value: option.preference_option_value,
};

if (
element.preferenceValueId ===
option.preference_option_value
) {
preferenceObj.type.selected =
option.preference_option_value;
}

preferenceObj.type.options.push(optionObj);
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 Expand Up @@ -120,8 +121,8 @@ async function route(server, options) {
})
);

results.forEach((element) => {
if (element[0] !== 1) {
results.forEach((preferenceType) => {
if (preferenceType[0] !== 1) {
throw Error;
}
});
Expand Down

0 comments on commit d81e1b8

Please sign in to comment.