Skip to content

Taridekpen/pham

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

use near_sdk::{near_bindgen, env}; This line imports the near_sdk crate, which provides the Near blockchain-specific functionality used in this program. Specifically, it imports the near_bindgen and env modules from the near_sdk crate.

use std::collections::HashMap; This line imports the HashMap data structure from the standard library of Rust. HashMap is a key-value data structure that allows for fast lookup of values given a specific key.

use borsh::{BorshDeserialize, BorshSerialize}; This line imports the borsh crate, which is a serialization and deserialization library for Rust that is optimized for size and speed. Specifically, it imports the BorshDeserialize and BorshSerialize traits, which allow structs to be encoded and decoded using Borsh.

#[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] pub struct Pharmacy { patients: HashMap<String, PatientData>, last_patient_id: u64, }

This is the definition of the Pharmacy struct, which is marked with the #[near_bindgen] attribute. This attribute allows the struct to be used as a contract on the Near blockchain. The Pharmacy struct contains a HashMap of PatientData structs, which is used to store patient information, and a last_patient_id field, which is used to generate unique patient IDs.

#[derive(BorshDeserialize, BorshSerialize)] pub struct PatientData { name: String, age: u8, address: String, phone_number: String, }

This is the definition of the PatientData struct, which contains fields for a patient's name, age, address, and phone number. It is also marked with the BorshDeserialize and BorshSerialize traits to allow for serialization and deserialization using Borsh.

`impl Pharmacy { pub fn register_patient(&mut self, name: String, age: u8, address: String, phone_number: String) -> String { let patient_id = format!("patient_{}", self.last_patient_id + 1); self.patients.insert(patient_id.clone(), PatientData { name, age, address, phone_number, }); self.last_patient_id += 1; env::log(format!("Patient registered with ID: {}", patient_id).as_bytes()); patient_id }

pub fn get_patient_data(&self, patient_id: String) -> Option<PatientData> {
    self.patients.get(&patient_id).cloned()
}

}`

These lines define the implementation of the Pharmacy struct. The register_patient method takes in patient data and generates a unique patient ID based on the last_patient_id field. It then inserts the patient data into the patients HashMap and increments last_patient_id. Finally, it logs the patient registration event and returns the patient ID.

The get_patient_data method takes in a patient ID and returns the associated `

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors