
167 Cal.App.4th 1145 (2008)
THE PEOPLE, Plaintiff and Appellant,
v.
TRAVIS WYLIE SWEIG, Defendant and Respondent.
No. C057241.
Court of Appeals of California, Third District.
October 27, 2008.
*1149 Edmund G. Brown, Jr., Attorney General, Dane R. Gillette, Chief Assistant Attorney General, Michael P. Farrell, Assistant Attorney General, John G. McLean and Doris A. Calandra, Deputy Attorneys General, for Plaintiff and Appellant.
Aaron Williams for Defendant and Respondent.

OPINION
SCOTLAND, P. J.
This case illustrates a legislative oversight with regard to statutes intended to prevent persons with mental disorders from harming themselves or others.
(1) A person who is gravely disabled or a danger to others because of a mental disorder may be taken into custody and placed in a mental health facility "for 72-hour treatment and evaluation." (Welf. & Inst. Code, § 5150.) If, when detained, such a person "is found to own, have in his or her possession or under his or her control, any firearm whatsoever, or any other deadly weapon," it "shall be confiscated by any law enforcement agency or peace officer, who shall retain custody of the firearm or other deadly weapon." (Welf. & Inst. Code, § 8102, subd. (a).) When the person is released from custody, "the confiscating law enforcement agency shall have 30 days to initiate a petition in the superior court for a hearing to determine whether the return of a firearm or other deadly weapon would be likely to result in endangering the person or others...." (Welf. & Inst. Code, § 8102, subd. (c); further section references are to the Welf. & Inst. Code unless otherwise specified.)
The flaw in the statutes is that the legislative scheme does not provide a constitutionally permissible way for law enforcement to confiscate a firearm or other deadly weapon when it is in the residence of the mentally disordered person who is detained outside the residence and there is no exigent circumstance or other basis for a warrantless entry into the residence. Although section 8102 requires confiscation of the firearm or deadly weapon, the situation is not included as a ground for the issuance of a search warrant (Pen. Code, § 1524), and section 8102 does not contain a mechanism to seize the firearm or other deadly weapon in that circumstance.
In this case, officers detained defendant Travis Wylie Sweig outside his residence, as authorized by section 5150, then entered his residence to seize a rifle they had observed in his possession prior to the detention. In searching *1150 for other firearms or deadly weapons, officers found an unlawful assault weapon under defendant's bed. After defendant was charged with possession of the unlawful assault weapon (Pen. Code, § 12280, subd. (b)), the trial court granted defendant's motion to suppress the evidence. Concluding the seizure of the weapon was the product of a warrantless entry of defendant's residence in violation of the Fourth Amendment to the United States Constitution, the court dismissed the criminal case. The People appeal.
As we will explain, we reject the People's contention that the seizure of the assault rifle was justified by the "community caretaking exception" to the Fourth Amendment. (See People v. Ray (1999) 21 Cal.4th 464 [88 Cal.Rptr.2d 1, 981 P.2d 928] (lead opn. of Brown, J.).) We therefore shall affirm the judgment of dismissal, but suggest that the Legislature address the statutory flaw highlighted in this case.

FACTS
It is uncontested that when law enforcement officers took defendant into custody, he was suffering from a mental disorder that made him dangerous to himself or others (§ 5150) and the officers knew that he possessed a firearm (§ 8102).
The officers had responded to a 9-1-1 hangup call made from defendant's residence, a trailer, in a sparsely populated area of Shasta County. Defendant was on the porch holding a rifle. When told to put it down, he walked around the side of the trailer and soon came back without the rifle. He ran when advised that the officers needed to pat search him for their safety, but they grabbed him and put him in the backseat of a patrol vehicle. He then began to cooperate.
Defendant said that he had not eaten in two days and that he called 9-1-1 because people were harassing him by banging on the sides of the trailer and aiming laser lights at him, which emitted radiation that burned his skin. Defendant had fired a gun to make the people leave, but one of the harassers was still on the property. "There is one now with the flashlight," he said; however, officers did not see anyone. Based on prior contacts with defendant, the officers knew that he had made similar complaints in the past and that his mother and aunt had reported defendant engaging in bizarre behavior. According to his mother, defendant said the community, his family, and law enforcement had "done him wrong" and that if he was "pulled over by the cops" he "was going to take them out."
Concluding that defendant's mental state was deteriorating and he was a danger to himself or others, an officer told defendant he needed help. *1151 Defendant eventually agreed it would be in his best interest to go to the hospital for mental health treatment and evaluation. (§ 5150.)
While defendant was still in the backseat of a patrol vehicle, officers went into his trailer to confiscate the rifle they had seen him carrying and to search for other firearms. (§ 8102.) When an officer asked if defendant wanted to take anything with him for his personal comfort while detained, defendant said he wanted his bag with a video camera.
The officers found numerous firearms in the trailer. One, presumably the rifle, "was located in the kitchen area leaned up against the counter." Other firearms were in defendant's bedroom, including a semiautomatic assault rifle in a gun case under the bed.

DISCUSSION
(2) "The right of the people to be secure in their persons, houses, papers and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized." (U.S. Const., 4th Amend.) Therefore, absent exceptional circumstances in which a search warrant is not needed, a law enforcement officer "must obtain a warrant from a judicial officer before conducting a search or seizure" of a residence. (People v. Williams (1999) 20 Cal.4th 119, 125-126 [83 Cal.Rptr.2d 275, 973 P.2d 52].)
(3) A knowing and voluntary consent to search allows an officer to forgo obtaining a warrant. (Schneckloth v. Bustamonte (1973) 412 U.S. 218, 222 [36 L.Ed.2d 854, 860, 93 S.Ct. 2041]; People v. Superior Court (Walker) (2006) 143 Cal.App.4th 1183, 1198 [49 Cal.Rptr.3d 831].) And a warrant is not necessary when "exigent circumstances" exist, requiring swift action and leaving no time to obtain a warrant before entering a residence. (People v. Frye (1998) 18 Cal.4th 894, 989 [77 Cal.Rptr.2d 25, 959 P.2d 183].) Thus, a warrant need not be obtained when there is probable cause to believe the entry is justified by the hot pursuit of a fleeing felon, the imminent destruction of evidence, the need to prevent a suspect's escape, or the risk of danger to the police or other persons inside or outside the house. (Minnesota v. Olson (1990) 495 U.S. 91, 100 [109 L.Ed.2d 85, 95, 110 S.Ct. 1684]; People v. Thompson (2006) 38 Cal.4th 811, 818 [43 Cal.Rptr.3d 750, 135 P.3d 3]; People v. Celis (2004) 33 Cal.4th 667, 676 [16 Cal.Rptr.3d 85, 93 P.3d 1027].) A warrant also is not required when there is an imminent risk of serious damage to property. (People v. Frye, supra, 18 Cal.4th at p. 989.) And a warrant may not be needed when an emergency arises while officers "`are not engaged in crime-solving activities'" but are performing "`community *1152 caretaking functions,'" such as when officers are "`respond[ing] to requests of friends and relatives and others for assistance when people are concerned about the health, safety or welfare of their friend, loved ones and others.'" (People v. Ray, supra, 21 Cal.4th at pp. 471, 472 (lead opn. of Brown, J.).)
In this case, a search warrant could not have been obtained despite the legislative mandate (§ 8102) that law enforcement shall confiscate and retain custody of any firearm or other deadly weapon that is owned, possessed, or under the control of a person detained for mental health treatment and evaluation because the person is suffering from a mental disorder causing the person to be gravely disabled or dangerous to himself, herself, or others (§ 5150).
(4) When a mentally disordered person is detained outside of his or her residence pursuant to section 5150, law enforcement cannot get a search warrant to confiscate a firearm or other deadly weapon inside the residence because, as the People acknowledge on appeal, the situation specified in section 8102, without more, does not fall within the limited grounds set forth in Penal Code section 1524 for the issuance of search warrants.[1]
(5) Asserting "it is inconceivable that the [L]egislature would place a mandatory duty on officers to seize weapons but not impliedly incorporate a necessary means to effect the mandate," the People ask us to read into section 8102 the authority for a warrantless entry into a residence to fulfill the mandate of that section. We must resist the temptation because the limited role of courts in interpreting a statute does not include rewriting it to achieve *1153 a result that is not provided for in the statute or in other legislation. (California Teachers Assn. v. Governing Bd. of Rialto Unified School Dist. (1997) 14 Cal.4th 627, 633 [59 Cal.Rptr.2d 671, 927 P.2d 1175] [courts have "`no power to rewrite the statute so as to make it conform to a presumed intention which is not expressed'"].) This is so even when the omission is an obvious oversight. "[I]f there is a flaw in the statutory scheme, it is up to the Legislature, not the courts, to correct it." (Neighbours v. Buzz Oates Enterprises (1990) 217 Cal.App.3d 325, 334 [265 Cal.Rptr. 788]; see also In re Brent F. (2005) 130 Cal.App.4th 1124, 1130 [30 Cal.Rptr.3d 833]; People v. Hunt (1999) 74 Cal.App.4th 939, 948 [88 Cal.Rptr.2d 524]; In re Marriage of Fisk (1992) 2 Cal.App.4th 1698, 1702 [4 Cal.Rptr.2d 95].)
Nothing in the language of section 8102 can be read to authorize the warrantless entry into a residence to comply with the statute's mandate. Other than the directive to confiscate and retain custody of a firearm or other deadly weapon, the remainder of section 8102 simply sets forth procedures that govern the return of the firearm or other deadly weapon to the person after his or her release from custody for mental health treatment and evaluation, or its forfeiture if returning it to the person would be likely to endanger the person or others. (§ 8102, subds. (b)-(g).) We will not, as the People ask, incorporate into section 8102, by inference, the authority for a warrantless entry to comply with its mandate. Indeed, a statute cannot strip a mentally disordered person, detained pursuant to section 5150, of the Fourth Amendment right against a warrantless entry into his or her residence, unless justified by exceptional circumstances recognized by courts.
Thus, to permit, pursuant to section 8102, the confiscation of firearms or other deadly weapons in the residence of a mentally disordered person detained outside pursuant to section 5150, the Legislature should have authorized the issuance of a search warrant to do so (by amending Pen. Code, § 1524) or created guidelines for a "constitutionally adequate substitute for a warrant." (See, e.g., Donovan v. Dewey (1981) 452 U.S. 594, 603 [69 L.Ed.2d 262, 272, 101 S.Ct. 2534].) It did not do so.
Consequently, the officers' entry into defendant's residence to confiscate the rifle and any other firearms or other deadly weapons was unlawful unless it fell within an exception to the warrant requirement.
In the trial court, the People did not argue the warrantless entry into defendant's residence was justified by the traditional exigent circumstances exception to the warrant requirement. This is understandable because defendant was in the locked backseat of the patrol car, and there was no cause to believe that anyone else was in the residence who either was at risk of imminent bodily harm or could prevent the officersif they did not act *1154 immediatelyfrom being able to confiscate the rifle and any other firearms or other deadly weapons that might be in the residence. And the People did not attempt to justify the warrantless entry based on a claim that defendant consented to it.[2]
The sole ground offered by the People in the trial court to justify the warrantless entry into defendant's residence was the "community caretaking function" exception to the requirement that law enforcement have a warrant, signed by a judicial officer, authorizing entry into a residence. The People's position was that "for the safety of the defendant and the community," the officers "were obliged by section 8102 to seize any firearms owned by or in the defendant's immediate physical proximity or control"; therefore, entering defendant's residence to do so was a community caretaking function not "motivated by a desire to investigate a crime to prosecute [defendant]" but for the "reasonable" purpose of "securing" defendant's "safety, the safety of his family, the safety of his neighbors."
(6) The community caretaking exception recognizes law enforcement officers perform many community functions apart from investigating crime. They are "expected to aid those in distress, combat actual hazards, prevent potential hazards from materializing, and provide an infinite variety of services to preserve and protect community safety." (U.S. v. Rodriguez-Morales (1st Cir. 1991) 929 F.2d 780, 784-785.) For example, the community caretaking function encompasses law enforcement's authority to remove vehicles that impede traffic or threaten public safety and to inventory the contents of impounded vehicles. (See South Dakota v. Opperman (1976) 428 U.S. 364, 368-372 [49 L.Ed.2d 1000, 1005-1007, 96 S.Ct. 3092].) The search warrant requirement is also obviated under the emergency aid doctrine, a subcategory of the community caretaking doctrine that applies where *1155 there is a "need to assist persons who are seriously injured or threatened with such injury." (Brigham City v. Stuart (2006) 547 U.S. 398, 403 [164 L.Ed.2d 650, 657, 126 S.Ct. 1943]; see U.S. v. Snipe (9th Cir. 2008) 515 F.3d 947, 951-952; U.S. v. Stafford (9th Cir. 2005) 416 F.3d 1068, 1073.)
The People rely on an aspect of the community caretaking function addressed in People v. Ray, supra, 21 Cal.4th 464 (lead opn. of Brown, J.) (hereafter Ray). There, officers responded to a neighbor's report that the door to a residence had been open all day long and that the interior of the home was in shambles. The officers entered to perform a security check after no one responded to their repeated knocking on the front door. While performing the check, which did not involve opening any interior doors or containers, the officers observed contraband in plain view. The observations provided the basis for obtaining a search warrant. (Id. at p. 478.)
The California Supreme Court concluded the warrantless entry was lawful, but split on the theory. Three justices found exigent circumstances applied because the officers had reason to believe a burglary was in progress or had been committed and there might be a person inside who needed assistance. (Ray, supra, 21 Cal.4th at pp. 480-482 (conc. opn. of George, C. J.).) Three justices relied on the community caretaking exception. (Id. at pp. 473-480 (lead opn. of Brown, J.).)
The lead opinion concluded the People had not met their burden of establishing the emergency aid subcategory of the community caretaking exception, but the exception nonetheless applied. (Ray, supra, 21 Cal.4th. at pp. 472-473, 478 (lead opn. of Brown, J.).) "Under the community caretaking exception, circumstances short of a perceived emergency may justify a warrantless entry, including the protection of property, as `where the police reasonably believe that the premises have recently been or are being burglarized.' [Citation.]" (Id. at p. 473.) "Although this court has not articulated these principles in terms of `community caretaking functions,' it has long recognized that `[n]ecessity often justifies an action which would otherwise constitute a trespass, as where the act is prompted by the motive of preserving life or property and reasonably appears to the actor to be necessary for that purpose. [Citations.]' [Citation.]" (Id. at p. 473.) After reviewing other states' case law in accord with these principles, the lead opinion concluded, "[t]he appropriate standard under the community caretaking exception is one of reasonableness: Given the known facts, would a prudent and reasonable officer have perceived a need to act in the proper discharge of his or her community caretaking functions?" (Id. at pp. 476-477.)
Applying its discussion of the law to the facts of that case, the lead opinion declared: "While the facts known to the officers may not have established *1156 exigent circumstances or the apparent need to render emergency aid, they warranted further inquiry to resolve the possibility someone inside required assistance or property needed protection. In such circumstances, `entering the premises was the only practical means of determining whether there was anyone inside in need of assistance [or property in need of protection].' [Citations.]" (Ray, supra, 21 Cal.4th at p. 478 (lead opn. of Brown, J.).)[3]
Here, the People assert that under the community caretaking exception, the officers' warrantless entry into defendant's residence to seize his weapons pursuant to the mandate of section 8102 did not violate his Fourth Amendment rights. We are not persuaded.
As we understand the community caretaking exception, there must be some necessity for a warrantless entry into a residence to fulfill a purpose of the exception. (Ray, supra, 21 Cal.4th at p. 473 (lead opn. of Brown, J.) ["`[n]ecessity often justifies an action which would otherwise constitute a trespass, as where the act is prompted by the motive of preserving life or property and reasonably appears to the actor to be necessary for that purpose'"].)
(7) In this case, defendant lived alone in a sparsely populated rural area. He was detained outside the residence and placed in a patrol car for transportation to a mental health facility where he would be held in custody for a minimum of 72 hours (§ 5150). Nothing suggested to the officers that it was necessary for them to make a warrantless entry into the residence to confiscate the rifle and additional firearms or other deadly weapons, rather than seek a warrant to do so.
Although it turns out that the officers could not have obtained a search warrant (a legal conclusion no doubt unknown to them at the time), this flaw in the statutory scheme does not, in our view, constitute a "necessity" for action that would otherwise violate the Fourth Amendment to the United States Constitution. A contrary conclusion would mean that a state could circumvent the warrant requirement by intentionally or inadvertently limiting *1157 the situations for issuance of a warrant, and then asserting that those limitations create a necessity for a warrantless entry to fulfill a community caretaking function.
We cannot ignore the warrant requirement of the Fourth Amendment simply because there is a flaw in California's statutory scheme for search warrants. Therefore, we conclude, the circumstances in this case did not give rise to an exception to the warrant requirement of the Fourth Amendment.

DISPOSITION
The trial court's orders granting the suppression motion and dismissing the case are affirmed.
Nicholson, J., and Raye, J., concurred.
NOTES
[1]  Penal Code section 1524 states: "(a) A search warrant may be issued upon any of the following grounds: [¶] (1) When the property was stolen or embezzled. [¶] (2) When the property or things were used as the means of committing a felony. [¶] (3) When the property or things are in the possession of any person with the intent to use them as a means of committing a public offense, or in the possession of another to whom he or she may have delivered them for the purpose of concealing them or preventing them from being discovered. [¶] (4) When the property or things to be seized consist of any item or constitute any evidence that tends to show a felony has been committed, or tends to show that a particular person has committed a felony. [¶] (5) When the property or things to be seized consist of evidence that tends to show that sexual exploitation of a child, in violation of Section 311.3, or possession of matter depicting sexual conduct of a person under the age of 18 years, in violation of Section 311.11, has occurred or is occurring. [¶] (6) When there is a warrant to arrest a person. [¶] (7) When a provider of electronic communication service or remote computing service has records or evidence, as specified in Section 1524.3, showing that property was stolen or embezzled constituting a misdemeanor, or that property or things are in the possession of any person with the intent to use them as a means of committing a misdemeanor public offense, or in the possession of another to whom he or she may have delivered them for the purpose of concealing them or preventing their discovery. [¶] (8) When the property or things to be seized include an item or any evidence that tends to show a violation of Section 3700.5 of the Labor Code, or tends to show that a particular person has violated Section 3700.5 of the Labor Code."
[2]  On appeal, the People contend that defendant consented to the entry when, in responding to an officer's question whether he wanted to take anything with him while he was being detained for mental heath treatment and evaluation, defendant asked the officer to bring him his video bag. In the People's view, it is appropriate to raise this theory for the first time on appeal because, they believe, "the record is complete as to the facts and the only issue left to be resolved is a legal one." (Citing People v. Watkins (1994) 26 Cal.App.4th 19, 30-31 [31 Cal.Rptr.2d 452] [the general rule that the People may not rely on a new theory on appeal "does not apply `where there does not appear to be any further evidence that could have been introduced to defeat the theory in the trial court and therefore the question of application of the new ground to a given set of facts is a question of law'"].) We disagree. Because the theory was not raised in the trial court, defendant was deprived of the opportunity to present relevant evidence at his disposal. For example, the officer was uncertain whether his question to defendant occurred before or after the search of the residence. If defendant had notice of the consent theory, he may have been able to introduce evidence that the search had already begun before he responded to the officer's question; or that he simply acquiesced in what he understood to be an entry over which he had no control and, thus, he did not voluntarily consent; or that given his mental condition, he was unable to validly consent to the entry.
[3]  The lead opinion distinguished the exigent circumstances exception from the community caretaking exception as follows: "`When the police act pursuant to the exigent circumstances exception, they are searching for evidence or perpetrators of a crime. Accordingly, in addition to showing the existence of an emergency leaving no time for a warrant, they must also possess probable cause that the premises to be searched contains such evidence or suspects. [Citations.] In contrast, the community caretaker exception is only invoked when the police are not engaged in crime-solving activities.' [Citations.] With respect to Fourth Amendment guaranties, this is the key distinction: `[T]he defining characteristic of community caretaking functions is that they are totally unrelated to the criminal investigation duties of the police.'" (Ray, supra, 21 Cal.4th. at p. 471 (lead opn. of Brown, J.).)
