97:14 If the moon was visible at the beginning of the night before they started to daven maariv, if there are still several nights left in which one might yet sanctify it, they first daven maariv and sanctify the moon after. This is because when one has to perform a more frequently-occurring mitzvah and a less frequently-occurring mitzvah, the more frequently-occurring mitzvah comes first. Also, reciting the Shema is a Biblical obligation. However, if there isn’t much more time to sanctify the moon – only two or three nights – in such a short time there is concern that the moon may be covered by clouds. In the rainy season, even when there are another four nights time, there’s still concern that the moon may be blocked by clouds, so one should sanctify the moon first.
If one sees the moon while reciting Shema and its blessings, if the time is so short that the deadline for sanctifying the moon will pass before he can finish saying Shemoneh Esreh, he may even stop in the middle of the blessings of Shema or in the middle of Shema itself but if possible, he should finish the paragraph he is in and sanctify the moon in between paragraphs.
97:15 If the moon was not seen in the month of Adar until the night of the 14th, which is the time to read the megillah, one should first sanctify the moon and then read the megillah. If the moon is seen in the middle of reading the megillah, if it’s at a time that one will be able to finish the reading and sanctify the moon, we don’t interrupt reading the megillah. However, if by the time megillah reading is over, the deadline to sanctify the moon will have passed – that is, the whole congegration will still not have sanctified it – then megillah reading is stopped, the moon is sanctified, and megillah reading resumes. However, if only an individual hasn’t yet sanctified the moon – so that if he stops to do so, he will need to finish the megillah later by himself – he should not stop reading. This is because publicizing the miracle of Purim takes priority.