A pharmacy, whether located in a retail environment or set up exclusively to provide supplies to a medical facility, has to follow certain rules. They are subject to pharmaceutical quality assurance protocols and they must also make sure they have well-trained staff and store drugs in a secure facility. The pharmacy is an old establishment, with the earliest being referred to as an apothecary for their one-stop-shop approach with spiritualism, herbalism and even medical treatments. They predate modern medicine, and have gradually evolved to a place where drugs are made to one where they are sold and dispensed.
The act of mixing a drug together to fit the needs of a patient is called compounding. Even though drugs are now typically purchased in useable form from the manufacturer, a pharmacist or pharmacy technician will still measure dosages and provide patients with additional instructions for consumption. Pharmacists must pay special attention to pharmaceutical quality training to make sure that not a single error slips through. Their education allows them to interpret the often cryptic seeming scribbles of a doctor, but if they are not sure they are trained to call. This is one of the reasons why a prescription pad includes the contact information of the doctor.
At a typical pharmacy, if it is retail establishment, a counter separates clients from the pharmacists. Customers drop off prescriptions they received from a doctor, and wait to pick up completed orders, either in provided seating or with shopping. If it's a refill they can even call in their order. Additional medicines, vitamins and medical appliances that do not need a prescription are available over the counter, but the pharmacist will also consult with clients to help them pick the best treatment. Whether prepackaged and over the counter or available only on a doctor's orders, every product with a medical purpose is subject to pharmaceutical quality assurance.
This means that it is rigorously tested and manufactured in a controlled facility. Most drugs need to be stored at exact temperatures, so one of the things pharmacists learn as part of pharmaceutical quality training is the necessary steps to keep the facilities clean and in compliance with regulations. Much how restaurant workers learn how to keep their work place hygienic in a food safety course, pharmacy programs
While drugs available on the shelves have safety seals to prevent tampering, the compounding and storage area will have reliable locks and security cameras. This helps insure pharmaceutical quality assurance protocols are maintained, but some motivation for this is because misuse of the contents of a pharmacy could be dangerous, but also because certain drugs cause a dependency. One of the roles of the pharmacist is to serve as a gatekeeper and make sure the products they sell are not misused.