# Standard api document file names

**URL:** <https://community.open-emr.org/t/standard-api-document-file-names/25368>\
**Category:** Support\
**Tags:** standard\_api\
**Created:** [April 24, 2025, 12:23pm UTC](https://community.open-emr.org/t/standard-api-document-file-names/25368 "2025-04-24T12:23:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aapjeisbaas](https://community.open-emr.org/user_avatar/community.open-emr.org/aapjeisbaas/32/11972_2.png) [@aapjeisbaas](https://community.open-emr.org/u/aapjeisbaas)\
**Post date:** [April 24, 2025, 12:23pm UTC](https://community.open-emr.org/t/standard-api-document-file-names/25368/1 "2025-04-24T12:23:56Z")

</div>

**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.

```auto
[{'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?

---

<div class="post-metadata">

**Author:** ![aapjeisbaas](https://community.open-emr.org/user_avatar/community.open-emr.org/aapjeisbaas/32/11972_2.png) [@aapjeisbaas](https://community.open-emr.org/u/aapjeisbaas)\
**Post date:** [April 24, 2025, 12:41pm UTC](https://community.open-emr.org/t/standard-api-document-file-names/25368/2 "2025-04-24T12:41:14Z")

</div>

Ican get a correct filename from the api if I change the `/src/Services/DocumentService.php` `getAllAtPath`

**From**

```auto
    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**

```auto
    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:

```auto
[{'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?
