Skip to content

Commit

Permalink
Encounter Merging tool (#551)
Browse files Browse the repository at this point in the history
* Encounter Merging tool
  • Loading branch information
aethelwulffe authored and Tony McCormick committed Jun 1, 2017
1 parent e09edb8 commit 3779f45
Show file tree
Hide file tree
Showing 18 changed files with 3,055 additions and 0 deletions.
52 changes: 52 additions & 0 deletions modules/merge_encounters/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
*
* Copyright (c) 2016 Sam Likins WSI-Services
* Copyright (c) 2016 SunCoast Connection
*
* LICENSE: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0
* See the Mozilla Public License for more details.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* @package Librehealth EHR
* @author Sam Likins <[email protected]>
* @link http://suncoastconnection.com
* @link http://librehealth.io
*
* Please help the overall project by sending changes you make to the author and to the LibreEHR community.
*
*/

$sanitize_all_escapes = true;
$fake_register_globals = false;

require_once('../../interface/globals.php');
require_once($srcdir.'/acl.inc');

if(!acl_check('admin', 'super')) {
die(xlt('Not authorized'));
} else {
define('MERGE_ENCOUNTERS', true);
}

require_once(__DIR__.'/lib/functions.php');

$service = getElementIfExist($_GET, 'service', null);

switch($service) {
case 'json-duplicates':
includeService('JSON-Duplicates');
break;

case 'json-encounters':
includeService('JSON-Encounters');
break;

case 'json-merge':
includeService('JSON-Merge');
break;

case null:
includeService('Screen');
break;
}
118 changes: 118 additions & 0 deletions modules/merge_encounters/lib/JsonHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/**
*
* Copyright (c) 2016 Sam Likins WSI-Services
* Copyright (c) 2016 SunCoast Connection
*
* LICENSE: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0
* See the Mozilla Public License for more details.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* @package Librehealth EHR
* @author Sam Likins <[email protected]>
* @link http://suncoastconnection.com
* @link http://librehealth.io
*
* Please help the overall project by sending changes you make to the author and to the LibreEHR community.
*
*/

const JSON_STATUS_OK = 1;
const JSON_STATUS_SUCCESS = 2;
const JSON_STATUS_FAIL = 3;

// JSON Handler

class JsonHandler {

protected static $jsonStatusMessages = [
JSON_STATUS_OK => 'OK',
JSON_STATUS_SUCCESS => 'SUCCESS',
JSON_STATUS_FAIL => 'FAIL',
];

public static function encode($value, $options = 0) {
$result = json_encode($value, $options);

if($result) {
return $result;
}

throw new RuntimeException(json_last_error_msg(), json_last_error());
}

public static function decode($json, $assoc = false) {
$result = json_decode($json, $assoc);

if($result) {
return $result;
}

throw new RuntimeException(json_last_error_msg(), json_last_error());
}

protected $status;

protected $errors = [];

protected $data;

public function __construct($status = JSON_STATUS_OK) {
$this->setStatus($status);
}

public function setStatus($status) {
if(array_key_exists($status, static::$jsonStatusMessages)) {
$this->status = $status;
}
}

public function getStatus() {
return $this->status;
}

public function addError($error) {
$this->errors[] = $error;
}

public function getErrors() {
return $this->errors;
}

public function setData($data) {
$this->data = $data;
}

public function &getData() {
return $this->data;
}

public function response($options = 0) {
try {
if(array_key_exists($this->getStatus(), static::$jsonStatusMessages)) {
$status = static::$jsonStatusMessages[$this->getStatus()];
} else {
$status = static::$jsonStatusMessages[JSON_STATUS_FAIL];
}

$return = [
'status' => $status,
'errors' => $this->getErrors(),
'data' => $this->getData()
];

array_walk_recursive($return, function(&$item) {
$item = utf8_encode($item);
});

$return = static::encode($return, $options);

header('Content-type: application/json;charset=utf-8');
} catch (RuntimeException $exception) {
$return = $exception->getMessage();
}

echo $return;
}

}
63 changes: 63 additions & 0 deletions modules/merge_encounters/lib/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
*
* Copyright (c) 2016 Sam Likins WSI-Services
* Copyright (c) 2016 SunCoast Connection
*
* LICENSE: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0
* See the Mozilla Public License for more details.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* @package Librehealth EHR
* @author Sam Likins <[email protected]>
* @link http://suncoastconnection.com
* @link http://librehealth.io
*
* Please help the overall project by sending changes you make to the author and to the LibreEHR community.
*
*/

function getElementIfExist(&$array, $key, $default = null) {
if(array_key_exists($key, $array)) {
return $array[$key];
} else {
return $default;
}
}

function includeService($service) {
$service = realpath(__DIR__.'/../service').'/'.$service.'.php';

if(file_exists($service)) {
include($service);
}
}

function pathToResource($resourceName, $version = false) {
$path = './resource/';

if(file_exists(__DIR__.'/.'.$path.$resourceName)) {
return $path.$resourceName.(
$version
? '?v='.(
$version === true
? time()
: $version
)
: ''
);
}
}

function getDatabaseConnection() {
global $sqlconf;

try {
$databaseConnection = new PDO('mysql:host='.$sqlconf['host'].';dbname='.$sqlconf['dbase'], $sqlconf['login'], $sqlconf['pass']);
$databaseConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $exception) {
echo 'ERROR: ' . $exception->getMessage();
}

return $databaseConnection;
}
9 changes: 9 additions & 0 deletions modules/merge_encounters/merge_encounter_docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# LibreHealthEHR Merge Encounters

## Technologies Used

- [JQuery|https://jquery.com]
- [KnockOutJS|http://knockoutjs.com]
- [KoGrid|https://knockout-contrib.github.io/KoGrid]
- [Split-Pane|https://github.com/shagstrom/split-pane]
- [KoSortingTable|http://develothink.com/sorting-tables-using-knockoutjs]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Merge Encounters User Documentation.

This is a stub.
Loading

0 comments on commit 3779f45

Please sign in to comment.