Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function destination_vaccinations ( $attrs = [], $content = null, $tag = '' ) {
- $attrs = array_change_key_case((array) $attrs, CASE_LOWER);
- $shortcode_attrs = shortcode_atts(array(
- 'api_id' => ( $this->_isset($_REQUEST, 'api_id') ) ? $_REQUEST['api_id'] : null,
- 'country_name' => ( $this->_isset($_REQUEST, 'country_name') ) ? $_REQUEST['country_name'] : null,
- ), $attrs, $tag);
- $api = $this->_get_api($shortcode_attrs['api_id']);
- if ( is_bool($api) ) {
- return '';
- }
- $countriesArray = $api->get_countries();
- $searchedValue = $shortcode_attrs['country_name'];
- $neededCountryObject = current(array_filter(
- $countriesArray,
- function ($e) use (&$searchedValue) {
- return strpos($e->Name, $searchedValue) !== false;
- // return $e->Name == $searchedValue;
- }
- ));
- // var_dump($countriesArray);
- if($neededCountryObject) {
- $vaccinationRecommendations = current($api->find_vaccination_recommendations( $neededCountryObject->Id ));
- $diseasesRaw = $vaccinationRecommendations->Diseases;
- $recommendationsRaw = $vaccinationRecommendations->Categories[1]->Recommendations;
- $diseases = $mandatory = $recommended = $consider = array();
- foreach($diseasesRaw as $disease)
- $diseases[ $disease->DiseaseId ] = $disease->Title;
- foreach($recommendationsRaw as $recommendation) {
- switch($recommendation->Level) {
- case 'Mandatory':
- $mandatory[ $recommendation->DiseaseId ] = $diseases[ $recommendation->DiseaseId ];
- break;
- case 'Recommended':
- $recommended[ $recommendation->DiseaseId ] = $diseases[ $recommendation->DiseaseId ];
- break;
- case 'Consider':
- $consider[ $recommendation->DiseaseId ] = $diseases[ $recommendation->DiseaseId ];
- break;
- }
- }
- $associationArray = array(
- 13 => 199, // Hepatitis A
- 2 => 151, // Typhoid
- 9 => 172, // Japanese encephalitis
- 24 => 163, // Rabies
- 27 => 160, // Diphtheria
- 16 => 160, // Tetanus,
- 23 => 160, // Polio,
- 6 => 200, // Cholera
- 14 => 174, // Hepatitis B
- 10 => 145, // Yellow Fever
- 21 => 169, // Meningitis ACWY
- // 28 => // Tuberculosis -> missing on LTC
- );
- $compiledRecommended = array();
- $compiledConsider = array();
- $resultRecommended = array();
- $resultConsider = array();
- if($mandatory)
- foreach($mandatory as $xmedicusId => $disease)
- $compiledRecommended[] = $xmedicusId;
- if($recommended)
- foreach($recommended as $xmedicusId => $disease)
- $compiledRecommended[] = $xmedicusId;
- if($consider)
- foreach($consider as $xmedicusId => $disease)
- $compiledConsider[] = $xmedicusId;
- if($compiledRecommended) {
- foreach($compiledRecommended as $xmedicusId) {
- if($associationArray[ $xmedicusId ])
- $resultRecommended[] = $associationArray[ $xmedicusId ];
- }
- }
- if($compiledConsider) {
- foreach($compiledConsider as $xmedicusId) {
- if($associationArray[ $xmedicusId ])
- $resultConsider[] = $associationArray[ $xmedicusId ];
- }
- }
- $resultRecommended = array_unique($resultRecommended);
- $resultsConsider = array_unique($resultConsider);
- // echo '<pre>';
- // var_dump($resultRecommended);
- // echo '</pre>';
- // echo '<pre>';
- // var_dump($resultConsider);
- // echo '</pre>';
- $mkey = 'vaccines_all_visitors';
- include(dirname( __FILE__ ) . '/templates/destination/listing-destination.php');
- $mkey = 'vaccines_some_visitors';
- include(dirname( __FILE__ ) . '/templates/destination/listing-destination.php');
- // foreach($recommended as $vaccine_name) {
- // $args = array(
- // 'xm_search_post_title' => $vaccine_name, // search post title only
- // 'post_status' => 'publish',
- // 'post_type' => 'disease'
- // );
- // add_filter( 'posts_where', array( $this, 'post_title_filter' ), 10, 2 );
- // $query = new \WP_Query( $args );
- // remove_filter( 'posts_where', array( $this, 'post_title_filter' ), 10, 2 );
- // if($query->have_posts()) {
- // while($query->have_posts()) {
- // $query->the_post();
- // echo get_permalink() . '<br>';
- // }
- // wp_reset_query();
- // }
- // }
- // // delete_transient('xm_popup_booking');
- // if(get_transient('xm_popup_booking') === false) {
- // $data = array();
- // $units = $api->organization_units(null, null, 40);
- // foreach($units as $unit) {
- // $resources = $api->get_resources($unit->Id);
- // foreach($resources as $resource) {
- // $resource_treatments = $api->get_treatments($resource->Id, $people);
- // $data[ $unit->Name ] = $resource_treatments;
- // // var_dump($unit->Name);
- // // var_dump($resource_treatments);
- // }
- // }
- // // Store data in transient, expire after 1 week
- // set_transient('xm_popup_booking', $data, 7 * 24 * HOUR_IN_SECONDS);
- // }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement