~begerega/ihris-chw-sl/trunk

« back to all changes in this revision

Viewing changes to tools/import_chiefdoms.php

  • Committer: Ese Egerega
  • Date: 2018-05-03 14:17:04 UTC
  • Revision ID: egerega@gmail.com-20180503141704-3br8dto013rgx65x
Initial import of Sierra Leone  CHW registry

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/php
 
2
<?php
 
3
require_once("./import_base.php");
 
4
 
 
5
 
 
6
 
 
7
/*********************************************
 
8
*
 
9
*      Process Class
 
10
*
 
11
*********************************************/
 
12
 
 
13
class InfiniumProcessor extends Processor {
 
14
                
 
15
  protected $create_new_people = null;
 
16
    public function __construct($file) {
 
17
      parent::__construct($file);
 
18
    }
 
19
 
 
20
    protected function mapData() {
 
21
        $mapped_data = parent::mapData();                
 
22
        return $mapped_data;
 
23
    }
 
24
 
 
25
    protected function getExpectedHeaders() {
 
26
        return  array(
 
27
        'province'=>'province',
 
28
        'district'=>'district',
 
29
        'chiefdom'=>'chiefdom',
 
30
            );
 
31
    }
 
32
       protected static $required_cols_by_transaction = array(
 
33
        'NE'=>array('chiefdom')
 
34
        );
 
35
 
 
36
 
 
37
    protected $effective_date;
 
38
    protected function _processRow() {
 
39
        if (!$this->verifyData()) {
 
40
            return false;
 
41
        }
 
42
        $success = false;
 
43
 
 
44
            $persID = $this->addChiefdom();
 
45
return $success;
 
46
    }
 
47
 
 
48
 
 
49
 
 
50
    function verifyData() {
 
51
        
 
52
        $missing_cols = array();
 
53
        foreach (self::$required_cols_by_transaction["NE"] as $required_col) {
 
54
            if ($this->mapped_data[$required_col] === false || (is_string($this->mapped_data[$required_col]) && strlen($this->mapped_data[$required_col]) == 0)) {
 
55
                $missing_cols[] = $required_col;
 
56
            }
 
57
        }
 
58
        if (count($missing_cols) > 0) {
 
59
            $this->addBadRecord("Missing required columns " . implode(" ",$missing_cols));
 
60
                $codearr=explode("-",$this->mapped_data["CHECK_NO"]);
 
61
                if(count($codearr)>1)
 
62
                {
 
63
                $_SESSION["depcode"]=trim($codearr[0]);
 
64
                }    
 
65
            return false;
 
66
        }
 
67
        return true;
 
68
    }
 
69
 
 
70
    function addChiefdom() {
 
71
      $countyObj = $this->ff->createContainer('county');
 
72
      $countyObj->name = ucwords(strtolower(trim($this->mapped_data['chiefdom'])));
 
73
      $countyObj->getField("district")->setFromDB($this->mapped_data['district']);
 
74
                $this->save($countyObj,false);
 
75
    }
 
76
}
 
77
 
 
78
/*********************************************
 
79
*
 
80
*      Execute!
 
81
*
 
82
*********************************************/
 
83
 
 
84
 
 
85
if (count($arg_files) != 1) {
 
86
    usage("Please specify the name of a spreadsheet to process");
 
87
}
 
88
 
 
89
reset($arg_files);
 
90
$file = current($arg_files);
 
91
if($file[0] == '/') {
 
92
    $file = realpath($file);
 
93
} else {
 
94
    $file = realpath($dir. '/' . $file);
 
95
}
 
96
if (!is_readable($file)) {
 
97
    usage("Please specify the name of a spreadsheet to import: " . $file . " is not readable");
 
98
}
 
99
 
 
100
I2CE::raiseMessage("Loading from $file");
 
101
 
 
102
 
 
103
$processor = new InfiniumProcessor($file);
 
104
$processor->run();
 
105
 
 
106
echo "Processing Statistics:\n";
 
107
print_r( $processor->getStats());