You can see the expression used in the following routines
1) evaluation of angular part of function in spherical harmonics
eval_angular() in the file $NWCHEM_TOP/src/nwdft/xc/xc_eval_basis.F
2) as far as the integrals code is concerned, the directory
$NWCHEM_TOP/src/NWints/auxil has a few routines for the conversion
between spherical and cartesian