Any person detained pursuant to this subchapter is entitled to the writ of habeas corpus, upon proper petition by himself or by a friend to any justice generally empowered to issue the writ of habeas corpus in the county in which the person is detained. [1983, c. 459, §7 (NEW).]