DISCUSSION "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].) 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 *Page 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). 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 thePeople 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 Asserting "it is inconceivable that the [Legislature 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 *Page 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 alsoIn 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 *Page 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." 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 *Page 1155 there is a "need to assist persons who are seriously injured or threatened with such injury." (BrighamCity 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.) (hereafterRay). 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 (cone. opn. of George, C. J.).) Three justices relied on the community caretaking exception. (Id. at pp. 473-780 (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 `[necessity 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 *Page 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.) ["`[necessity 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'"].) 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 theFourth Amendment to the United States Constitution. A contrary conclusion would mean that a state could circumvent the warrant requirement by intentionally or inadvertently limiting *Page 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 theFourth 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.