RSS Git Download  Clone
Raw Blame History
<!-- BEGIN [% component.name %] -->
[%- #  (re)define request-specific vars - supports single or multiple requests:
    yy = data.year - 2000 | format('%02d');   
    text_str.amended_report = '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;

    # 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;
-%]
  <!-- container -->
  [% class = ['container' ]; class.push('printHide') UNLESS is_print_request %]
  <div class="[% class.join %]">
    <div class="row">
      <img src="/images/lcc_logo.jpg"/>
    </div>
 
    [% UNLESS is_print_request; INCLUDE record/report/navbar.tt; END %]

    <div class="row">
      [% IF has_optional.clinical_trial;
          trial_number = get_trial_number(patient.id, data.request_trial.trial_id) %]
          <h3 class="text-warning text-center">
              CLINICAL TRIAL: [% data.request_trial.trial.trial_name %]
              [% IF trial_number %][ [% trial_number %] ][% END %]
          </h3>
      [% END %]

      <div class="span2.5">
        [% INCLUDE record/report/patient.tt %]
      </div>
      
      [% class = is_print_request ? 'span8' : 'span7 offset1' # need to adjust for PDF view %]
      <div class="[% class %]">
        <div class="main-div">
          [% IF report; # PROCESS dumper.tt dump = report.as_tree %]
            <div class="diagnosis bright"><!-- style="white-space: nowrap" // doesn't scale with screen resolution -->
              [% IF have_secondary_diagnosis %]1.[% END %]
              [% # UNLESS special_formatting.skip_diagnosis # do we need to bother ? %]
                <span class="[% is_updated_diagnosis ? 'warning' : 'normal' %]">
                  [% report.diagnosis.name %]
                </span>
              [% # END %]
              [% IF want_icdo3 AND report.diagnosis.icdo3 # don't want it %]
                [[% report.diagnosis.icdo3 %]]
              [% END %]
              [% UNLESS is_print_request %]
                <sup>[% INCLUDE site/snippets/hmrn_info_link.tt %]</sup>
              [% END %]
            </div>
          [% ELSE %]
            <div class="diagnosis bright">[ REPORT PENDING AUTHORISATION ]</div>
          [% END %]
        
          [% IF have_secondary_diagnosis %]
            <div class="diagnosis bright">2.
              [% request_data.request_secondary_diagnosis.diagnosis.name %]
            </div>
          [% END %]
        
          <p class="indent">
            [% INCLUDE record/report/specimen.tt %]
          </p>

          [% # 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 %]              
              <p class="text-error">[% comment.join('<br />') %]</p>  
          [% 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;
          %]
            <ul>
              [% FOREACH entry IN context_warnings %]
                <li class="text-warning">[% entry %]</li>
              [% END %]
              [% FOREACH entry IN diagnosis_riders %]
                <li class="text-error">[% entry %]</li>
              [% END %]
            </ul>
          [% END %]
        </div>
        
        [% # additional comments:
          additional_comments = [];
          
          IF report AND NOT report.status.match('default');
              str = 'this is a ' _ report.status.upper _ ' diagnosis';
              additional_comments.push(str);
          END;

          IF outstanding_tests.size;
            additional_comments.push(text_str.tests_pending);
          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_amended_report;
            additional_comments.push(text_str.amended_report);
          END; 

          IF is_print_request; # print report or print run
            additional_comments.push(text_str.service_url);
          END;

          IF additional_comments.size;   
        %]
          <div class="comments">
            <ul>
              [% FOREACH entry IN additional_comments %]
                <li class="text-info">[% entry %]</li>
              [% END %]
            </ul>                   
          </div>
        [% END %]
      </div>
    </div>

    [% IF outreach.size; INCLUDE record/report/outreach.tt; END %]

    [% IF report AND ( report.morphology OR result_summaries.size );
        INCLUDE record/report/results.tt;
      ELSE # spacer: %]
        <p class="spacer"></p>
    [% 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) %]
            <a href="[% app_url %]/resources/user_messages/[% user.id %]">
              <span class="badge badge-bright"><i class="icon-user icon-white"></i></span>
            </a>
    [% END; END; END; %]
      <div class="row">
        <div class="row span7">
          <span class="rich">Reported by:
            <b>[% reporter.first_name | ucfirst %]</b>
            <b>[% reporter.last_name  | ucfirst %]</b>
          </span>
          on <b>[% history.reported.time.strftime('%a %d.%b.%Y @ %H:%M') %]</b>
          [% INCLUDE contact_user user = reporter %]
        </div>
        [% IF authoriser; # in case pre-2004 %]
        <div class="row span7">
          <span class="rich">Authorised by:
            <b>[% authoriser.first_name | ucfirst %]</b>
            <b>[% authoriser.last_name  | ucfirst %]</b>          
          </span>
          on <b>[% history.authorised.time.strftime('%a %d.%b.%Y @ %H:%M') %]</b>
          [% INCLUDE contact_user user = authoriser %]
        </div>
        [% END %]
      </div>
    [% END %]
    
    [% IF previous_diagnoses.size; # PROCESS dumper.tt dump = previous_diagnoses;
        BLOCK amended_report_update; # PROCESS dumper.tt dump = entry.as_tree %]
          <div class="row">
            <div class="row span8">
              <span class="rich">Amended report issued by:
                <b>[% entry.user.first_name | ucfirst %]</b>
                <b>[% entry.user.last_name  | ucfirst %]</b>
              </span>	
              on <b>[% entry.time.strftime('%a %d.%b.%Y') %]
              @ [% entry.time.strftime('%T').match('00:00:00') # for legacy data
                ? '??:??' : entry.time.strftime('%H:%M') %]</b>
              [% INCLUDE contact_user user = entry.user %]
            </div>
          </div>
        [% 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 %]
      <p class="spacer"></p>
      <div class="row">
        <div class="row span7">Report sent to:
            <ul>
                [% FOREACH report IN dispatch_log %]
                    <li>[% report.recipient %] on
                        [% report.time.strftime('%d.%b.%Y @ %H:%M') %]</li>
                [% END %]
            </ul>
        </div>
      </div>
    [% END %]

  </div>
  <!-- /container -->
<!-- END [% component.name %] -->