[% # PROCESS dumper.tt dump = patient; # PROCESS dumper.tt dump = params; %] [% IF pds.size; # is_code_ref(pds_query).match('HASH') pds_return_codes = settings.patient_demographic_service.return_codes; IF pds.ErrorCode.match('SMSP-0000'); fields = [ 'last_name' 'first_name' 'middle_name' 'gender' 'dob' 'nhs_number' ]; USE format; zero_padded = format('%02d'); # ensure zero-padded for cmp patient_dob = [ params.year, zero_padded(params.month), params.day ]; is_validated = 1; %]

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

[% FOREACH field IN fields; a = pds.${field} | lower; # PROCESS dumper.tt dump = a; b = ( field == 'dob' ) ? patient_dob.join('-') : params.${field} | lower; # PROCESS dumper.tt dump = b; %] [% IF a != b # highlight it %] [% pds.item(field) || '[NULL]' %] [% ELSIF pds.${field}; pds.${field}; ELSE; NEXT; END # skip if empty %] [% ' :: ' IF loop.next # add separator unless end of array %] [% END %] [% IF pds.home_address; ' :: ' _ pds.home_address _ ', ' _ pds.post_code; END %]

[% IF NOT pds.demographics_verified %] Patient details do not match PDS entry. Please check your source. [% END %]
[% ELSE; # PDS returned a not-OK error code: error_code = pds.ErrorCode; error_str = pds_return_codes.${error_code}; # empty for a PDS timeout %]

PDS returned: [% error_code %] [[% error_str %]] [% IF error_code.match('DEMOG-000[17]') # no or multiple matches OR error_code.match('SMSP-0001'); # message validation error %] PLEASE CHECK ALL FIELDS AND RESUBMIT [% 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' : 'PDS cannot find a match or returns multiple matches'; %]

If [% message %], skip repeat PDS lookup:

[% END %] [% ELSE %]

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

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