Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of test_patient_structure by
patients.cpp@1:060801821b1c, 2017-11-02 (annotated)
- Committer:
- CSTritt
- Date:
- Thu Nov 02 21:22:34 2017 +0000
- Revision:
- 1:060801821b1c
- Parent:
- patients.h@0:c435f76658b2
Initial version. Based on demo program by Dr. Sheila Ross.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
CSTritt | 1:060801821b1c | 1 | /* |
CSTritt | 1:060801821b1c | 2 | Project: PatientStructure |
CSTritt | 1:060801821b1c | 3 | File: patients.cpp (v. 1.0) |
CSTritt | 1:060801821b1c | 4 | |
CSTritt | 1:060801821b1c | 5 | Declarations for patient data base using structure example. See main.cpp |
CSTritt | 1:060801821b1c | 6 | for details. |
CSTritt | 1:060801821b1c | 7 | |
CSTritt | 1:060801821b1c | 8 | Modified by Dr. C. S. Tritt |
CSTritt | 1:060801821b1c | 9 | */ |
CSTritt | 1:060801821b1c | 10 | #include "mbed.h" |
CSTritt | 1:060801821b1c | 11 | #include "patients.h" |
rossatmsoe | 0:c435f76658b2 | 12 | |
CSTritt | 1:060801821b1c | 13 | // Prints the values in the structure for a particular patient. |
rossatmsoe | 0:c435f76658b2 | 14 | void print_patient_record(struct patient_record *first_patient, int N) { |
CSTritt | 1:060801821b1c | 15 | pc.printf("%s %s \t ID: %d\n", first_patient[N].firstname, |
CSTritt | 1:060801821b1c | 16 | first_patient[N].lastname, N); |
CSTritt | 1:060801821b1c | 17 | pc.printf("BP: %d/%d SpO2: %f\n",first_patient[N].systolic, |
CSTritt | 1:060801821b1c | 18 | first_patient[N].diastolic, first_patient[N].spO2); |
rossatmsoe | 0:c435f76658b2 | 19 | } |
rossatmsoe | 0:c435f76658b2 | 20 | |
CSTritt | 1:060801821b1c | 21 | // Puts patient into record. |
rossatmsoe | 0:c435f76658b2 | 22 | void newPatient(struct patient_record *patient, char *first, char*last) |
rossatmsoe | 0:c435f76658b2 | 23 | { |
rossatmsoe | 0:c435f76658b2 | 24 | // We can't just set the firstname pointer equal to the |
rossatmsoe | 0:c435f76658b2 | 25 | // first pointer; that doesn't actually move the information into |
rossatmsoe | 0:c435f76658b2 | 26 | // the structure. We need to copy each letter of the patient's name |
rossatmsoe | 0:c435f76658b2 | 27 | // into the structure. strcpy does this. |
rossatmsoe | 0:c435f76658b2 | 28 | strcpy(patient->firstname, first); |
CSTritt | 1:060801821b1c | 29 | strcpy(patient->lastname, last); |
rossatmsoe | 0:c435f76658b2 | 30 | } |
rossatmsoe | 0:c435f76658b2 | 31 | |
CSTritt | 1:060801821b1c | 32 | // Fills in vital signs directly. Note that we use -> when we have a |
CSTritt | 1:060801821b1c | 33 | // pointer to a struct and we want to access one of the members. |
rossatmsoe | 0:c435f76658b2 | 34 | void recordBP(struct patient_record *patient, int sys, int dias, float o2) { |
rossatmsoe | 0:c435f76658b2 | 35 | patient->systolic=sys; |
rossatmsoe | 0:c435f76658b2 | 36 | patient->diastolic=dias; |
rossatmsoe | 0:c435f76658b2 | 37 | patient->spO2 = o2; |
rossatmsoe | 0:c435f76658b2 | 38 | } |
rossatmsoe | 0:c435f76658b2 | 39 | |
CSTritt | 1:060801821b1c | 40 | // Fills in vital signs through the serial monitor (for BP) and the oxygen |
CSTritt | 1:060801821b1c | 41 | // sensor assumed to be an analog input giving the SpO2 level as a fraction. |
CSTritt | 1:060801821b1c | 42 | void recordBPinteractive(struct patient_record *first_patient, |
CSTritt | 1:060801821b1c | 43 | AnalogIn oxygen) { |
CSTritt | 1:060801821b1c | 44 | |
rossatmsoe | 0:c435f76658b2 | 45 | int N; |
rossatmsoe | 0:c435f76658b2 | 46 | int s; |
rossatmsoe | 0:c435f76658b2 | 47 | int d; |
rossatmsoe | 0:c435f76658b2 | 48 | |
rossatmsoe | 0:c435f76658b2 | 49 | pc.printf("Enter the patient number:\n"); |
rossatmsoe | 0:c435f76658b2 | 50 | pc.scanf("%d",&N); |
rossatmsoe | 0:c435f76658b2 | 51 | pc.printf("Enter the systolic BP:\n"); |
rossatmsoe | 0:c435f76658b2 | 52 | pc.scanf("%d",&s); |
rossatmsoe | 0:c435f76658b2 | 53 | pc.printf("Enter the diastolic BP:\n"); |
rossatmsoe | 0:c435f76658b2 | 54 | pc.scanf("%d",&d); |
rossatmsoe | 0:c435f76658b2 | 55 | |
rossatmsoe | 0:c435f76658b2 | 56 | //Note that [N] turns first_patient into a struct rather than a |
rossatmsoe | 0:c435f76658b2 | 57 | //pointer to a struct (dereferences the pointer). Therefore, we |
rossatmsoe | 0:c435f76658b2 | 58 | //use . to access members. |
rossatmsoe | 0:c435f76658b2 | 59 | first_patient[N].systolic=s; |
rossatmsoe | 0:c435f76658b2 | 60 | first_patient[N].diastolic=d; |
rossatmsoe | 0:c435f76658b2 | 61 | first_patient[N].spO2=oxygen; |
rossatmsoe | 0:c435f76658b2 | 62 | |
rossatmsoe | 0:c435f76658b2 | 63 | //Print information to confirm |
rossatmsoe | 0:c435f76658b2 | 64 | pc.printf("Data entered:\n"); |
CSTritt | 1:060801821b1c | 65 | print_patient_record(first_patient, N); |
rossatmsoe | 0:c435f76658b2 | 66 | } |
rossatmsoe | 0:c435f76658b2 | 67 | |
rossatmsoe | 0:c435f76658b2 | 68 | //Look up the patient number by searching through the array of patients |
rossatmsoe | 0:c435f76658b2 | 69 | //and matching the first and last name. strcmp returns 0 if two strings |
rossatmsoe | 0:c435f76658b2 | 70 | //are identical. Return the patient's position in the array if name is |
CSTritt | 1:060801821b1c | 71 | //found, -1 if it is not found. Note 2 returns! |
CSTritt | 1:060801821b1c | 72 | int lookup_patient_name(struct patient_record *first_patient, char *first, |
CSTritt | 1:060801821b1c | 73 | char*last) |
rossatmsoe | 0:c435f76658b2 | 74 | { |
rossatmsoe | 0:c435f76658b2 | 75 | for(int k=0; k<MAX_PATIENTS; k++) { |
rossatmsoe | 0:c435f76658b2 | 76 | if(strcmp(first_patient[k].lastname,last) == 0) { |
rossatmsoe | 0:c435f76658b2 | 77 | if(strcmp(first_patient[k].firstname,first) == 0) { |
rossatmsoe | 0:c435f76658b2 | 78 | return k; |
rossatmsoe | 0:c435f76658b2 | 79 | } |
rossatmsoe | 0:c435f76658b2 | 80 | } |
rossatmsoe | 0:c435f76658b2 | 81 | } |
rossatmsoe | 0:c435f76658b2 | 82 | return -1; |
CSTritt | 1:060801821b1c | 83 | } |