SELECT
	'E' AS `patient_type`,
	`patients`.`id` AS `id`,
	`patients`.`patient_unique_id` AS `patient_unique_id`,
	`patients`.`title` AS `patient_title`,
	`patients`.`patient_name` AS `patient_name`,
	`patients`.`first_name` AS `first_name`,
	`patients`.`last_name` AS `last_name`,
	`patients`.`age` AS `age_year`,
	`patients`.`month` AS `age_month`,
	`patients`.`days` AS `age_days`,
	`patients`.`dob` AS `dob`,
	`patients`.`gender` AS `gender`,
	`patients`.`marital_status` AS `marital_status`,
	`patients`.`blood_group` AS `blood_group`,
	`contacts`.`contact_details` AS `contact_details`,
	`email`.`contact_details` AS `email`,
	`addresses`.`pin` AS `pin`,
	concat_ws( ' ', `addresses`.`house_no`, `addresses`.`street` ) AS `street`,
	`addresses`.`locality` AS `locality` 
FROM
	(((
				`patients`
				LEFT JOIN `contacts` ON (((
							`contacts`.`data_source_id` = `patients`.`id` 
							) 
						AND ( `contacts`.`data_source` = 'Patient' ) 
						AND ( `contacts`.`contact_type` = 'M' ) 
					AND ( `contacts`.`is_active` = 'Y' ))))
			LEFT JOIN `contacts` `email` ON (((
						`email`.`data_source_id` = `patients`.`id` 
						) 
					AND ( `email`.`data_source` = 'Patient' ) 
				AND ( `email`.`contact_type` = 'E' ))))
		LEFT JOIN `addresses` ON (((
					`addresses`.`data_source_id` = `patients`.`id` 
					) 
				AND ( `addresses`.`data_source` = 'Patient' ) 
			AND ( `addresses`.`address_type` = 'P' )))) UNION
SELECT
	'W' AS `W`,
	`pharmacy_walkin_patient`.`id` AS `id`,
	'' AS `Name_exp_3`,
	'' AS `Name_exp_4`,
	`pharmacy_walkin_patient`.`patient_name` AS `patient_name`,
	'' AS `Name_exp_6`,
	'' AS `Name_exp_7`,
	'' AS `Name_exp_8`,
	'' AS `Name_exp_9`,
	'' AS `Name_exp_10`,
	'' AS `Name_exp_11`,
	'' AS `Name_exp_12`,
	'' AS `Name_exp_13`,
	'' AS `Name_exp_14`,
	`pharmacy_walkin_patient`.`patient_contact` AS `patient_contact`,
	'' AS `Name_exp_16`,
	'' AS `Name_exp_17`,
	'' AS `Name_exp_18`,
	'' AS `Name_exp_19` 
FROM
	`pharmacy_walkin_patient`