MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with schemata.
MongoDB is an open source database management system (DBMS) that uses a document-oriented database model which supports various forms of data. It is one of numerous non relational database technologies which arose in the mid-2000s under the NoSQL banner for use in big data applications and other processing jobs involving data that doesn't fit well in a rigid relational model. Instead of using tables and rows as in relational databases, the MongoDB architecture is made up of collections and documents.
How it works
A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB documents are similar to JavaScript Object Notation objects but use a variant called Binary JSON (BSON) that accommodates more data types. The fields in documents are akin to the columns in a relational database, and the values they contain can be a variety of data types, including other documents, arrays and arrays of documents, according to the MongoDB user manual.
Documents, which also must incorporate a primary key as a unique identifier, are the basic unit of data in MongoDB. Collections contain sets of documents and function as the equivalent of relational database tables. Collections can contain any type of data, but the restriction is the data in a collection cannot be spread across different databases. The mongo shell is an interactive JavaScript interface to MongoDB which allows users to query and update data, and conduct administrative operations. The shell is a standard component of the open source distributions of MongoDB. Once MongoDB is installed, users connect the mongo shell to their running MongoDB instances.
Being a NoSQL tool means it does not use the usual rows and columns that we so much associate with the relational database management. It is an architecture that is built on collections and documents. The basic unit of data in this database consists of a set of key-value pairs. To be connected to the project mongodb you need to create SSH connection with IP address and port number (0.0.0.0:27017) using privet key for establishing that connection. All communication and tasks in the application server done using service called mongoose.
When the application connected to the database; any process for storing or retrieving the user data will be triggered using Express.js, see the below architecture.
CareBud backend has nine modules which shown below in CareBud Data Module and each module represents functionality in the application, thus modules explained as follow:
The above diagram illustrates all the relation between the existing modules in CareBud backend and each module has its own data schema and attributes. The following example shows the schema for users’ module:
Users: user module includes all information about all user accounts.
var validateEmail = function(email) {
var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
return re.test(email)
};
var UserSchema = new Schema({
lastName: {type: String, required: [true, "last name is required"]},
firstName: {type: String, required: [true, "first name is required"]},
userName: {type: String, required: [true, "user name is required"], unique: [true, "username should be unique"]},
password: {type: String, required: [true, "password is required"]},
userType: {type: String, required: [true, "user type is required"]},
age: {type: String, required: [true, "user age is required"]},
address: {type: String},
userMobile: {type: String, required: [true, "mobile number is required"], unique: [true , "This mobile number is exist!"]},
userEmail:{type: String, required: [false, "mobile number is required"], unique: [true , "This mobile number is exist!"]},
userEmail: { type: String, trim: true, lowercase: true, unique: true, required: [false, "Email is required"],
validate: [validateEmail, 'Please fill a valid email address'],
match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, 'Please fill a valid email address']},
location: {
lng: {type: String, required: [true, "lng location is required"]},
lat: {type: String, required: [true, "lat location is required"]}
},
birthDate: {type: String, required: [true, "birthDate is required"]},
gender: {type: String, required: [true, "gender is required"]},
photo: {type: String, default: "photoDir",},
time_created: {type: Date, required: [true, "date and time required"], default: Date.now}
});
//USER SCHEMA FROM BACKEND APPLICATION
Patient: contains information about patient accounts and health reports for that patient, along with list that contains information about contacted doctors and relatives.
var PatientSchema = new Schema({
user_id: { type: String, required:[true, "user Id is required"]},
relatedRelative_id:{type: String, default: ""},//only one relative is allowed to view patient details.
relatedDoctors_ids:[], //many doctors will be associated with the patient
healthStatus:[]
});
Doctors: contains information about a particular doctor and along with list contains information about the contacted patients.
var DoctorSchema = new Schema({
user_id: {type: String, required: [true, "user ID is required"]},
yearsExperience: {type: String, default: 0},
doctorSpecialist: {type: String, required: [true, "Doctor Specialist is required"]},
doctor_about:{type: String, required: [true, "Information about a doctor is required"]}
});
Relatives: contains information about a particular relative and contain information about the contacted patients.
var PatientRelativesSchema= new Schema({
user_id: {type: String, required:[true, "user ID is required"]}, // user type is Relative
patient_id: {type: String, default: ""} // patient should be monitored by Relative
relative_relation: {type: String, default: "family"},
relative_details: {type: String, default: "Non"}
});
Health Status: contains all current health status only for a particular patient which includes a status array of (Blood Pressure, Body Temperature and Heart Beat Reports) that will be taken be virtual Smartwatch.
var HealthStatusSchema= new Schema({
user_id: { type: String, required:[true, "user ID is required"]},
healthStatus_name: {type: String, required:[true, "test name is required"]},
healthStatus_description: {type: String},
healthStatus_value: {type: String, required:[false, "heart rate value is not required"]},
healthStatus_previousValue: {type: String, required:[false, "previous heart rate value is not required"]},
healthStatus_unit: {type: String, required:[true, "measuring unit required"]},
effectedTime: {type: Date, required:[true, "time is required"], default: Date.now},
previous_effectedTime: {type: Date, required:[true, "previous time is required"],default: Date.now},
bloodPressureReport: {
systolicBPValue: {type: String, required:[false, "systolic value is not required"]},
previous_systolicBPValue: {type: String, required:[false, "previous systolic value is not required"]},
diastolicBPValue: {type: String, required:[false, "diastolic value is not required"]},
previous_diastolicBPValue: {type: String, required:[false, "previous diastolic value is not required"]}
}
});
PatientGeneralHealthReport: is a report that contains health reports and diagnosis provided by a patient or his doctor also any advises written by him.
var PatientGeneralHealthReportSchema = new Schema({
patient_id: {type: String, required: [true, "user ID is required"]},
patientGeneralHealthReport: {
whatSymptomsDoYouHave: {type: String, default: "whatSymptomsDoYouHave"},
doYouHaveAnyDiscomfort: {type: String, default: "doYouHaveAnyDiscomfort"},
whereDoYouHaveDiscomfort: {type: String, default: "whereDoYouHaveDiscomfort"},
whatRelievesYourDiscomfort: {type: String, default: "whatRelievesYourDiscomfort"},
hasAnyoneInYourFamilyEverHadHeartProblems: {type: String, default: "hasAnyoneInYourFamilyEverHadHeartProblems"},
doYouHaveAnyChronicDisease: {type: String, default: "doYouHaveAnyChronicDisease"},
patientNoteIfAny: {type: String, default: "patientNoteIfAny"},
doctorNoteIfAny: {type: String, default: "doctorNoteIfAny"}
},
doctorReportAdvices: {type: String, required: [false, "doctorReportAdvicesname is not required"]},
doctorDetails: [], // array contains all doctor information who reviwed patient general report
time_created: {type: Date, required: [true, "date and time required"], default: Date.now}
});
PatientHealthReportHistory: this module will store old health reports for a patient that can be called for reviewing to help doctors diagnosing patient health well.
var PatientHealthReportHistorySchema= new Schema({
patient_id: { type: String, required:[true, "user ID is required"]},
time_created: {type: Date, required: [true, "date and time required"], default: Date.now},
patientHealthReportStatus:[] // array contain all patinet health reports history
});
Notification: This module will contain all notifications running through the application, for example when patient select specific doctor, a direct notification will be fired to the doctor for approving that, also if the patient health status gets critical, the system will fire real time notification upon that to the available doctors and relative list for fast responding. On that action, the information required for that patient will be provided along with the notification.
var NotificationSchema = new Schema({
sender_id: {type: String, required:[true, "user ID is required"]}, // Notification creator
receiver_ids: [], // Ids of the receivers of the notification
message: String, // any description of the notification message
read_by:[{
readerId:{type: String},
read_at: {type: Date, default: Date.now}
}],
created_at:{type: Date, default: Date.now}
});
Chat: this module is available only between patients and doctors, for any advises and related health status reports.
var ChatSchema = new Schema({
patient_id: {type: String, required:[true, "ptient ID is required"]},
doctor_id: {type: String, required:[true, "doctor ID is required"]},
messages:[MessagesSchema],
cr_time_created:{type:Date, required:[true, "date and time required"], default: Date.now}
});
var MessagesSchema = new Schema({
author_id: {type: String, required:[true, "author ID is required"]},
author_name: {type: String, required:[true, "author name is required"]},
message:{type:String, required:[true, "message is required"]},
time_created:{type:Date, required:[true, "date and time required"], default: Date.now}
});
Same structure for all module’s schema with different attributes and data types, which make it easy to build and code in the front end application also when the data process for encryption and decryption. For more details about CareBud Backend Application.