Complet exercici 2f
This commit is contained in:
parent
af36e69df2
commit
36bac13b1b
1 changed files with 47 additions and 4 deletions
|
@ -13,6 +13,12 @@
|
||||||
#define VACCINE_LOT_NUM_FIELDS 7
|
#define VACCINE_LOT_NUM_FIELDS 7
|
||||||
#define MAX_CP_LEN 5
|
#define MAX_CP_LEN 5
|
||||||
#define MAX_VACCINE_NAME_LEN 15
|
#define MAX_VACCINE_NAME_LEN 15
|
||||||
|
#define PERSON_TYPE_NAME "PERSON"
|
||||||
|
#define PERSON_NUM_FIELDS 7
|
||||||
|
#define MAX_PERSON_DOCUMENT_LEN 9
|
||||||
|
#define MAX_PERSON_NAME_LEN 15
|
||||||
|
#define MAX_PERSON_EMAIL_LEN 30
|
||||||
|
#define MAX_PERSON_ADDRESS_LEN 30
|
||||||
|
|
||||||
// Get the API version information
|
// Get the API version information
|
||||||
const char* api_version() {
|
const char* api_version() {
|
||||||
|
@ -168,9 +174,9 @@ tApiError api_freeData(tApiData* data) {
|
||||||
// Ex PR1 2e
|
// Ex PR1 2e
|
||||||
/////////////////////////////////
|
/////////////////////////////////
|
||||||
|
|
||||||
population_free(&data->population);
|
population_free(&(data->population));
|
||||||
vaccineList_free(&data->vaccines);
|
vaccineList_free(&(data->vaccines));
|
||||||
vaccineLotData_free(&data->vaccineLots);
|
vaccineLotData_free(&(data->vaccineLots));
|
||||||
|
|
||||||
return E_SUCCESS;
|
return E_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +190,44 @@ tApiError api_addDataEntry(tApiData* data, tCSVEntry entry) {
|
||||||
|
|
||||||
tApiError ret = E_NOT_IMPLEMENTED;
|
tApiError ret = E_NOT_IMPLEMENTED;
|
||||||
|
|
||||||
|
// Check if entry type is Vaccine Lot and its field number is correct
|
||||||
|
if (strcmp(csv_getType(&entry),VACCINE_LOT_TYPE_NAME) == 0) {
|
||||||
|
if (csv_numFields(entry) == VACCINE_LOT_NUM_FIELDS) {
|
||||||
|
|
||||||
|
ret = api_addVaccineLot(data,entry);
|
||||||
|
|
||||||
|
} else { // Num fields does not match
|
||||||
|
ret = E_INVALID_ENTRY_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if entry type is Person and its field number is correct
|
||||||
|
} else if (strcmp(csv_getType(&entry),PERSON_TYPE_NAME) == 0) {
|
||||||
|
if (csv_numFields(entry) == PERSON_NUM_FIELDS) {
|
||||||
|
|
||||||
|
// Process could be implemented in a "api_addPerson()" function
|
||||||
|
// as in "api_addVaccineLot()"
|
||||||
|
|
||||||
|
tPerson entryPerson;
|
||||||
|
person_init(&entryPerson);
|
||||||
|
person_parse(&entryPerson,entry);
|
||||||
|
|
||||||
|
// Check if person already exists
|
||||||
|
if (population_find(data->population,entryPerson.document) == -1) {
|
||||||
|
population_add(&(data->population),entryPerson);
|
||||||
|
ret = E_SUCCESS;
|
||||||
|
} else {
|
||||||
|
ret = E_DUPLICATED_PERSON;
|
||||||
|
}
|
||||||
|
|
||||||
|
person_free(&entryPerson);
|
||||||
|
|
||||||
|
} else { // Num fields does not match
|
||||||
|
ret = E_INVALID_ENTRY_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ret = E_INVALID_ENTRY_TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue