# IWangLang: Patient Fhir Helper

## 🚀 Quick Start

Install:

```bash
# npm
npm i @iwanglang/patient-fhir-helper

# yarn
yarn add @iwanglang/patient-fhir-helper
```

Import:

```js
// ESM / Typescript
import { PatientFhirHelper } from "@iwanglang/patient-fhir-helper";

// CommonJS
const { PatientFhirHelper } = require("@iwanglang/patient-fhir-helper");
```

## 🥸 How it work?

The `PatientFhirHelper` class is used to search for patients in Fhir Server using `business identifier` and convert it into an interface `PatientNormalization`. So if you want to get patient information and don't know about fhir, let's call functionnn

```mermaid
sequenceDiagram
    patientFhirHelper->>FhirServer: search by business identifier
    FhirServer->>patientFhirHelper: Response Patient Resource
    patientFhirHelper-)PatientNormalization: Convert to interface
```

## 🥸 Get Patient Information by Identifier

```typescript
import { PatientFhirHelper } from "@iwanglang/patient-fhir-helper";

async function bootstrap() {
  const patientFhirHelper = new PatientFhirHelper("http://hapi.fhir.org/baseR4");

  const patient = await patientFhirHelper.findPatientByIdentifier("12345");

  console.log(patient);
  /**
   * {
    id: "1174249",
    patientReference: "Patient/1174249",
    identifier: [
      {
        use: "usual",
        type: [Object ...],
        system: "urn:oid:1.2.3.4.5",
        value: "89765a87b",
      }
    ],
    deceasedBoolean: false,
    hospitalNumber: "89765a87b",
    name: "-",
    gender: "male",
    birthdate: "1967-10-02",
    remainingAge: "56ปี 6เดือน 9วัน",
    remainingAgeYears: 56,
    remainingAgeMonths: 6,
    remainingAgeDays: 9,
    photo: undefined,
  }
  */
}

bootstrap();
```

## 🥸 Patient Information Interface

The `findPatientByIdentifier()` function returns a `PatientNormalization` object.

| element | type | description |
|---|---|---|
| id | string | The patient's unique identifier in the FHIR server. |
| patientReference | string | The patient's reference in the FHIR server. |
| identifier | Identifier[] | The patient's identifier. |
| deceasedBoolean | boolean | The patient's deceased status. |
| hospitalNumber | string \| null | The patient's hospital number, or `null` if not found. |
| name | string | The patient's name. |
| gender | ('male'\|'female'\|'other'\|'unknown') | The patient's gender. |
| birthdate | string \| null | The patient's birthdate, or `null` if not found. |
| remainingAge | string \| null | The patient's remainingAge, or `null` if not found. |
| remainingAgeYears | number \| null | The patient's remainingAgeYears, or `null` if not found. |
| remainingAgeMonths | number \| null | The patient's remainingAgeMonths, or `null` if not found. |
| remainingAgeDays | number \| null | The patient's remainingAgeDays, or `null` if not found. |
| photo | string \| undefined | The patient's photo, or `undefined` if not found. |
