A Lawrence court officer has been charged with raping a female inmate three times in a courthouse while the victim’s legs were shackled.

Prosecutors allege Jose Martinez, 46, of 21 Amherst St., Lawrence, raped the woman when she was appearing in Lawrence District Court on various charges in July 2009, and again in September and October of 2014.

The victim told a New Hampshire prison worker about the alleged rapes in 2014, the Essex County District Attorney’s office said. A State Police investigation followed, which resulted in the charges.

Thursday, Martinez was arraigned on three counts of rape and four counts of indecent assault and battery.

Judge Richard Savignano ordered Martinez held on $40,000 bail. The judge ordered Martinez to stay away from Lawrence District Court – except for court appearances. Martinez was also ordered to have no contact with the victim and to surrender all firearms and licenses to carry firearms and ammunition.

Martinez is to return to court for a probable cause hearing on March 23.