Charles Tritt / Mbed 2 deprecated PatientStructure

Dependencies:   mbed

Fork of test_patient_structure by MSOE EE2905

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Thu Nov 02 21:22:34 2017 +0000
Parent:
0:c435f76658b2
Commit message:
Initial version. Based on demo program by Dr. Sheila Ross.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
patients.cpp Show annotated file Show diff for this revision Revisions of this file
patients.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Nov 02 18:31:39 2017 +0000
+++ b/main.cpp	Thu Nov 02 21:22:34 2017 +0000
@@ -1,13 +1,36 @@
+/*
+  Project: PatientStructure (based on very similar example by Dr. Ross.)
+  File: main.cpp (file v. 1.0)
+  Modified by by: Dr. C. S. Tritt
+  Last revision on: 11/2/17 (Project v. 1.0)
+
+  Simulates a patient database. See comments in patients.cpp regarding purpose 
+  use of each function. This function just populates the database and initates 
+  update of one record.
+  
+  This program is for demonstration only. Input is not validated and array 
+  limits are not checked. This is bad programming practice, but okay for "toy"
+  programs like this.
+*/
+
 #include "mbed.h"
 #include "patients.h"
 
+// Some functions use the serial monitor so define it here. Declare as extern
+// in header file.
+Serial pc(USBTX,USBRX);
+
 //Pretend we have a pulse oximeter attached to A0 which provides the SpO2
 //as a fraction.
 AnalogIn pulse_oximeter(A0);
 
 int main()
 {
-    // Create an array of patient_record structures to form the patient database.
+    pc.printf("\nWelcome to PatientStructure Example.\n");
+    pc.printf("Turn local echo on!\n");
+    // Create an array of patient_record structures to form the patient 
+    // database.
+    pc.printf("About to create and populate database...\n");
     struct patient_record all_patients[MAX_PATIENTS];
     // Keep track of the number of patients.
     int enrollment=0;
@@ -20,20 +43,24 @@
     enrollment++;
     
     newPatient(&(all_patients[enrollment]),"Thomas","Jefferson");
-    enrollment++;
+    enrollment++; // Enrollment incr. an extra time. Its the # of pateints.
 
-    //Look up a patient--this one is not in our database.    
-    int X=lookup_patient_name(all_patients,"Abraham","Lincoln");
-    pc.printf("Abraham Lincoln is patient %d\n",X);
+    //Look up a patient -- this one is not in our database.  
+    pc.printf("About to lookup non-existent patient...\n");  
+    int X = lookup_patient_name(all_patients, "Abraham", "Lincoln");
+    pc.printf("Abraham Lincoln is patient %d\n", X);
     
     //Look up a patient.    
-    int Y=lookup_patient_name(all_patients,"Thomas","Jefferson");
-    pc.printf("Thomas Jefferson is patient %d\n",Y);
+    pc.printf("About to lookup valid patient...\n");  
+    int Y = lookup_patient_name(all_patients, "Thomas", "Jefferson");
+    pc.printf("Thomas Jefferson is patient %d\n", Y);
    
     //Enter patient's vitals.
+    pc.printf("About to interactively update patient data...\n");
+    pc.printf("There are %d patients in the database. Be careful!\n", 
+        enrollment);  
     recordBPinteractive(all_patients, pulse_oximeter);
-
-    while(1);   
-
-
+    
+    pc.printf("Done. I sleep now...\n");  
+    while(true) wait(3600); // Loop here forever, waiting an hour at a time.
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/patients.cpp	Thu Nov 02 21:22:34 2017 +0000
@@ -0,0 +1,83 @@
+/*
+   Project: PatientStructure   
+   File: patients.cpp (v. 1.0)
+   
+   Declarations for patient data base using structure example. See main.cpp
+   for details.
+   
+   Modified by Dr. C. S. Tritt
+*/
+#include "mbed.h"
+#include "patients.h"
+
+// Prints the values in the structure for a particular patient.
+void print_patient_record(struct patient_record *first_patient, int N) {
+    pc.printf("%s %s \t ID: %d\n", first_patient[N].firstname, 
+        first_patient[N].lastname, N);
+    pc.printf("BP: %d/%d  SpO2: %f\n",first_patient[N].systolic, 
+        first_patient[N].diastolic, first_patient[N].spO2);
+}   
+
+// Puts patient into record.
+void newPatient(struct patient_record *patient,  char *first, char*last)
+{
+    // We can't just set the firstname pointer equal to the
+    // first pointer; that doesn't actually move the information into
+    // the structure.  We need to copy each letter of the patient's name
+    // into the structure.  strcpy does this.
+    strcpy(patient->firstname, first);
+    strcpy(patient->lastname, last);
+}
+
+// Fills in vital signs directly.  Note that we use -> when we have a
+// pointer to a struct and we want to access one of the members.
+void recordBP(struct patient_record *patient, int sys, int dias, float o2) {
+    patient->systolic=sys;
+    patient->diastolic=dias;
+    patient->spO2 = o2;
+}
+
+// Fills in vital signs through the serial monitor (for BP) and the oxygen 
+// sensor assumed to be an analog input giving the SpO2 level as a fraction.
+void recordBPinteractive(struct patient_record *first_patient, 
+    AnalogIn oxygen) {
+        
+    int N;
+    int s;
+    int d;
+    
+    pc.printf("Enter the patient number:\n");
+    pc.scanf("%d",&N);
+    pc.printf("Enter the systolic BP:\n");
+    pc.scanf("%d",&s);
+    pc.printf("Enter the diastolic BP:\n");
+    pc.scanf("%d",&d);
+    
+    //Note that [N] turns first_patient into a struct rather than a
+    //pointer to a struct (dereferences the pointer).  Therefore, we
+    //use . to access members.
+    first_patient[N].systolic=s;
+    first_patient[N].diastolic=d;
+    first_patient[N].spO2=oxygen;
+    
+    //Print information to confirm
+    pc.printf("Data entered:\n");
+    print_patient_record(first_patient, N);
+}      
+
+//Look up the patient number by searching through the array of patients
+//and matching the first and last name.  strcmp returns 0 if two strings
+//are identical.  Return the patient's position in the array if name is
+//found, -1 if it is not found. Note 2 returns!
+int lookup_patient_name(struct patient_record *first_patient, char *first,
+    char*last)
+{
+    for(int k=0; k<MAX_PATIENTS; k++) {
+        if(strcmp(first_patient[k].lastname,last) == 0) {
+            if(strcmp(first_patient[k].firstname,first) == 0) {
+                return k;
+            }
+        }
+    }
+    return -1;
+}
\ No newline at end of file
--- a/patients.h	Thu Nov 02 18:31:39 2017 +0000
+++ b/patients.h	Thu Nov 02 21:22:34 2017 +0000
@@ -1,5 +1,16 @@
-// Some functions use the serial monitor so define it here.
-Serial pc(USBTX,USBRX);
+/*
+   Project: PatientStructure
+   File: patients.h (v. 1.0)
+   
+   Header file for patient data base using structure example. See main.cpp
+   for details.
+   
+   Modified by Dr. C. S. Tritt
+*/
+// Defined in main. Used in main & patients.cpp, so declare in header file. 
+// extern is rerequied to avoid duplicate objects that result in a linker
+// error.
+extern Serial pc;
 
 // The patient_record structure stores name and vitals for a patient.
 struct patient_record {
@@ -15,69 +26,18 @@
 #define MAX_PATIENTS 100
 
 //Print the values in the structure for a particular patient.
-void print_patient_record(struct patient_record *first_patient, int N) {
-    pc.printf("%s %s \t ID: %d\n",first_patient[N].firstname, first_patient[N].lastname,N);
-    pc.printf("BP: %d/%d  SpO2: %f\n",first_patient[N].systolic, first_patient[N].diastolic, first_patient[N].spO2);
-}   
-
+void print_patient_record(struct patient_record *first_patient, int N);
 //Put patient into record.
-void newPatient(struct patient_record *patient,  char *first, char*last)
-{
-    // We can't just set the firstname pointer equal to the
-    // first pointer; that doesn't actually move the information into
-    // the structure.  We need to copy each letter of the patient's name
-    // into the structure.  strcpy does this.
-    strcpy(patient->firstname, first);
-    strcpy(patient->lastname,last);
-}
-
+void newPatient(struct patient_record *patient,  char *first, char*last);
 //Fill in vital signs directly.  Note that we use -> when we have a
 //pointer to a struct and we want to access one of the members.
-void recordBP(struct patient_record *patient, int sys, int dias, float o2) {
-    patient->systolic=sys;
-    patient->diastolic=dias;
-    patient->spO2 = o2;
-}
-
+void recordBP(struct patient_record *patient, int sys, int dias, float o2); 
 //Fill in vital signs through the serial monitor (for BP) and the oxygen sensor,
 //assumed to be an analog input giving the SpO2 level as a fraction.
-void recordBPinteractive(struct patient_record *first_patient, AnalogIn oxygen) {
-    int N;
-    int s;
-    int d;
-    
-    pc.printf("Enter the patient number:\n");
-    pc.scanf("%d",&N);
-    pc.printf("Enter the systolic BP:\n");
-    pc.scanf("%d",&s);
-    pc.printf("Enter the diastolic BP:\n");
-    pc.scanf("%d",&d);
-    
-    //Note that [N] turns first_patient into a struct rather than a
-    //pointer to a struct (dereferences the pointer).  Therefore, we
-    //use . to access members.
-    first_patient[N].systolic=s;
-    first_patient[N].diastolic=d;
-    first_patient[N].spO2=oxygen;
-    
-    //Print information to confirm
-    pc.printf("Data entered:\n");
-    print_patient_record(first_patient,N);
-}      
-
+void recordBPinteractive(struct patient_record *first_patient, AnalogIn oxygen);
 //Look up the patient number by searching through the array of patients
 //and matching the first and last name.  strcmp returns 0 if two strings
 //are identical.  Return the patient's position in the array if name is
 //found, -1 if it is not found.
-int lookup_patient_name(struct patient_record *first_patient,char*first,char*last)
-{
-    for(int k=0; k<MAX_PATIENTS; k++) {
-        if(strcmp(first_patient[k].lastname,last) == 0) {
-            if(strcmp(first_patient[k].firstname,first) == 0) {
-                return k;
-            }
-        }
-    }
-    return -1;
-}
-
+int lookup_patient_name(struct patient_record *first_patient, char*first,
+    char*last);
\ No newline at end of file