Skip to content

Commit

Permalink
Missing heiarchy fix (#44)
Browse files Browse the repository at this point in the history
Optional chaining and ternary statments used to solve missing heiarhcy issue

Signed-off-by: Courtney Gosselin <[email protected]>

Co-authored-by: Courtney Gosselin <[email protected]>
  • Loading branch information
CourtneyGosselin and Courtney Gosselin authored Jun 7, 2022
1 parent 2a180e0 commit abd7692
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 50 deletions.
76 changes: 40 additions & 36 deletions src/store/mcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ export const medicationStatementColumns = [
export const processMCodeMainData = (dataObject) => {
const row = {};

row.id = dataObject.id || null;
row.sex = dataObject.subject.sex || 'NA';
row.ethnicity = dataObject.subject.ethnicity || 'NA';
row.date_of_birth = dataObject.subject.date_of_birth || 'NA';
row.date_of_death = dataObject.date_of_death || 'NA';
row.race = dataObject.subject.race || 'NA';
row.communication_language = dataObject.subject.extra_properties.communication_language || 'NA';
row.id = dataObject?.id ? dataObject?.id : null;
row.sex = dataObject?.subject?.sex ? dataObject?.subject?.sex : 'NA';
row.ethnicity = dataObject?.subject?.ethnicity ? dataObject?.subject?.ethnicity : 'NA';
row.date_of_birth = dataObject?.subject?.date_of_birth ? dataObject?.subject?.date_of_birth : 'NA';
row.date_of_death = dataObject?.date_of_death ? dataObject?.date_of_death : 'NA';
row.race = dataObject?.subject?.race ? dataObject?.subject?.race : 'NA';
row.communication_language = dataObject?.subject?.extra_properties?.communication_language
? dataObject?.subject?.extra_properties?.communication_language
: 'NA';

return row;
};
Expand All @@ -194,13 +196,15 @@ export const processMCodeMainData = (dataObject) => {
*/
export const processSubjectData = (dataObject) => {
const row = {};
row.id = dataObject.id || null;
row.sex = dataObject.subject.sex || 'NA';
row.date_of_birth = dataObject.subject.date_of_birth || 'NA';
row.date_of_death = dataObject.date_of_death || 'NA';
row.ethnicity = dataObject.subject.ethnicity || 'NA';
row.race = dataObject.subject.race || 'NA';
row.communication_language = dataObject.subject.extra_properties.communication_language || 'NA';
row.id = dataObject?.id ? dataObject?.id : null;
row.sex = dataObject?.subject?.sex ? dataObject?.subject?.sex : 'NA';
row.date_of_birth = dataObject?.subject?.date_of_birth ? dataObject?.subject?.date_of_birth : 'NA';
row.date_of_death = dataObject?.date_of_death ? dataObject?.date_of_death : 'NA';
row.ethnicity = dataObject?.subject?.ethnicity ? dataObject?.subject?.ethnicity : 'NA';
row.race = dataObject?.subject?.race ? dataObject?.subject?.race : 'NA';
row.communication_language = dataObject?.subject?.extra_properties?.communication_language
? dataObject?.subject?.extra_properties?.communication_language
: 'NA';

return [row];
};
Expand All @@ -214,14 +218,14 @@ export const processConditionsData = (dataObject) => {
const rows = [];

// eslint-disable-next-line camelcase
dataObject.cancer_condition.forEach((cancer_condition) => {
dataObject?.cancer_condition.forEach((cancer_condition) => {
const row = {};
row.id = cancer_condition.id || null;
row.id = cancer_condition?.id || null;
if (row.id !== null) {
row.condition_type = cancer_condition.condition_type || 'NA';
row.code_id = cancer_condition.code.id || 'NA';
row.code_label = cancer_condition.code.label || 'NA';
row.date_of_diagnosis = cancer_condition.date_of_diagnosis || 'NA';
row.condition_type = cancer_condition?.condition_type ? cancer_condition?.condition_type : 'NA';
row.code_id = cancer_condition?.code?.id ? cancer_condition?.code?.id : 'NA';
row.code_label = cancer_condition?.code?.label ? cancer_condition?.code?.label : 'NA';
row.date_of_diagnosis = cancer_condition?.date_of_diagnosis ? cancer_condition?.date_of_diagnosis : 'NA';

rows.push(row);
}
Expand All @@ -243,11 +247,11 @@ export const processProceduresData = (dataObject) => {
const row = {};
row.id = cancer_related_procedure.id || null;
if (row.id !== null) {
row.procedure_type = cancer_related_procedure.procedure_type || 'NA';
row.procedure_code_id = cancer_related_procedure.code.id || 'NA';
row.procedure_code_label = cancer_related_procedure.code.label || 'NA';
row.body_site_id = cancer_related_procedure.body_site.id || 'NA';
row.body_site_label = cancer_related_procedure.body_site.label || 'NA';
row.procedure_type = cancer_related_procedure?.procedure_type ? cancer_related_procedure?.procedure_type : 'NA';
row.procedure_code_id = cancer_related_procedure?.code?.id ? cancer_related_procedure?.code?.id : 'NA';
row.procedure_code_label = cancer_related_procedure?.code?.label ? cancer_related_procedure?.code?.label : 'NA';
row.body_site_id = cancer_related_procedure?.body_site?.id ? cancer_related_procedure?.body_site?.id : 'NA';
row.body_site_label = cancer_related_procedure?.body_site?.label ? cancer_related_procedure?.body_site?.label : 'NA';

rows.push(row);
}
Expand All @@ -269,8 +273,8 @@ export const processMedicationStatementData = (dataObject) => {
const row = {};
row.id = medication_statement.id || null;
if (row.id !== null) {
row.medication_code_id = medication_statement.medication_code.id || 'NA';
row.medication_code_label = medication_statement.medication_code.label || 'NA';
row.medication_code_id = medication_statement?.medication_code?.id ? medication_statement?.medication_code?.id : 'NA';
row.medication_code_label = medication_statement?.medication_code?.label ? medication_statement?.medication_code?.label : 'NA';

rows.push(row);
}
Expand All @@ -287,10 +291,10 @@ export const processMedicationStatementData = (dataObject) => {
export const processMedicationListData = (dataObject) => {
const list = {};
dataObject.forEach((patient) => {
patient.medication_statement.forEach((medication) => {
const key = medication.medication_code.id;
patient?.medication_statement.forEach((medication) => {
const key = medication?.medication_code?.id;
if (!(key in list)) {
list[key] = medication.medication_code.label;
list[key] = medication?.medication_code?.label;
}
});
});
Expand All @@ -306,10 +310,10 @@ export const processMedicationListData = (dataObject) => {
export const processCondtionsListData = (dataObject) => {
const list = {};
dataObject.forEach((patient) => {
patient.cancer_condition.forEach((condition) => {
const key = condition.code.id;
patient?.cancer_condition.forEach((condition) => {
const key = condition?.code?.id;
if (!(key in list)) {
list[key] = condition.code.label;
list[key] = condition?.code?.label;
}
});
});
Expand All @@ -325,10 +329,10 @@ export const processCondtionsListData = (dataObject) => {
export const processProceduresListData = (dataObject) => {
const list = {};
dataObject.forEach((patient) => {
patient.cancer_related_procedures.forEach((procedure) => {
const key = procedure.code.id;
patient?.cancer_related_procedures.forEach((procedure) => {
const key = procedure?.code?.id;
if (!(key in list)) {
list[key] = procedure.procedure_type;
list[key] = procedure?.procedure_type;
}
});
});
Expand Down
29 changes: 15 additions & 14 deletions src/views/clinical/mcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,19 @@ function MCodeView() {

setSelectedPatient(mcodeData.results[index].id);
setSelectedPatientMobileInfo({
Ethnicity: mcodeData.results[index].subject.ethnicity,
Sex: mcodeData.results[index].subject.sex,
Birthday: mcodeData.results[index].subject.date_of_birth,
DeathDate: mcodeData.results[index].date_of_death,
Language: mcodeData.results[index].subject.extra_properties.communication_language
Ethnicity: mcodeData?.results[index]?.subject?.ethnicity ? mcodeData?.results[index]?.subject?.ethnicity : 'NA',
Sex: mcodeData?.results[index]?.subject?.sex ? mcodeData?.results[index]?.subject?.sex : 'NA',
Birthday: mcodeData?.results[index]?.subject?.date_of_birth ? mcodeData?.results[index]?.subject?.date_of_birth : 'NA',
DeathDate: mcodeData?.results[index]?.date_of_death ? mcodeData?.results[index]?.date_of_death : 'NA',
Language: mcodeData?.results[index]?.subject?.extra_properties?.communication_language
? mcodeData?.results[index]?.subject?.extra_properties?.communication_language
: 'NA'
});

// Subtables
setCancerConditions(processConditionsData(mcodeData.results[index]));
setProcedures(processProceduresData(mcodeData.results[index]));
setMedicationStatement(processMedicationStatementData(mcodeData.results[index]));
setCancerConditions(processConditionsData(mcodeData?.results[index]));
setProcedures(processProceduresData(mcodeData?.results[index]));
setMedicationStatement(processMedicationStatementData(mcodeData?.results[index]));
setListOpen(false);
};

Expand All @@ -133,7 +135,6 @@ function MCodeView() {
trackPromise(
fetchKatsu('/api/mcodepackets').then((data) => {
setMcodeData(data);

const tempRows = [];
for (let i = 0; i < data.results.length; i += 1) {
// Patient table filtering
Expand Down Expand Up @@ -183,11 +184,11 @@ function MCodeView() {
if (tempRows[0].id !== null) {
setSelectedPatient(tempRows[0].id);
setSelectedPatientMobileInfo({
Ethnicity: tempRows[0].ethnicity,
Sex: tempRows[0].sex,
Birthday: tempRows[0].date_of_birth,
DeathDate: tempRows[0].date_of_death,
Language: tempRows[0].communication_language
Ethnicity: tempRows[0]?.ethnicity ? tempRows[0]?.ethnicity : 'NA',
Sex: tempRows[0]?.sex ? tempRows[0]?.sex : 'NA',
Birthday: tempRows[0]?.date_of_birth ? tempRows[0]?.date_of_birth : 'NA',
DeathDate: tempRows[0]?.date_of_death ? tempRows[0]?.date_of_death : 'NA',
Language: tempRows[0]?.communication_language ? tempRows[0]?.communication_language : 'NA'
});
}

Expand Down

0 comments on commit abd7692

Please sign in to comment.