Skip to content

Commit

Permalink
chore: enable EMR debug option (#88)
Browse files Browse the repository at this point in the history
* implement debug option

* add changeset
  • Loading branch information
mustofa-id authored May 17, 2024
1 parent 7f6de5f commit 22a02d5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/pretty-parents-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ssecd/jkn": patch
---

add debug option for EMR API
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules
.env
.env.*
!.env.example
/debug
31 changes: 30 additions & 1 deletion src/rekam-medis/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { existsSync, mkdirSync } from 'fs';
import { writeFile } from 'fs/promises';
import { inspect } from 'util';
import { BaseApi } from '../base.js';
import { Config } from '../fetcher.js';
import { MRBundle } from './types.js';
Expand Down Expand Up @@ -26,9 +29,32 @@ export class RekamMedis extends BaseApi<'rekamMedis'> {
* secara otomatis pada method ini
*/
dataRekamMedis: MRBundle;

/** log `dataMR` request data ke console atau file */
debug?: 'console' | 'file';
}) {
const config = await this.requiredConfig('ppkCode');
const dataMR = await preprocess(data.dataRekamMedis, config);

if (config.mode === 'development' && data.debug) {
const result = {
...data,
dataMR,
dataMRPlain: data.dataRekamMedis,
dataRekamMedis: undefined
};

if (data.debug === 'console') {
console.debug(inspect(result, false, null, true));
} else if (data.debug === 'file') {
if (!existsSync('debug')) mkdirSync('debug');
writeFile(
`debug/JKN_MR_BUNDLE_${data.nomorSEP}.json`,
JSON.stringify(result, null, 2)
).catch(console.error);
}
}

return this.send<{ keterangan: string }>({
path: `/eclaim/rekammedis/insert`,
method: 'POST',
Expand All @@ -54,7 +80,10 @@ export class RekamMedis extends BaseApi<'rekamMedis'> {
* dan KODE PPK. Ini berdasarkan spesifikasi yang telah ditentukan
* pada halaman TrustMark BPJS Kesehatan.
*/
async function preprocess(data: MRBundle, { consId, consSecret, ppkCode }: Config): Promise<string> {
async function preprocess(
data: MRBundle,
{ consId, consSecret, ppkCode }: Config
): Promise<string> {
try {
const value = JSON.stringify(data);
const compressed = await gzip(value);
Expand Down
1 change: 1 addition & 0 deletions test/rekam-medis/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe(
tahun: 2023,
jenisPelayanan: '2',
nomorSEP: '0089S0020523V000001',
debug: 'file',
dataRekamMedis: {
resourceType: 'Bundle',
id: '123456',
Expand Down

0 comments on commit 22a02d5

Please sign in to comment.