Charles Tritt / Mbed 2 deprecated PatientStructure

Dependencies:   mbed

Fork of test_patient_structure by MSOE EE2905

patients.cpp

Committer:
CSTritt
Date:
2017-11-02
Revision:
1:060801821b1c
Parent:
patients.h@ 0:c435f76658b2

File content as of revision 1:060801821b1c:

/*
   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;
}