aapjeisbaas
(Stein van Broekhoven)
April 24, 2025, 12:23pm
1
Situation
I want to access patient documents through the api.
After some struggles I was able to implement posting files and getting files.
Only I just get the uuid of the files back not the original filename.
[{'docdate': '2025-04-18',
'filename': '9eb49ed5-31d1-4576-a9ef-8c72988398a0',
'id': 341,
'mimetype': 'image/png'},
{'docdate': '2025-04-24',
'filename': '9ec06625-a7b3-4bd5-9cf4-4d14c8d6a77c',
'id': 346,
'mimetype': 'image/png'}]
also in the Content Disposition on the download i just get the uuid in the filename.
OpenEMR Version
I’m using OpenEMR version docker 7.0.3
Question
Is there a way for me to get the filenames from the api?
Or do I need to fall back to scraping the frontend to get the filenames?
aapjeisbaas
(Stein van Broekhoven)
April 24, 2025, 12:41pm
2
Ican get a correct filename from the api if I change the /src/Services/DocumentService.php
getAllAtPath
From
public function getAllAtPath($pid, $path)
{
if (!$this->isValidPath($path)) {
return false;
}
$categoryId = $this->getLastIdOfPath($path);
$documentsSql = " SELECT doc.url, doc.id, doc.mimetype, doc.docdate";
$documentsSql .= " FROM documents doc";
$documentsSql .= " JOIN categories_to_documents ctd on ctd.document_id = doc.id";
$documentsSql .= " WHERE ctd.category_id = ? and doc.foreign_id = ? and doc.deleted = 0";
$documentResults = sqlStatement($documentsSql, array($categoryId, $pid));
$fileResults = array();
while ($row = sqlFetchArray($documentResults)) {
array_push($fileResults, array(
"filename" => basename($row["url"]),
"id" => $row["id"],
"mimetype" => $row["mimetype"],
"docdate" => $row["docdate"]
));
}
return $fileResults;
}
To
public function getAllAtPath($pid, $path)
{
if (!$this->isValidPath($path)) {
return false;
}
$categoryId = $this->getLastIdOfPath($path);
$documentsSql = " SELECT doc.name, doc.id, doc.mimetype, doc.docdate";
$documentsSql .= " FROM documents doc";
$documentsSql .= " JOIN categories_to_documents ctd on ctd.document_id = doc.id";
$documentsSql .= " WHERE ctd.category_id = ? and doc.foreign_id = ? and doc.deleted = 0";
$documentResults = sqlStatement($documentsSql, array($categoryId, $pid));
$fileResults = array();
while ($row = sqlFetchArray($documentResults)) {
array_push($fileResults, array(
"filename" => basename($row["name"]),
"id" => $row["id"],
"mimetype" => $row["mimetype"],
"docdate" => $row["docdate"]
));
}
return $fileResults;
}
API output:
[{'docdate': '2025-04-18',
'filename': 'music.png',
'id': 341,
'mimetype': 'image/png'},
{'docdate': '2025-04-24',
'filename': 'music.png',
'id': 346,
'mimetype': 'image/png'}]
Is it reasonable to open a PR to work on a solution together?