In healthcare systems, blockchain technology plays a crucial role in transmitting COVID-19 data among multiple entities. Over time, various blockchain-based medical applications have emerged to handle medical information confidentially. One such system is the Scalable eHealthChain system (SeHealthChain), which utilizes a sharding scheme consisting of transaction chain and reputation chain structures to enhance throughput and security. However, the system employs a modified Raft-based Synchronous Consensus Scheme (RSCS) for generating the transaction blockchain, which can potentially introduce illegitimate transactions to the Hyperledger fabric network if a rogue node transfers them to the orderer. This poses a significant security risk in the worst-case scenarios. Additionally, as the hash rate fluctuates exponentially, the generation period of transaction blocks and computation difficulty increase. To address these issues, this article proposes an Optimized SeHealthChain (OSeHealthChain) system. It integrates a Tuna Swarm Optimization Algorithm (TSOA) with the modified RSCS to dynamically adjust the blockchain parameters in response to significant changes in the hash rate. The TSOA optimizes two variables, namely the Block Interval (BI) and Difficulty Adjustment Interval (DAI) of the Proof-of-Work (PoW) for the transaction blockchain, based on objective functions that consider the Standard Deviations (SD) of the mean BI and difficulty. By selecting appropriate variables, the system generates new transaction blocks with minimal nodes and overhead, effectively validating transactions and blocks to enhance the security level. Extensive simulations show that the OSeHealthChain achieves a throughput of 3918tps and a user-perceived latency of 63.8s for 1000 nodes, outperforming the SeHealthChain, eHealthChain, Permissionless Proof-of-Reputation-X (PL-PoRX), and hybrid Proof of Stake-Practical Byzantine Fault Tolerance (POS-PBFT) algorithms in blockchain systems. It also achieves throughputs of 7051tps, 6418tps, and 6290tps for simple, camouflage, and observe-act attacks, respectively, with 1000 nodes and a shard dimension of 200 during 20 epochs.