add function to get chartnumber from patid
adjust quiery to pull all data and use patid not chart as selector
adjust script to use patid not chart as selector