-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* register to fetcher * add env example entry * api definition * add ppk code configuration * expose config on fetcher and base api * data compression and encryption * initial rekam medis data types * define type using @types/fhir * update docs * use fhir v4 * add changeset * add fhir type docs
- Loading branch information
1 parent
6fa2b64
commit 13cbb7d
Showing
12 changed files
with
203 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ssecd/jkn': minor | ||
--- | ||
|
||
implement Rekam Medis web service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
JKN_PPK_CODE= | ||
JKN_CONS_ID= | ||
JKN_CONS_SECRET= | ||
JKN_VCLAIM_USER_KEY= | ||
JKN_ANTREAN_USER_KEY= | ||
JKN_APOTEK_USER_KEY= | ||
JKN_PCARE_USER_KEY= | ||
JKN_ICARE_USER_KEY= | ||
JKN_REKAM_MEDIS_USER_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { BaseApi } from '../base.js'; | ||
import { Config } from '../fetcher.js'; | ||
import { RekamMedisFormat } from './types.js'; | ||
import { encrypt, gzip } from './utils.js'; | ||
|
||
export class RekamMedis extends BaseApi<'rekamMedis'> { | ||
protected type = 'rekamMedis' as const; | ||
|
||
async insert(data: { | ||
/** nomor SEP */ | ||
nomorSEP: string; | ||
|
||
/** jenis pelayanan (1 = Rawat Inap) (2 = Rawat Jalan) */ | ||
jenisPelayanan: string; | ||
|
||
/** bulan penerbitan SEP (1 sampai 12) */ | ||
bulan: number; | ||
|
||
/** tahun penerbitan SEP misal 2023 */ | ||
tahun: number; | ||
|
||
/** | ||
* data rekam medis berupa plain object | ||
* | ||
* Proses kompresi dan enkripsi akan dilakukan | ||
* secara otomatis pada method ini | ||
*/ | ||
dataRekamMedis: RekamMedisFormat; | ||
}) { | ||
const dataMR = await preprocess(data.dataRekamMedis, this.config); | ||
return this.send({ | ||
path: `/`, | ||
method: 'POST', | ||
skipContentTypeHack: true, | ||
headers: { 'Content-Type': 'text/plain' }, | ||
data: { | ||
request: { | ||
noSep: data.nomorSEP, | ||
jnsPelayanan: data.jenisPelayanan, | ||
bulan: String(data.bulan), | ||
tahun: String(data.tahun), | ||
dataMR | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
/** | ||
* Pengolahan data berupa compression menggunakan metode GZIP | ||
* and encryption dengan key berupa kombinasi CONS ID, SECRET KEY, | ||
* dan KODE PPK. Ini berdasarkan spesifikasi yang telah ditentukan | ||
* pada halaman TrustMark BPJS Kesehatan. | ||
*/ | ||
async function preprocess(data: unknown, config: Config): Promise<string> { | ||
try { | ||
const value = JSON.stringify(data); | ||
const compressed = await gzip(value); | ||
return encrypt(compressed.toString(), config); | ||
} catch (err) { | ||
// TODO: define custom error | ||
throw new Error(`failed to compress or encrypt data. ${err}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export interface Bundle<T = fhir4.FhirResource> extends fhir4.Bundle<T> {} | ||
|
||
export interface Composition extends fhir4.Composition {} | ||
|
||
export interface Patient extends fhir4.Patient {} | ||
|
||
export interface Encounter extends fhir4.Encounter { | ||
subject?: fhir4.Encounter['subject'] & { noSep: string }; | ||
} | ||
|
||
export interface MedicationRequest extends fhir4.MedicationRequest {} | ||
|
||
export interface Practitioner extends fhir4.Practitioner {} | ||
|
||
export interface Organization extends fhir4.Organization {} | ||
|
||
export interface Condition extends fhir4.Condition {} | ||
|
||
export interface DiagnosticReport extends fhir4.DiagnosticReport {} | ||
|
||
export interface Procedure extends fhir4.Procedure {} | ||
|
||
export interface Device extends fhir4.Device {} | ||
|
||
export type RekamMedisFormat = | ||
| Bundle | ||
| Composition | ||
| Patient | ||
| Encounter | ||
| MedicationRequest | ||
| Practitioner | ||
| Organization | ||
| Condition | ||
| DiagnosticReport | ||
| Procedure | ||
| Device; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import zlib from 'node:zlib'; | ||
import { Config } from '../fetcher.js'; | ||
import { createCipheriv, createHash } from 'node:crypto'; | ||
|
||
export async function gzip(value: string): Promise<Buffer> { | ||
return new Promise((resolve, reject) => { | ||
zlib.gzip(Buffer.from(value), (err, buf) => { | ||
if (err) reject(err); | ||
else resolve(buf); | ||
}); | ||
}); | ||
} | ||
|
||
export function encrypt(value: string, config: Config): string { | ||
const { consId, consSecret, ppkCode } = config; | ||
if (!consId || !consSecret || !ppkCode) { | ||
throw new Error(`consId, consSecret, or ppkCode are not set`); | ||
} | ||
|
||
const keyPlain = consId + consSecret + ppkCode; | ||
const key = createHash('sha256').update(keyPlain, 'utf8').digest(); | ||
const iv = Uint8Array.from(key.subarray(0, 16)); | ||
const cipher = createCipheriv('aes-256-cbc', key, iv); | ||
let enc = cipher.update(value, 'base64', 'utf8'); | ||
enc += cipher.final('utf8'); | ||
return enc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters