def serialize_data(self): """Serializes appointment data. Returns list of AppointmentData objects.""" LOGGER.info('------------------------------') LOGGER.info('| Serialize Data |') LOGGER.info('------------------------------') self.serialized_appointments = [] i = 1 total = len(self.appointments_data) LOGGER.info('Serializing appointments data. Total count: %i', total) for appt in self.appointments_data: LOGGER.info('Serializing appointment (%i of %i)', i, total) i = i + 1 appointment = AppointmentData() LOGGER.debug('\tAppointment Id: %s - Raw Data: \n%s', appt.get('altAppointmentId'), ET.tostring(appt)) LOGGER.info('\tAlt appointment id: %s', appt.get('altAppointmentId')) # Customer ID appointment.customer_id = self.customer_id # ================ # Appointment data # ================ appointment.altAppointmentId = appt.get('altAppointmentId') appt_date_time = appt.get('apptDateTime') if (appt_date_time): date_time = datetime.strptime(appt_date_time, "%Y-%m-%dT%H:%M:%S") # Convert string(2012-09-26T10:00:00) to datetime object appointment.apptDate = date_time.strftime("%Y-%m-%d") appointment.apptTime = date_time.strftime("%Y-%m-%d %H:%M:%S") appointment.apptTypeName = appt.get('apptTypeName').title() #TODO: confirm if apptType="RefReason" can be used appointment.altApptTypeId = appt.get('apptTypeName').title() (status_id, conformation_id, appt_kept, reschdeuled) = AMDStatusLookup.get_appointment_status_info(appt.get('apptStatusId')) appointment.apptStatusId = status_id appointment.apptConformationId = conformation_id appointment.apptKept = appt_kept appointment.reschedule = reschdeuled # ============= # Facility data # ============= appointment.altFacilityId = appt.get('altFacilityId') appointment.facilityName = appt.get('facilityName').title() #TODO: Facility id is empty for Advanced MD, confirm appointment.facilityAddr = "" # ============ # Patient data # ============ appointment.altPatientId = appt.get('altPatientId') appt_patient = appt.find('patientlist/patient') appointment.fname = appt_patient.get('fname').title() appointment.lname = appt_patient.get('lname').title() if (is_email_valid(appt_patient.get('email'))): # Validate email appointment.email = appt_patient.get('email').lower() if (AMDStatusLookup.is_cell_phone(appt_patient.get('otherPhoneType'))): appointment.cellPhone = appt_patient.get('cellPhone') #TODO: Handle empty workPhone and homePhone appointment.homePhone = appt_patient.get('homePhone') appointment.workPhone = appt_patient.get('workPhone') appointment.workPhoneExt = appt_patient.get('workPhoneExt') appointment.address = (appt_patient.get('address1') + ' ' + appt_patient.get('address2')).title() appointment.city = appt_patient.get('city').title() appointment.state = appt_patient.get('state').upper() appointment.zip = appt_patient.get('zip') appointment.language = appt_patient.get('language').strip() if appointment.language in NULLS: appointment.language = "ENG" if(appt_patient.get('dateOfBirth')): dob = datetime.strptime(appt_patient.get('dateOfBirth'), "%Y-%m-%dT%H:%M:%S") appointment.dateOfBirth = dob.strftime("%Y-%m-%d") # ============== # Guarantor data # ============== appointment.guarantorID = appt_patient.get('altGuarantorId') appointment.gFname = appt_patient.get('rpFname').title() appointment.gLname = appt_patient.get('rpLname').title() appointment.gAddress = (appt_patient.get('rpAddress1') + ' ' + appt_patient.get('rpAddress2')).title() appointment.gZip = appt_patient.get('rpZip') appointment.gCity = appt_patient.get('rpCity').title() appointment.gState = appt_patient.get('rpState').upper() appointment.gWorkPhone = appt_patient.get('rpWorkPhone') appointment.gHomePhone = appt_patient.get('rpHomePhone') if (AMDStatusLookup.is_cell_phone(appt_patient.get('rpOtherPhoneType'))): appointment.gCellPhone = appt_patient.get('rpCellPhone') #TODO: Handle empty workPhone and homePhone if (is_email_valid(appt_patient.get('rpEmail'))): # Validate email appointment.gEmail = appt_patient.get('rpEmail').lower() if(appt_patient.get('rpDob')): # "1945-11-14T00:00:00" dob = datetime.strptime(appt_patient.get('rpDob'), "%Y-%m-%dT%H:%M:%S") appointment.gDob = dob.strftime("%Y-%m-%d") # =========== # Doctor data # =========== appointment.altDoctorId = appt_patient.get('altDoctorId') appointment.doctorName = (appt_patient.get('drFname') + ' ' + appt_patient.get('drLname')).title() # Get doctor titled name appointment.doctorName = AMDStatusLookup.get_dr_titled_name(appt_patient.get('drTitle'), appointment.doctorName) appointment.normalize() LOGGER.debug('Appointment ID: %s, serialized result:\n%s', appt.get('altAppointmentId'), json.dumps(appointment.__dict__)) self.serialized_appointments.append(appointment) return self.serialized_appointments