Class ObjectScript.Lookup2
{
/// lookup names in these forms: Smith; Smith,John; Smith,J; Sm,John; Sm,J
ClassMethod Name(name as %String)
{
set count = 0
set last = $piece(name, ",", 1), first = $piece(name, ",", 2)
// last may be an exact match, so find preceding last name
set ln = $order(^PersonI("Name", last), -1)
// loop through last names
for {
set ln = $order(^PersonI("Name", ln))
// quit as soon as last name doesn't match original
quit:($extract(ln, 1, $length(last)) '= last)
// first may be "". Otherwise, it may be an exact match, so find preceding first name
if (first = "") {set fn = ""}
else { set fn = $order(^PersonI("Name", ln, first), -1)}
// loop through first names
for {
set fn = $order(^PersonI("Name", ln, fn))
// quit as soon as first name doesn't match original, or is ""
quit:(($extract(fn, 1, $length(first)) '= first) || (fn = ""))
set id = ""
// loop through all IDs
for {
set id = $order(^PersonI("Name", ln, fn, id))
quit:(id = "")
write:(count = 0) "...finding name matches"
set count = count + 1
write !, count, ") "
do ..DisplayLine(id)
}
}
}
if (count = 0) {write "...no matches"}
}
}