Z codes are for use in any healthcare setting. Z codes may be used as either a first-listed (principal diagnosis code in the inpatient setting) or secondary code, depending on the circumstances of the encounter.