def serialize_data(self): """ Mapping data from row data to appointment class """ LOGGER.info("------------------------------") LOGGER.info("| Serialize Data |") LOGGER.info("------------------------------") self.serialized_appointments = [] if self.appointments_data: number = 1 total_count = len(self.appointments_data["SitesScheduledAppointmentsGetResult"]["ScheduledAppointments"]) LOGGER.info("Serializing appointments data. Total count: %s" % (total_count)) for appt in self.appointments_data["SitesScheduledAppointmentsGetResult"]["ScheduledAppointments"]: LOGGER.debug("Serializing appointment (%s of %s)" % (number, total_count)) number += 1 LOGGER.debug("Appointment Id: %s - Raw Data: \n%s" % (appt["AppointmentID"], appt)) appointment = AppointmentData() # Customer ID appointment.customer_id = self.customer_id # Appointment data appointment.altAppointmentId = appt["AppointmentID"] if appt["ScheduleDate"]: appt_date = time.strptime(appt["ScheduleDate"], "%m/%d/%Y") appointment.apptDate = time.strftime("%Y-%m-%d", appt_date) if appt["StartTime"]: appt_time = time.strptime(appt["ScheduleDate"] + appt["StartTime"], "%m/%d/%Y%I:%M:%S %p") appointment.apptTime = time.strftime("%Y-%m-%d %H:%M:%S", appt_time) appointment.apptTypeName = appt["Type"]["Name"] appointment.altApptTypeId = appt["Type"]["AppointmentTypeID"] # Patient data appointment.altPatientId = appt["Patient"]["PatientID"] if appt["Patient"]["FullName"] not in NULLS: name = appt["Patient"]["FullName"].split(",") appointment.fname = name[1] appointment.lname = name[0] elif appt["Patient"]["Firstname"] not in NULLS: appointment.fname = appt["Patient"]["Firstname"] elif appt["Patient"]["LastName"] not in NULLS: appointment.lname = appt["Patient"]["LastName"] if appt["Patient"]["EmailAddress1"] not in NULLS: appointment.email = appt["Patient"]["EmailAddress1"] elif appt["Patient"]["EmailAddress2"] not in NULLS: appointment.email = appt["Patient"]["EmailAddress2"] # Patient's email validating if not is_email_valid(appointment.email): appointment.email = "" # Patient's cell phone is added if appt["Patient"]["PrimaryPhoneNumber"] not in NULLS: appointment.cellPhone = appt["Patient"]["PrimaryPhoneNumber"] elif appt["Patient"]["CellPhoneNumber1"] not in NULLS: appointment.cellPhone = appt["Patient"]["CellPhoneNumber1"] elif appt["Patient"]["CellPhoneNumber2"] not in NULLS: appointment.cellPhone = appt["Patient"]["CellPhoneNumber2"] # Patient's home phone is added if appt["Patient"]["PhoneNumber1"] not in NULLS: appointment.homePhone = appt["Patient"]["PhoneNumber1"] elif appt["Patient"]["PhoneNumber2"] not in NULLS: appointment.homePhone = appt["Patient"]["PhoneNumber2"] # Patient's work phone is added if appt["Patient"]["PrimaryWorkPhone"] not in NULLS: appointment.workPhone = appt["Patient"]["PrimaryWorkPhone"] appointment.pagerNo = appt["Patient"]["PagerNumber"] # Patient's Address mapping. if appt["Patient"]["ResidentialAddress"] not in NULLS: if appt["Patient"]["ResidentialAddress"]["AddressLine1"] not in NULLS: appointment.address = appt["Patient"]["ResidentialAddress"]["AddressLine1"] elif appt["Patient"]["ResidentialAddress"]["AddressLine2"] not in NULLS: appointment.address += " " + appt["Patient"]["ResidentialAddress"]["AddressLine2"] if appt["Patient"]["ResidentialAddress"]["City"] not in NULLS: appointment.city = appt["Patient"]["ResidentialAddress"]["City"] if appt["Patient"]["ResidentialAddress"]["State"] not in NULLS: appointment.state = appt["Patient"]["ResidentialAddress"]["State"] if appt["Patient"]["ResidentialAddress"]["PostalCode"] not in NULLS: appointment.zip = appt["Patient"]["ResidentialAddress"]["PostalCode"] if appt["Patient"]["PrimaryLanguage"] not in NULLS: appointment.language = appt["Patient"]["PrimaryLanguage"] if appt["Patient"]["DateOfBirth"] not in NULLS: dob = re.findall(r"\/\w+\S(\-?\d+)", appt["Patient"]["DateOfBirth"])[ 0 ] # trying to parse '/Date(223432432432-4400)/ and /Date(-223432432432-4400)/' if dob[0] == "-": dob = dob[1:] dob = time.gmtime(long(dob) / 1000) appointment.dateOfBirth = time.strftime("%Y-%m-%d", dob) appointment.guarantorID = appt["Patient"]["GuarantorID"] # Doctor data appointment.altDoctorId = appt["Resource"]["OwnerCareProviderID"] if appt["Resource"]["Name"]: appointment.doctorName = appt["Resource"]["Name"] if appointment.doctorName.find("Dr") == -1: appointment.doctorName = "Dr. " + appointment.doctorName else: appointment.doctorName = "the staff" # Facility data appointment.altFacilityId = appt["ScheduleLocation"]["ScheduleLocationID"] appointment.facilityName = appt["ScheduleLocation"]["Name"] appointment.facilityAddr = appt["ScheduleLocation"]["CareProviderLocation"]["Address"] appointment.normalize() LOGGER.debug( "Appointment ID: %s, serialized result: \n%s" % (appointment.altAppointmentId, appointment.__dict__) ) self.serialized_appointments.append(appointment) return self.serialized_appointments