Skip to content

Commit

Permalink
Merge branch 'P2-903-Tracking-of-outcomes-achievements-against-target…
Browse files Browse the repository at this point in the history
…s' into dev
  • Loading branch information
xKeCo committed Nov 29, 2024
2 parents 5608893 + 440f476 commit c1708d6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class OutcomeIndicatorHomeComponent {
{ header: 'Expected target', key: 'expected_target', width: 22 },
{ header: 'Actual target achieved', key: 'actual_target_achieved', width: 30 },
{ header: 'Achieved status', key: 'achieved_status', width: 22 },
{ header: 'Reporting status', key: 'reporting_status', width: 22 }
{ header: 'Reporting status', key: 'reporting_status', width: 22 },
{ header: 'Narrative', key: 'indicator_achieved_narrative', width: 50 },
{ header: 'Supporting results', key: 'indicator_supporting_results', width: 60 }
];

const wscolsWPs = [
Expand All @@ -40,7 +42,9 @@ export class OutcomeIndicatorHomeComponent {
{ header: 'Expected target', key: 'expected_target', width: 22 },
{ header: 'Actual target achieved', key: 'actual_target_achieved', width: 30 },
{ header: 'Achieved status', key: 'achieved_status', width: 22 },
{ header: 'Reporting status', key: 'reporting_status', width: 22 }
{ header: 'Reporting status', key: 'reporting_status', width: 22 },
{ header: 'Narrative', key: 'indicator_achieved_narrative', width: 50 },
{ header: 'Supporting results', key: 'indicator_supporting_results', width: 60 }
];

this.exportTablesSE.exportOutcomesIndicatorsToExcel(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ export class ExportTablesService {
indicatorType = `${prefix} ${data.indicators[0]?.indicator_name}`;
}

const supportingResults = !data.indicators[0]?.indicator_supporting_results
? 'Not defined'
: data.indicators[0]?.indicator_supporting_results.map(item => `• ${item.result_type} ${item.result_code} - ${item.result_title}`).join('\n');

worksheet.addRow({
toc_result_title: data.toc_result_description ?? 'Not defined',
indicator_name: data.indicators[0]?.indicator_description ?? 'Not defined',
Expand All @@ -244,7 +248,9 @@ export class ExportTablesService {
achieved_status: this.outcomeIService.achievedStatus(data.indicators[0]?.indicator_target_value, data.indicators[0]?.indicator_achieved_value)
? 'Yes'
: 'No',
reporting_status: data.indicators[0]?.indicator_submission_status ? 'Submitted' : 'Editing'
reporting_status: data.indicators[0]?.indicator_submission_status ? 'Submitted' : 'Editing',
indicator_achieved_narrative: data.indicators[0]?.indicator_achieved_narrative ?? 'Not defined',
indicator_supporting_results: supportingResults
});
}

Expand All @@ -256,6 +262,9 @@ export class ExportTablesService {
const prefix = indicator.is_indicator_custom ? 'Custom - ' : 'Standard - ';
indicatorType = `${prefix} ${indicator.indicator_name}`;
}
const supportingResults = !indicator.indicator_supporting_results
? 'Not defined'
: indicator.indicator_supporting_results.map(item => `• ${item.result_type} ${item.result_code} - ${item.result_title}`).join('\n');

worksheet.addRow({
workpackage_name: `${data.workpackage_short_name}: ${data.workpackage_name}`,
Expand All @@ -265,7 +274,9 @@ export class ExportTablesService {
expected_target: indicator.indicator_target_value ?? 'Not defined',
actual_target_achieved: indicator.indicator_achieved_value ?? 'Not defined',
achieved_status: this.outcomeIService.achievedStatus(indicator.indicator_target_value, indicator.indicator_achieved_value) ? 'Yes' : 'No',
reporting_status: indicator.indicator_submission_status ? 'Submitted' : 'Editing'
reporting_status: indicator.indicator_submission_status ? 'Submitted' : 'Editing',
indicator_achieved_narrative: indicator.indicator_achieved_narrative ?? 'Not defined',
indicator_supporting_results: supportingResults
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export class ContributionToIndicatorsRepository extends Repository<ContributionT
const relationName = 'eoi';
const dataQuery = `
select ${this._getTocResultSubquery(relationName)} as eois
from prdb.clarisa_initiatives ci
left join Integration_information.toc_results ${relationName} on ${relationName}.is_active and ${relationName}.result_type = 3
from ${env.DB_NAME}.clarisa_initiatives ci
left join ${env.DB_TOC}.toc_results ${relationName} on ${relationName}.is_active and ${relationName}.result_type = 3
and ${relationName}.id_toc_initiative = ci.toc_id
right join prdb.\`version\` v on ${relationName}.phase = v.toc_pahse_id
right join ${env.DB_NAME}.\`version\` v on ${relationName}.phase = v.toc_pahse_id
and v.phase_year = 2024 and v.app_module_id = 1 and v.is_active = 1 and v.status = 1
where ci.official_code = ?
`;
Expand Down Expand Up @@ -97,7 +97,9 @@ export class ContributionToIndicatorsRepository extends Repository<ContributionT
when indicator_s.result_status_id = 3 then 1
else null
END
))
)),
"indicator_supporting_results", (${this._flattenedResultsQuery('oi.toc_result_indicator_id')}),
"indicator_achieved_narrative", cti.narrative_achieved_in_2024
))
from ${env.DB_TOC}.toc_results_indicators oi
left join ${env.DB_TOC}.toc_result_indicator_target trit
Expand All @@ -112,4 +114,69 @@ export class ContributionToIndicatorsRepository extends Repository<ContributionT
)
)`;
}

private _flattenedResultsQuery(tocId: string) {
return `
select json_arrayagg(json_object(
"contribution_id", contribution_id,
"is_active", is_active,
"result_id", result_id,
"result_code", result_code,
"result_title", result_title,
"phase_name", phase_name,
"phase_id", phase_id,
"result_type", result_type,
"result_submitter", result_submitter,
"result_status", result_status,
"result_creation_date", result_creation_date,
"original_linked_result_code", original_linked_result_code,
"original_linked_result_phase", original_linked_result_phase
))
from (
select main_ctir.id as contribution_id, main_ctir.is_active, main_r.id as result_id, main_r.result_code, main_r.title as result_title,
main_v.phase_name, main_v.id as phase_id, main_rt.name as result_type, main_ci.official_code as result_submitter,
main_rs.status_name as result_status, date_format(main_r.created_date, '%Y-%m-%d') as result_creation_date,
null as original_linked_result_code, null as original_linked_result_phase
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results outcomes on tri.toc_results_id = outcomes.id
right join ${env.DB_NAME}.results_toc_result rtr on rtr.toc_result_id = outcomes.id and rtr.is_active
left join ${env.DB_NAME}.result main_r on main_r.id = rtr.results_id and main_r.is_active
left join ${env.DB_NAME}.contribution_to_indicator_results main_ctir on main_ctir.result_id = main_r.id
left join ${env.DB_NAME}.\`version\` main_v on main_r.version_id = main_v.id
left join ${env.DB_NAME}.result_type main_rt on main_r.result_type_id = main_rt.id
left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id
and main_rbi.initiative_role_id = 1 and rtr.initiative_id = main_rbi.inititiative_id
left join ${env.DB_NAME}.clarisa_initiatives main_ci on main_ci.id = main_rbi.inititiative_id
left join ${env.DB_NAME}.result_status main_rs on main_rs.result_status_id = main_r.status_id
where tri.toc_result_indicator_id = ${tocId} and tri.is_active
union all
select linked_ctir.id as contribution_id, linked_ctir.is_active as is_active, linked_r.id as result_id,
linked_r.result_code as result_code, linked_r.title as result_title, linked_v.phase_name as phase_name,
linked_v.id as phase_id, linked_rt.name as result_type, linked_ci.official_code as result_submitter,
linked_rs.status_name as result_status, date_format(linked_r.created_date, '%Y-%m-%d') as result_creation_date,
original_results.result_code as original_linked_result_code, original_results.phase_id as original_linked_result_phase
from (
select main_r.id as result_id, main_r.result_code, main_r.version_id as phase_id
from ${env.DB_TOC}.toc_results_indicators tri
right join ${env.DB_TOC}.toc_results outcomes on tri.toc_results_id = outcomes.id
right join ${env.DB_NAME}.results_toc_result rtr on rtr.toc_result_id = outcomes.id and rtr.is_active
left join ${env.DB_NAME}.result main_r on main_r.id = rtr.results_id and main_r.is_active
left join ${env.DB_NAME}.results_by_inititiative main_rbi on main_rbi.result_id = main_r.id
and main_rbi.initiative_role_id = 1 and rtr.initiative_id = main_rbi.inititiative_id
where tri.toc_result_indicator_id = ${tocId} and tri.is_active
) as original_results
left join ${env.DB_NAME}.linked_result lr on lr.is_active and lr.origin_result_id = original_results.result_id
left join ${env.DB_NAME}.result linked_r on linked_r.id = lr.linked_results_id and linked_r.is_active
left join ${env.DB_NAME}.contribution_to_indicator_results linked_ctir on linked_ctir.result_id = linked_r.id
left join ${env.DB_NAME}.\`version\` linked_v on linked_r.version_id = linked_v.id
left join ${env.DB_NAME}.result_type linked_rt on linked_r.result_type_id = linked_rt.id
left join ${env.DB_NAME}.results_by_inititiative linked_rbi on linked_rbi.result_id = linked_r.id and linked_rbi.initiative_role_id = 1
left join ${env.DB_NAME}.clarisa_initiatives linked_ci on linked_ci.id = linked_rbi.inititiative_id
left join ${env.DB_NAME}.result_status linked_rs on linked_rs.result_status_id = linked_r.status_id
where linked_r.id is not null
) inner_q
`;
}
}

0 comments on commit c1708d6

Please sign in to comment.