Maedot Pharmacy
Transforming Pharmacy Operations: A Solo Endeavor This project represents a solo build for a real client, currently active in production. It began with absolutely no prior digital infrastructure, requiring a complete, ground-up architectural solution. The Client Reality Before this system, the pharmacy operated with a purely paper-based inventory. This led to significant challenges: expired stock often went unnoticed, leading to waste, and the administrative overhead of manual tracking consumed hours daily. Imagine the constant risk of stockouts and the sheer manual effort involved in managing patient records and prescriptions without a digital backbone. 💡 Architecting a system solo where real patients depend on the outcome demands a profound sense of responsibility and meticulous attention to detail at every stage. The System Inventory Engine At the core of the inventory management is a robust engine leveraging atomic operations within Prisma. This is crucial for handling concurrent stock mutations. By using atomic operations, we prevent race conditions where multiple requests attempting to update the same stock item simultaneously could lead to inconsistent or incorrect inventory counts. This ensures data integrity even under heavy load. Stock Alert System To combat stockouts, a SKU-level threshold monitoring system was implemented. When a stock level hits its predefined threshold, a real-time alert is pushed via WebSockets directly to the relevant user role (e.g., inventory manager). WebSockets were chosen over traditional polling because they provide immediate, bidirectional communication, ensuring that staff are notified the instant a critical stock level is reached, rather than relying on periodic checks. Expiration Tracking A batch-level schema was designed to meticulously track expiration dates. A scheduled job runs regularly to identify and flag items nearing expiration. Since the implementation of this feature, the pharmacy has experienced near-zero losses due to expired stock, significantly improving profitability and reducing waste. RBAC Layer A robust Role-Based Access Control (RBAC) layer is implemented at the middleware level. This ensures that permissions are strictly scoped for roles such as Pharmacist, Admin, and Doctor. A clearly bounded access surface prevents unauthorized access to sensitive patient data and system functions, mitigating risks associated with data breaches and internal misuse. Telemedicine + Stripe The system facilitates end-to-end payment capture through integration with Stripe. A WebSocket session layer manages the communication between the client and server during consultations and payment processes. Integrating Stripe involved handling secure tokenization, managing payment intents, and processing webhooks to confirm transactions accurately, ensuring a seamless and secure payment experience for patients. async function handlePayment(orderId: string, paymentIntentId: string) { // Verify payment intent status with Stripe const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId); if (paymentIntent.status === 'succeeded') { // Update order status in DB using Prisma atomic operation await prisma.order.update({ where: { id: orderId }, data: { status: 'PAID', paymentDetails: { create: { stripeId: paymentIntentId, amount: paymentIntent.amount, currency: paymentIntent.currency, }, }, }, }); // Push notification via WebSocket sendWebSocketMessage(userId, 'payment_success', { orderId }); } else { // Handle payment failure sendWebSocketMessage(userId, 'payment_failed', { orderId }); } } This system has led to significant improvements, including an estimated ~60% overhead reduction in administrative tasks, ~45% fewer stockouts, and facilitated over 500 consultations. Staff now save approximately 4 hours per day previously spent on manual inventory and administrative duties. Closing The system is in production today. Real pharmacists. Real patients. Real operations.




