(a) A juvenile board or local juvenile probation department shall establish a system that identifies children with mental illnesses or intellectual disabilities who are in the custody of the juvenile board or local juvenile probation department.
(b) Before a child who is identified as having a mental illness is discharged from the custody of the juvenile board or local juvenile probation department under Section 152.00163(b), the juvenile board or local juvenile probation department shall arrange for a psychiatrist to examine the child. The juvenile board or local juvenile probation department shall refer a child requiring outpatient psychiatric treatment to the appropriate mental health authority. For a child requiring inpatient psychiatric treatment, the juvenile board or local juvenile probation department shall file a sworn application for court-ordered mental health services, as provided in Subchapter C, Chapter 574, Health and Safety Code, if:
(1) the child is not receiving court-ordered mental health services; and
(2) the psychiatrist who examined the child determines that the child has a mental illness and the child meets at least one of the criteria listed in Section 574.034 or 574.0345, Health and Safety Code.
(c) Before a child who is identified as having an intellectual disability under Chapter 593, Health and Safety Code, is discharged from the custody of a juvenile board or local juvenile probation department under Section 152.00163(b), the department shall refer the child for intellectual disability services if the child is not receiving intellectual disability services.