Assalamualaikum ustaz. I have a question. What is the ruling of doing a swab test for Covid-19 whilst fasting? Does it invalidate fasting or not? I hope for an explanation from Ustaz.
Swab test or Covid-19 screening test using the method of Nasopharyngeal swab (through the nostril) and Oropharyngeal swab (through the throat) conducted whilst fasting does not invalidate fasting. This is because the swab test through both methods does not reach the inner cavity.
Screening, testing and verifying Covid-19 are divided into two types. The first is by Reverse Transcriptase Polymerase Chain Reaction (Rt-PCR). While the second is stated as Antigen Rapid Test (RTK Ag). Both tests are conducted by swabbing through the throat (Oropharyngeal swab) and through the nostril (Nasopharyngeal swab) . Both tests are conducted to detect the infection of the Covid-19 virus.
The Nasopharyngeal swab method is by inserting the swab into the nostrils of the individual until the nasopharynx area (the upper part of the pharynx, connecting with the nasal cavity above the soft palate) with the depth of approximately 4.8cm for adolescents and 8-12cm for adults to take mucus sample. While the method of Oropharyngeal swab is by inserting the swab into the mouth to the oropharynx area which is the back part of the roof of the mouth to take mucus sample.
Among the matters that may invalidate fasting is by inserting something into the open cavity through an open channel like the nose, ear, mouth, anus and private parts. Ibn al-Naqib al-Misri states:
وصولُ عينٍ وإنْ قلَّتْ منْ منفدٍ مفتوحٍ إلى جوفٍ
“(Among actions that invalidate one’s fasting are) the reaching of something into the cavity through an open channel even in small amount” 
Syeikh Zakariya al-Ansari said:
(فَرْعٌ يُفْطِرُ) الصَّائِمُ أَيْضًا (بِوُصُولِ عَيْنٍ) وَإِنْ قَلَّتْ كَسِمْسِمَةٍ وَلَمْ تُؤْكَلْ عَادَةً كَحَصَاةٍ (مِنْ الظَّاهِرِ فِي مَنْفَذٍ) بِفَتْحِ الْفَاءِ (مَفْتُوحٍ عَنْ قَصْدٍ) لِوُصُولِهَا (مَعَ ذِكْرِ الصَّوْمِ إلَى مَا يُسَمَّى جَوْفًا)
“Fasting is invalidated by the reaching of something even in a small amount like the sesame, even if something that enters is normally not eaten like small stones. In which it enters through an open cavity intentionally. This is because it reaches something which is called an open cavity.” 
The open cavity includes the ear, nose, mouth, anus and private parts. This is explained by Ibn al-Muqri’:
وَحُدِّدَ الظَّاهِرُ بِمَخْرَجِ الْحَاءِ الْمُهْمَلَةِ ثُمَّ دَاخِلُ الْفَمِ وَالْأَنْفِ إلَى مُنْتَهَى الْغَلْصَمَةِ وَالْخَيْشُومِ...
“The standard limit of internal part is at the makhraj of letter ha’, then into the mouth and nose reaching the end of the uvula and nostril cavity.” 
Hence, according to madhhab al-Shafi’e, whatever enters through the channel may invalidate one’s fasting. In addition, if the swab test procedure conducted enters far inside the nostril cavity, it may be considered invalidating one’s fasting. Sheikh Zakariya al-Ansari states on this matter:
(ثُمَّ أَلْحلَقَ وَمَا وَرَاءَ الْخَيَاشِيمِ) جَمْعُ خَيْشُومٍ وَهُوَ أَقْصَى الْأَنْفِ (جَوْفَانِ) فَالْوَاصِلُ إلَيْهِمَا مُفْطِرٌ
“Next is Adam’s apple and beside the nostril cavity which it is the upper part of the nose, is a cavity. Whatever enters into these two parts may cause his fasting invalidated.” 
This opinion is different from madhhab Maliki in which they are of the opinion that one’s fasting will only be invalidated if something enters the mouth cavity. Whatever enters other parts will not invalidate fasting as stated by Sheikh Abu Abdullah al-Maliki:
وَالْإِفْطَارُ بِمَا يَصِلُ إلَى الْجَوْفِ أَوْ الْمَعِدَةِ مِنْ الْفَمِ
“Fasting is invalidated when something enters the cavity or the stomach through the mouth.” 
Sheikh Abu al-Barakat al-Dardir also said:
وَأَمَّا غَيْرُ الْمَائِعِ فَلَا يُفْطِرُ إلَّا إذَا وَصَلَ لِلْمَعِدَةِ مِنْ الْفَمِ
“While other than liquid, it does not invalidate fasting unless if it reaches the stomach through the mouth.” 
Based on the decision of the 3rd Special Convention of Fatwa Council for Islamic Religious Affairs Malaysia (MKI), the council decided:
“Procedure of screening test to detect the infection of Covid-19 is by taking mucus sample in the nostril cavity reaching to the nasopharynx area (upper part of nostril cavity) and the mouth cavity reaching to the oropharynx area (uvula) does NOT INVALIDATE FASTING. This aligns with the decision of the 87th Convention of Fatwa Council for Islamic Religious Affairs Malaysia (MKI) held on 23rd to 25th June 2009 which convened on Fasting Guidelines for Sick People”.
Hence, swab test or screening test for Covid-19 using the method of Nasopharyngeal swab (through the nostril) and Oropharyngeal swab (through the throat) conducted whilst fasting does not invalidate fasting. This is because the swab test through both processes do not reach the inner cavity.
 Refer website My Health KKM through the link https://www.myhealth.ph/covid-19-test-now-available-at-myhealth/
 Ibn Al-Naqib, Ahmad Bin Lu’lu, ‘Umdah Al-Salik wa ‘Uddah Al-Nasik (1982), publisher Al-Syuun Al-Diniyah,Qatar, h.117.
 Al-Ansari, Zakariya Bin Muhammad, Asna Al-Matalib Syarh Raudh Al-Talib, Dar Al-Kitab Al-Islami, j. 1 h.415
 Ibn Al-Muqri’ , Ismail Bin Al-Muqri’, Raudh Al-Talib wa Nihayah Al-Matlab Al-Raghib(2013), Dar Al-Dhiya’, Kuwait, j. 1 h.335-336
 Abu Abdullah, Muhammad Bin Ahmad, Manh Al-Jalil Syarh Mukhtasar Al-Khalil (1989), Dar Al-Fikr, Beirut, j.2 h.137
 Abu Al-Barakat Al-Dardir, Ahmad Bin Muhammad, Aqrab Al-Masalik ila Mazhab Al-Imam Malik, Dar Al-Ma’arif, j.1 h.699.