[%- # (re)define request-specific vars - supports single or multiple requests: yy = data.year - 2000 | format('%02d'); text_str.amended_report = 'this is an amended report' _ ' [supercedes any previous issued on' _ ' HMDS ref ' _ data.request_number _ '/' _ yy _ ']'; ref_time = status_options.authorised.is_active.match('yes') ? history.authorised.time : history.reported.time; # ref_time; is_gp = data.referrer_department.hospital_department_code.match('600') ? 1 : 0; # INCLUDE dumper.tt dump = has_optional; IF has_optional.report AND status_options.authorised.is_active.match('yes') AND NOT history.authorised.size # not authorised AND request_data.year > 2005; # eg Molecular Misc requests pre-2006 never auth'd # reset report: report = 0; # 'here'; END; # request_data = {}; # for testing have_secondary_diagnosis = request_data.request_secondary_diagnosis ? 1 : 0; is_amended_report = report.comment.match('[Aa]dditional [Cc]omment') ? 1 : 0; IF ref_time AND NOT is_amended_report; # date calcs need ref_time FOREACH d IN previous_diagnoses; # if diagnosis change > auth date: IF d.time.subtract_datetime(ref_time).delta_days > 0; is_amended_report = 1; is_updated_diagnosis = 1; # to flag on report LAST; END; END; UNLESS is_amended_report; # irrelevant if already set FOREACH entry IN result_summaries; # PROCESS dumper.tt dump = entry.value.time; NEXT UNLESS entry.value.time; # fatal in cmp if unset # if result summary updated AFTER authorisation date: IF entry.value.time.subtract_datetime(ref_time).delta_days > 0; is_amended_report = 1; LAST; END; END; END; # is_amended_report; END; BLOCK debug_delta_days; INCLUDE dumper.tt dump = [ ref_time.datetime, o.datetime, o.subtract_datetime(ref_time).delta_days ]; END; -%] [% class = ['container' ]; class.push('printHide') UNLESS is_print_request %]
[% banner = outreach ? 'outreach_logo.jpg' : c.cfg('settings').report_header %]
[% UNLESS is_print_request; INCLUDE record/report/navbar.tt; END %]
[% IF has_optional.clinical_trial; trial_number = get_trial_number(patient.id, data.request_trial.trial_id) %]

CLINICAL TRIAL [% data.request_trial.trial.trial_name %] [% IF trial_number %][ [% trial_number %] ][% END %]

[% ELSIF is_outreach # not large enough %]

Outreach

[% END %] [% # class = is_print_request ? 'span8' : 'span7 offset1' # need to adjust for PDF view # need to allow sufficient space for 'please use nhs number' & main-div # span2/min-width & span8/pull-right works OK for HTML & PDF %] [% min_width = 200; # span2.5 best on FF, but not official, and not supported by IE <8 %]
[% INCLUDE record/report/patient.tt %]
[% IF report; # PROCESS dumper.tt dump = report.as_tree %]
[% '1.' IF have_secondary_diagnosis; class = is_updated_diagnosis ? 'warning' : 'normal' -%] [% report.diagnosis.name %] [% IF report.diagnosis.icdo3 %] [[% report.diagnosis.icdo3 %]] [% END %] [% UNLESS is_print_request %] [% INCLUDE site/snippets/hmrn_info_link.tt diagnosis = request_data.request_report.diagnosis %] [% END %]
[% ELSE %]
[ REPORT PENDING AUTHORISATION ]
[% END %] [% IF have_secondary_diagnosis %]
2. [% request_data.request_secondary_diagnosis.diagnosis.name %] [% IF request_data.request_secondary_diagnosis.diagnosis.icdo3 %] [[% request_data.request_secondary_diagnosis.diagnosis.icdo3 %]] [% END %] [% UNLESS is_print_request %] [% INCLUDE site/snippets/hmrn_info_link.tt diagnosis = request_data.request_secondary_diagnosis.diagnosis %] [% END %]
[% END %]

[% INCLUDE record/report/specimen.tt %]

[% # report comment: IF report.comment; # PROCESS dumper.tt dump = report.comment; comment = []; UNLESS special_formatting.no_comment; formatted_comment = symbolise(report.comment).replace( '[Aa]dditional [Cc]omment','ADDITIONAL COMMENT') | html_line_break; # to split comment on full-stop: # re = '\.\s+'; # for legacy comment; keep space to retain decimal numbers # FOREACH line IN formatted_comment.split(re); # comment.push(line); # END; comment.push(formatted_comment); # if not splitting on '.' END; IF outreach; follow_opt_id = outreach.followup.followup_option_id; option = outreach.menu_options.followup_options.item(follow_opt_id).option; label = outreach.menu_options.followup_options.item(follow_opt_id).label; IF option.match('clinic_return'); comment.push(text_str.clinic_return); ELSIF option.match('zero'); str = text_str.pack_dispatch _ ' immediately.'; comment.push(str); ELSIF option.match('month'); str = text_str.pack_dispatch _ ' in ' _ label _ '.'; comment.push(str); END; END %]

[% comment.join('
') %]

[% END %] [% # context warnings: context_warnings = []; context_warning_map = report_data_maps.context_warning_map; IF report AND context_warning_map.size AND NOT outreach.size; warning = context_warning_map.item(report.diagnosis.id); IF warning; context_warnings.push(warning); END; END; IF specimen_map.item(data.id).description.grep('CSF').size AND report AND NOT report.diagnosis.icdo3.match('/3'); # non-ICDO3 + CSF context_warnings.push(text_str.csf); END; IF context_warnings.size; %]
    [% FOREACH entry IN context_warnings %]
  • [% entry %]
  • [% END %] [% FOREACH entry IN diagnosis_riders %]
  • [% entry %]
  • [% END %]
[% END %]
[% # additional comments: additional_comments = []; text_highlights = []; IF report AND NOT report.status.match('default'); str = 'this is a ' _ report.status.upper _ ' diagnosis'; text_highlights.push(str); END; IF is_amended_report; text_highlights.push(text_str.amended_report); END; IF outstanding_tests.size; str = text_str.tests_pending; sections = outstanding_tests.keys.join('; '); additional_comments.push(str _ ' [' _ sections.lower _ ']'); END; IF request_errors.size; # PROCESS dumper.tt dump = report_data_maps.report_error_codes; FOREACH entry IN request_errors; err_code = entry.error_code.code; # only want reportable errs: NEXT UNLESS report_data_maps.report_error_codes.item(err_code); str = report_data_maps.report_error_codes.item(err_code).description _ ' [' _ err_code.upper _ ']'; additional_comments.push(str); END; END; specimen = specimen_map.item(data.id).sample_code; IF specimen.grep('BMA').size AND NOT specimen.grep('PB').size AND NOT request_data.request_trial; additional_comments.push(text_str.pb_sample); END; IF is_print_request; # print report or print run additional_comments.push(text_str.service_url); END %] [% IF text_highlights.size OR additional_comments.size %]
    [% FOREACH entry IN text_highlights %]
  • [% entry %]
  • [% END %] [% FOREACH entry IN additional_comments %]
  • [% entry %]
  • [% END %]
[% END %]
[% IF outreach.size; INCLUDE record/report/outreach.tt; ELSIF is_gp %]
[% data.referrer_department.referrer.name || 'UNKNOWN' %], [% data.patient_case.referral_source.display_name | html %]
[% END %] [% IF report AND ( report.morphology OR result_summaries.size ); INCLUDE record/report/results.tt; ELSE # spacer: %]

[% END %] [% IF history.reported; reporter = history.reported.user; authoriser = history.authorised.user; users = []; # to avoid repeat user-contact icons BLOCK contact_user; UNLESS is_print_request; IF user.active.match('yes') AND NOT users.grep(user.username).size; users.push(user.username) %] [% END; END; END; %]
Reported by: [% reporter.first_name | ucfirst %] [% reporter.last_name | ucfirst %] on [% history.reported.time.strftime('%a %d.%b.%Y @ %H:%M') %] [% INCLUDE contact_user user = reporter %]
[% IF authoriser; # in case pre-2004 %]
Authorised by: [% authoriser.first_name | ucfirst %] [% authoriser.last_name | ucfirst %] on [% history.authorised.time.strftime('%a %d.%b.%Y @ %H:%M') %] [% INCLUDE contact_user user = authoriser %]
[% END %]
[% END %] [% IF previous_diagnoses.size; # PROCESS dumper.tt dump = previous_diagnoses; BLOCK amended_report_update; # PROCESS dumper.tt dump = entry.as_tree %]
Amended report issued by: [% entry.user.first_name | ucfirst %] [% entry.user.last_name | ucfirst %] on [% entry.time.strftime('%a %d.%b.%Y') %] @ [% entry.time.strftime('%T').match('00:00:00') # for legacy data ? '??:??' : entry.time.strftime('%H:%M') %] [% INCLUDE contact_user user = entry.user %]
[% END; IF ref_time;# or subtract_datetime dies FOREACH entry IN previous_diagnoses; # INCLUDE debug_delta_days o = entry.time; IF entry.time.subtract_datetime(ref_time).delta_days > 0; PROCESS amended_report_update; END; END; END; END; %] [% IF dispatch_log.size %]

Report sent to:
    [% FOREACH report IN dispatch_log %]
  • [% report.recipient %] on [% report.time.strftime('%d.%b.%Y @ %H:%M') %]
  • [% END %]
[% END %]