Skip to content

Commit

Permalink
Dicom Rework (openemr#3731)
Browse files Browse the repository at this point in the history
* Dicom Rework

* - bells and whistles

* - add dicom folder upload
  • Loading branch information
sjpadgett authored Jul 12, 2020
1 parent 8884c3f commit 5250fc6
Show file tree
Hide file tree
Showing 40 changed files with 4,564 additions and 873 deletions.
16 changes: 0 additions & 16 deletions API_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Finally, APIs which are integrated with the new `handleProcessingResult` method
- [Facility API](API_README.md#post-apifacility)
- [Practitioner API](API_README.md#get-apipractitioner)
- [Patient API](API_README.md#post-apipatient)
- [Immunization API](API_README.md#get-apiimmunization)
- [Insurance API](API_README.md#get-apipatientpidinsurance)
- [Appointment API](API_README.md#get-apiappointment)
- [Document API](API_README.md#get-apipatientpiddocument)
Expand Down Expand Up @@ -501,21 +500,6 @@ Response:
}
}
```
#### GET /api/immunization

Request:

```sh
curl -X GET 'http://localhost:8300/apis/api/immunization'
```

#### GET /api/immunization/:uuid

Request:

```sh
curl -X GET 'http://localhost:8300/apis/api/immunization/90cde167-7b9b-4ed1-bd55-533925cb2605'
```

#### POST /api/patient/:pid/encounter

Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ You will need a "local" version of OpenEMR to make changes to the source code. T

1. [Create your own fork of OpenEMR](https://github.com/openemr/openemr/fork) (you will need a GitHub account) and `git clone` it to your local machine.
- It's best to also add an `upstream` origin to keep your local fork up to date. [Check out this guide](https://oneemptymind.wordpress.com/2018/07/11/keeping-a-fork-up-to-date/) for more info.
- If you haven't already, [install git](https://git-scm.com/downloads) for your system
2. `cd openemr` (the directory you cloned the code into)
- If you haven't already, [install Docker](https://docs.docker.com/install/) and [install compose](https://docs.docker.com/compose/install/) for your system
- If you haven't already, [install Docker](https://docs.docker.com/install/) for your system
3. Run `docker-compose up` from your command line
- When the build is done, you'll see the following message:
```sh
Expand Down
37 changes: 17 additions & 20 deletions FHIR_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Database Result -> Service Component -> FHIR Service Component -> Parse OpenEMR
- [FHIR Encounter API](FHIR_README.md#get-fhirencounter)
- [FHIR Practitioner API](FHIR_README.md#get-fhirpractitioner)
- [FHIR PractitionerRole API](FHIR_README.md#get-fhirpractitionerrole)
- [FHIR Immunization API](FHIR_README.md#get-fhirimmunization)
- [FHIR Organization API](FHIR_README.md#get-fhirorganization)
- [FHIR AllergyIntolerance API](FHIR_README.md#get-fhirallergyintolerance)
- [FHIR Observation API](FHIR_README.md#get-fhirobservation)
- [FHIR QuestionnaireResponse API](FHIR_README.md#get-fhirquestionnaireresponse)
- [FHIR Immunization API](FHIR_README.md#get-fhirimmunization)
- [FHIR Condition API](FHIR_README.md#get-fhircondition)
- [FHIR Procedure API](FHIR_README.md#get-fhirprocedure)
- [FHIR MedicationStatement API](FHIR_README.md#get-fhirmedicationstatement)
Expand Down Expand Up @@ -321,25 +321,6 @@ curl -X GET 'http://localhost:8300/apis/fhir/PractitionerRole/90de091a-91e9-4bbe
- speciality
- practitioner

#### GET [base]/Immunization

Request:

```sh
curl -X GET 'http://localhost:8300/apis/fhir/Immunization'
```

#### GET [base]/Immunization/:id

Request:

```sh
curl -X GET 'http://localhost:8300/apis/fhir/Immunization/90feaaa2-4097-4437-966e-c425d1958dd6'
```

- Supported Search Parameters
- patient

#### GET /fhir/Organization

Request:
Expand Down Expand Up @@ -421,6 +402,22 @@ curl -X POST -H 'Content-Type: application/fhir+json' 'http://localhost:8300/api
}'
```

#### GET /fhir/Immunization

Request:

```sh
curl -X GET 'http://localhost:8300/apis/fhir/Immunization'
```

#### GET /fhir/Immunization/:id

Request:

```sh
curl -X GET 'http://localhost:8300/apis/fhir/Immunization/1'
```

#### GET /fhir/Condition

Request:
Expand Down
13 changes: 2 additions & 11 deletions _rest_routes.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use OpenEMR\RestControllers\AuthRestController;
use OpenEMR\RestControllers\ONoteRestController;
use OpenEMR\RestControllers\DocumentRestController;
use OpenEMR\RestControllers\ImmunizationRestController;
use OpenEMR\RestControllers\InsuranceRestController;
use OpenEMR\RestControllers\MessageRestController;

Expand Down Expand Up @@ -346,14 +345,6 @@
RestConfig::authorization_check("patients", "notes");
return (new MessageRestController())->delete($pid, $mid);
},
"GET /api/immunization" => function () {
RestConfig::authorization_check("patients", "med");
return (new ImmunizationRestController())->getAll($_GET);
},
"GET /api/immunization/:id" => function ($id) {
RestConfig::authorization_check("patients", "med");
return (new ImmunizationRestController())->getOne($id);
},

);

Expand Down Expand Up @@ -474,11 +465,11 @@
},
"GET /fhir/Immunization" => function () {
RestConfig::authorization_check("patients", "med");
return (new FhirImmunizationRestController())->getAll($_GET);
return (new FhirImmunizationRestController(null))->getAll($_GET);
},
"GET /fhir/Immunization/:id" => function ($id) {
RestConfig::authorization_check("patients", "med");
return (new FhirImmunizationRestController())->getOne($id);
return (new FhirImmunizationRestController(null))->getOne($id);
},
"GET /fhir/Condition" => function () {
RestConfig::authorization_check("patients", "med");
Expand Down
40 changes: 40 additions & 0 deletions controllers/C_Document.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,33 @@ function upload_action($patient_id, $category_id)
return $this->list_action($patient_id);
}

function zip_dicom_folder($study_name = null)
{
$zip = new ZipArchive();
$zip_name = $GLOBALS['temporary_files_dir'] . "/" . $study_name;
if ($zip->open($zip_name, (ZipArchive::CREATE | ZipArchive::OVERWRITE)) === true) {
foreach ($_FILES['dicom_folder']['name'] as $i => $name) {
$zfn = $GLOBALS['temporary_files_dir'] . "/" . $name;
move_uploaded_file($_FILES['dicom_folder']['tmp_name'][$i], $zfn);
$fparts = explode(".", $zfn);
$fext = strtolower(end($fparts));
// disregard other file ext's
if ($fext == 'dcm') {
$zip->addFile($zfn, $name);
}
}
$zip->close();
} else {
return false;
}
$file_array['name'][] = $study_name;
$file_array['type'][] = 'zip';
$file_array['tmp_name'][] = $zip_name;
$file_array['error'][] = '';
$file_array['size'][] = filesize($zip_name);
return $file_array;
}

//Upload multiple files on single click
function upload_action_process()
{
Expand Down Expand Up @@ -167,6 +194,19 @@ function upload_action_process()
$patient_id = $_POST['patient_id'];
}

if (!empty($_FILES['dicom_folder']['name'][0])) {
// let's zip um up then pass along new zip
$study_name = $_POST['destination'] ? (trim($_POST['destination']) . ".zip") : 'DicomStudy.zip';
$study_name = preg_replace('/\s+/', '_', $study_name);
$_POST['destination'] = "";
$zipped = $this->zip_dicom_folder($study_name);
if ($zipped) {
$_FILES['file'] = $zipped;
}
// and off we go! just fall through and let routine
// do its normal file processing..
}

$sentUploadStatus = array();
if (count($_FILES['file']['name']) > 0) {
$upl_inc = 0;
Expand Down
8 changes: 0 additions & 8 deletions interface/patient_file/summary/immunizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use OpenEMR\Common\Csrf\CsrfUtils;
use OpenEMR\Common\Logging\EventAuditLogger;
use OpenEMR\Common\Uuid\UuidRegistry;
use OpenEMR\Core\Header;

if (isset($_GET['mode'])) {
Expand All @@ -32,7 +31,6 @@
if ($_GET['mode'] == "add") {
$sql = "REPLACE INTO immunizations set
id = ?,
uuid = ?,
administered_date = if(?,?,NULL),
immunization_id = ?,
cvx_code = ?,
Expand All @@ -58,7 +56,6 @@
ordering_provider = ?";
$sqlBindArray = array(
trim($_GET['id']),
UuidRegistry::isValidStringUUID($_GET['uuid']) ? UuidRegistry::uuidToBytes($_GET['uuid']) : null,
trim($_GET['administered_date']), trim($_GET['administered_date']),
trim($_GET['form_immunization_id']),
trim($_GET['cvx_code']),
Expand Down Expand Up @@ -111,10 +108,6 @@
$result = sqlQuery($sql, array($_GET['id']));

$administered_date = new DateTime($result['administered_date']);
$uuid = null;
if (isset($result['uuid']) && !UuidRegistry::isEmptyBinaryUUID($result['uuid'])) {
$uuid = UuidRegistry::uuidToString($result['uuid']);
}
$administered_date = $administered_date->format('Y-m-d H:i');

$immuniz_amt_adminstrd = $result['amount_administered'];
Expand Down Expand Up @@ -353,7 +346,6 @@ function saveImmunizationObservationResults($id, $immunizationdata)
<input type="hidden" name="mode" id="mode" value="add">
<input type="hidden" name="id" id="id" value="<?php echo attr($id); ?>">
<input type="hidden" name="pid" id="pid" value="<?php echo attr($pid); ?>">
<input type="hidden" name="uuid" id="uuid" value="<?php echo attr($uuid); ?>">
<br />
<table border=0 cellpadding=1 cellspacing=1>
<?php
Expand Down
53 changes: 48 additions & 5 deletions library/ajax/upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
* @link https://www.open-emr.org
* @author Sherwin Gaddis <sherwingaddis@gmail.com>
* @author Brady Miller <brady.g.miller@gmail.com>
* @author Jerry Padgett <sjpadgett@gmail.com>
* @copyright Copyright (c) 2017 Sherwin Gaddis <sherwingaddis@gmail.com>
* @copyright Copyright (c) 2018 Brady Miller <brady.g.miller@gmail.com>
* @copyright Copyright (c) 2020 Jerry Padgett <sjpadgett@gmail.com>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

Expand All @@ -17,19 +19,60 @@

use OpenEMR\Common\Csrf\CsrfUtils;

if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
if (!CsrfUtils::verifyCsrfToken($_REQUEST["csrf_token_form"])) {
CsrfUtils::csrfNotVerified();
}

// check if this is for dicom image maintenance.
$action = $_POST['action'] ?? null;
$doc_id = (int)$_POST['doc_id'] ?? null;
$json_data = $_POST['json_data'] ?? null;

if ($action == 'save') {
//$data = json_decode($json_data, true);
//$json_data = base64_encode($data);
$pass_it = dicom_history_action($action, $doc_id, $json_data);
if ($pass_it === 'false') {
// query success. send back a translated message for user.
echo xlj("Server says thanks. Images state saved.");
} else {
echo xlj("Error! Images state save failed.");
}

exit();
}
if ($action == 'fetch') {
$json_data = dicom_history_action($action, $doc_id);
echo $json_data;

exit();
}
// nope! so continue on with Sherwins uploader.
$patient_id = filter_input(INPUT_GET, 'patient_id');
$category_id = filter_input(INPUT_GET, 'parent_id');

if (!empty($_FILES)) {
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$name = $_FILES['file']['name'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];
$owner = $GLOBALS['userauthorized'];
$size = $_FILES['file']['size'];
$owner = $GLOBALS['userauthorized'];

addNewDocument($name, $type, $tmp_name, $error, $size, $owner, $patient_id, $category_id);
exit();
}

function dicom_history_action($action, $doc_id, $json_data = '')
{
if ($action == 'save') {
$json_data = base64_encode($json_data);
return json_encode(sqlQuery("UPDATE documents SET document_data = ? WHERE id = ?", array($json_data, $doc_id)));
}

if ($action == 'fetch') {
$qrtn = sqlQuery("Select document_data FROM documents WHERE id = ?", array($doc_id));
return base64_decode($qrtn['document_data']);
}

return xlj("Unknown");
}
Loading

0 comments on commit 5250fc6

Please sign in to comment.