For healthcare systems utilizing Wireless Body Area Networks (WBANs), maintaining the network's diverse Quality of Service (QoS) metrics necessitates effective communication among Fog Computing resources. While fog nodes efficiently handle local requests with substantial processing resources, it is crucial to acknowledge the unpredictable availability of these nodes, potentially resulting in a decline in system performance. This study explores a software-defined fog architecture supporting different healthcare applications in Internet of Things (IoT) environment to ensure consistent specialized medical care amidst evolving health issues. Even minor delays, packet losses, or network overhead could adversely affect patient health. The article establishes a mathematical foundation based on transmitted and sensed data, ensuring each fog node executes an ideal quantity of processes. This study formulates an optimization problem to maximize the utility of fog nodes, leveraging the Lagrangian approach and Karush-Kuhn-Tucker conditions to streamline and resolve the optimization problem. Performance analysis demonstrates a significant reduction in delays by approximately 38 %, 29 %, and 32 %, along with energy savings of roughly 26.89 %, 12.16 %, and 22.50 %, compared to benchmark approaches. This study holds promise in healthcare, cloud-fog simulation, and WBANs, emphasizing the critical need for swift and accurate data processing.