// Builds complete user id
function build_home_id ($pcode_id, $assigned_id_no) {
//$cmplt_id = $pcode_id . "-" . number_pad($assigned_id_no,3); // Gets postcode string and calls the number padding function to add the leading0's
do {
$cmplt_id = $pcode_id . "-" . number_pad($assigned_id_no,3); // Gets postcode string and calls the number padding function to add the leading0's
$assigned_id_no++; // Increase assigned_id_no
$existing = get_page_by_title($cmplt_id, OBJECT, "patient");
$existing_post = $existing->post_title;
}
while($cmplt_id == $existing_post); // Restart loop if built id matches any already in existance
return $cmplt_id;
}