Medical records are transmitted between medical institutions using cloud-based Electronic Health Record (EHR) systems, which are intended to improve various medical services. Due to the potential of data breaches and the resultant loss of patient data, medical organizations find it challenging to employ cloud-based electronic medical record systems. EHR systems frequently necessitate high transmission costs, energy use, and time loss for physicians and patients. Furthermore, EHR security is a critical concern that jeopardizes patient privacy. Compared to a single system, cloud-based EHR solutions may bring extra security concerns as the system architecture gets more intricate. Access control strategies and the development of efficient security mechanisms for cloud-based EHR data are critical. For privacy reasons, the Dynamic Constrained Message Authentication (DCMA) technique is used in the proposed system to encrypt the outsource medical data by using symmetric key cryptography which uses the Seagull Optimization Algorithm (SOA) for choosing the best random keys for encryption and then resultant data is hashed using the SHA-256 technique. The system is developed in Python language, and the results are assessed using performance metrics including delay time, security rate, false error rate (FER), storage time, retrieval time, throughput ratio, encryption and decryption time, accuracy rate, key generation time, and security. The implemented system is superior in terms of security because it adopts the advance random secret keys generation which adds more security to the system of about 94% with less delay and loss ratio.