To add Python to the PID segment:
PID Segment Definition Window
PatientID = value;
Adding Python Code to the PatientObservation Table