[% messages = c.messages('demographics'); # PROCESS dumper.tt dump = patient; # PROCESS dumper.tt dump = pds_query; # PROCESS dumper.tt dump = pds_codes; # PROCESS dumper.tt dump = c.query; %] [% IF is_code_ref(pds_query).match('HASH') %] [% IF pds_query.ErrorCode.match('SMSP-0000'); fields = [ 'last_name' 'first_name' 'middle_name' 'gender' 'dob' 'nhs_number' ]; %]

PDS query [% IF pds_query.demographics_verified %] [patient details verified] [% ELSE %] [patient details unverified] [% END %]

[% FOREACH field IN fields; a = pds_query.item(field) | lower; # PROCESS dumper.tt dump = a; b = ( field == 'dob' ) # string (new record) or DateTime object (existing): ? ( patient.dob.ymd || patient.dob ) # ymd will be empty if dob = str : patient.item(field) | lower; # PROCESS dumper.tt dump = b; %] [% IF a != b # highlight it %] [% pds_query.item(field) || '[NULL]' %] [% ELSIF pds_query.item(field); pds_query.item(field); ELSE; NEXT; END # skip if empty %] [% ' :: ' IF loop.next # add separator unless end of array %] [% END %] [% IF pds_query.home_address; ' :: ' _ pds_query.home_address _ ', ' _ pds_query.post_code; END %]

[% IF pds_query.demographics_verified # only relevant for _check_new_patient() %] [% ELSIF is_new_patient || is_patient_edit # flag from Patient::add_new() or :: update_patient() %]

Patient details do not match PDS entry. Please amend, or confirm details below are correct:

[% ELSE # have selected existing patient %]

Patient details do not match PDS entry. Do you need to edit selected patient?

[% END %]
[% ELSE; # PDS returned a not-OK error code: error_code = pds_query.ErrorCode; error_str = pds_codes.item(error_code); # empty for a PDS timeout %]

PDS returned: [% error_code %] [% error_str %] [% IF error_code.match('timeout') # LIMS error msg, not PDS error code %] GO » [% ELSIF error_code.match('DEMOG-000[17]'); # no or multiple matches IF patient.id; uri = patient.id; ELSE; params = []; FOREACH entry IN ['last_name' 'first_name' 'nhs_number' 'gender' 'unit_number' 'year' 'month' 'day' 'referral_source_id']; params.push(entry _ '=' _ patient.item(entry)); END; uri = '?' _ params.join(';'); # need leading '?' or entire str taken as id END; %] REFINE SEARCH » [% ELSIF error_code.match('SMSP-0001'); # message validation error %] PLEASE CHECK ALL FIELDS [% END %]

[% # allow PDS query override or no chance of registering if timeout or anon details: message = error_code.match('timeout') ? 'patient demographic service appears to be off-line' : 'this is an anonymised patient, or PDS cannot find a match'; %]

If [% message %], skip repeat PDS:

[% END %] [% ELSE %]

PDS did not return expected format: [% pds_query %]

[%# to break out of cycle %] [% END %]