Code:
#include <stdio.h>
#include <time.h>
typedef struct
{
char fName[21];
char gName[21];
} name_struct;
typedef struct
{
char street[21];
char suburb[16];
char state[4];
int postcode;
} address_struct;
typedef struct
{
char id[5];
name_struct name;
address_struct address;
double balance ;
char lastUpdate[11];
} patient_struct;
/*typedef struct
{
int jobCode;
char description[21];
double fee;
}fee_struct;*/
void showMenu();
void modifyPatient();
void showPatient();
void processFile();
void getDate(char *);
//void FeeSchedule(fee_struct fee[30]);
void displayPatient(patient_struct);
void getPatient(patient_struct patient);
void modifyfName();
void modifygName();
void modifyStreet();
void modifySuburb();
void modifyState();
void modifyPostCode();
char today[11];
main()
{
//fee_struct feeSchedule[30];
char option ='0';
getDate(today);
//getFeeSchedule(feeSchedule);
while(option!='q'||option!='Q')
{
showMenu();
option=getchar();getchar();
switch(option)
{
case '1':modifyPatient();
break;
case '2':showPatient();
break;
case '3':processFile();
break;
case 'q':
case 'Q':exit(0);
}
}
}
void getDate(char *today)
{
time_t x;
struct tm *t;
time(&x);
t = localtime(&x);
sprintf(today,"%d/%d/%d\n", t->tm_mday, t->tm_mon + 1, t->tm_year + 1900);
puts(today);
}
/*void FeeSchedule(fee_struct fee[30])
{
//Here you
//1.open the text file
//2.read the records and put them in the array (week8-9)
}*/
void showMenu()
{
printf("\n\n");
printf("Dr Stevenson Dental Surgery\n");
printf("Patient System\n\n");
printf("1. Modify patient record\n");
printf("2. Show patient record\n");
printf("3. Process work file\n");
printf("q. Quit the system\n");
printf(" Choose 1,2,3 or q: ");
}
void modifyPatient()
{
FILE *file;
int i;
char option ='0';
char patientId[5];
patient_struct patient;
printf("Enter patient id: ");
gets(patientId);
file=fopen("patient.dat","rb");
fread(&patient, sizeof(patient), 1,file);
while(!feof(file))
{
if (strcmp(patientId,patient.id)==0)
while(option!='q'||option!='Q')
{
getPatient(patient);
option=getchar();getchar();
switch(option)
{
case '1':modifyfName();
break;
case '2':modifygName();
break;
case '3':modifyStreet();
break;
case '4':modifySuburb();
break;
case '5':modifyState();
break;
case '6':modifyPostCode();
case 'q':
case 'Q': exit(0);
}
}
fread(&patient, sizeof(patient), 1,file);
}//end of file
fclose(file);
}
void modifyfName()
{
//printf("not yet done\n");
FILE *file;
patient_struct patient;
file=fopen("patient.dat","ab");
fwrite(&patient,sizeof(patient_struct),1,file);
printf("Enter new family name: ");
gets(patient.name.gName);
}
void modifygName()
{
printf("not yet done\n");
}
void modifyStreet()
{
printf("not yet done\n");
}
void modifySuburb()
{
printf("not yet done\n");
}
void modifyState()
{
printf("not yet done\n");
}
void modifyPostCode()
{
printf("not yet done\n");
}
void getPatient(patient_struct patient)
{
printf("\n");
printf(" Patient id : %s \n", patient.id);
printf("1.Family name : %s \n", patient.name.gName);
printf("2.Given name : %s \n", patient.name.fName);
printf("3.Street & Number : %s \n", patient.address.street);
printf("4.Suburb : %s \n", patient.address.suburb);
printf("5.State : %s \n", patient.address.state);
printf("6.Postcode : %d \n", patient.address.postcode);
printf(" Balance : %.2lf\n", patient.balance);
printf(" Last update : %s\n", patient.lastUpdate);
printf("q.Go back to menu\n");
}
void showPatient()
{
//get patient id
FILE *file;
char patientId[5];
patient_struct patient;
printf("Enter patient id: ");
gets(patientId);
file=fopen("patient.dat","rb");
fread(&patient,sizeof(patient_struct),1,file);
while(!feof(file))
{
if(strcmp(patientId,patient.id)==0)
{
displayPatient(patient);
break;
}
fread(&patient,sizeof(patient_struct),1,file);
}//end of file
fclose(file);
}
void processFile()
{
printf("not yet done\n");
}
void displayPatient(patient_struct patient)
{
printf("\n");
printf("Patient id : %s \n", patient.id);
printf("Patient name : %s %s \n", patient.name.gName, patient.name.fName);
printf("Patient address: %s \n", patient.address.street);
printf(" %s %s %d\n", patient.address.suburb,
patient.address.state, patient.address.postcode);
printf("Balance : %.2lf \n", patient.balance);
printf("Last update : %s\n", patient.lastUpdate);
}