@iwanglang/patient-fhir-helper
Version:
Patient Fhir Helper
259 lines • 8.88 kB
TypeScript
import type { Patient as R4Patient, Identifier as R4Identifier } from 'fhir/r4';
import type { Patient as R5Patient, Identifier as R5Identifier } from 'fhir/r5';
type Identifier = R4Identifier | R5Identifier;
type Patient = R4Patient | R5Patient;
/**
* An option object for configuring the behavior of the PatientHelper
* class.
*/
interface PatientHelperOption {
/**
* Whether to include the Medical Record Number (MR) in the search
* results. Default: `false`.
*/
medicalRecordNumber?: boolean;
/**
* The headers to be used in the request. Default: An empty
* `Headers` object.
*/
headers?: HeadersInit;
/**
* The current date to be used. Default: The current date when the
* `findPatientByIdentifier()` function is called.
*/
currentDate?: Date;
}
/**
* An object that contains the default option values for the PatientHelper
* class.
*
* The properties of this object are:
*
* - `medicalRecordNumber`: A boolean value that indicates whether the
* Medical Record Number (MR) should be included in the search results.
* Default: `false`.
* - `headers`: The headers to be used in the request. Default: An empty
* `Headers` object.
* - `currentDate`: The current date to be used. Default: The current date
* when the `findPatientByIdentifier()` function is called.
*/
export interface PatientHelperOptionDefault {
/**
* Whether to include the Medical Record Number (MR) in the search
* results. Default: `false`.
*/
medicalRecordNumber: boolean;
/**
* The headers to be used in the request. Default: An empty `Headers` object.
*/
headers: Headers;
/**
* The current date to be used. Default: The current date when the
* `findPatientByIdentifier()` function is called.
*/
currentDate: Date;
}
/**
* Normalized patient data for the client application.
*/
export interface PatientNormalization {
/**
* The patient's unique identifier in the FHIR server.
*/
id: string;
/**
* The patient's reference in the FHIR server.
*/
patientReference: string;
/**
* The patient's identifier.
*/
identifier: Identifier[];
/**
* The patient's deceased status.
*/
deceasedBoolean?: boolean | undefined;
/**
* The patient's hospital number, or `null` if not found.
*/
hospitalNumber: string | null;
/**
* The patient's name.
*/
name: string;
/**
* The patient's gender.
*/
gender: ('male' | 'female' | 'other' | 'unknown');
/**
* The patient's birthdate, or `null` if not found.
*/
birthdate: string | null;
/**
* The patient's remainingAge, or `null` if not found.
*/
remainingAge: string | null;
/**
* The patient's remainingAgeYears, or `null` if not found.
*/
remainingAgeYears: number | null;
/**
* The patient's remainingAgeMonths, or `null` if not found.
*/
remainingAgeMonths: number | null;
/**
* The patient's remainingAgeDays, or `null` if not found.
*/
remainingAgeDays: number | null;
/**
* The patient's photo, or `undefined` if not found.
*/
photo?: string | undefined;
}
export declare function useFhirHumanName(patient: Patient | null | undefined, use?: ('usual' | 'official' | 'temp' | 'nickname' | 'anonymous' | 'old' | 'maiden') | undefined): string;
/**
* Calculate the remaining age based on the birth date and current date.
*
* @param {string} birthdate - The birth date string
* @param {Date} [currentDate] - Optional parameter for the current date
* @return {string} The remaining age in years, months, and days
*/
export declare function calculateRemainingAgeString(birthdate: string, currentDate: Date): string;
/**
* Calculate the remaining age based on the birth date and current date.
*
* @param {string} birthdate - The birth date string
* @param {Date} [currentDate] - Optional parameter for the current date
* @return {string} The remaining age in years, months, and days
*/
export declare function calculateRemainingAgeString(birthdate: string, currentDate?: Date | undefined): string;
/**
* Calculate the remaining age based on the birth date and current date.
*
* @param {string} birthdate - The birth date string
* @return {string} The remaining age in years, months, and days
*/
export declare function calculateRemainingAgeString(birthdate: string): string;
/**
* Calculate the remaining age based on the birth date and current date.
*
* @param {string} birthdate - The birth date string
* @param {Date} [currentDate] - Optional parameter for the current date
* @return {string} The remaining age in years, months, and days
*/
export declare function calculateRemainingAge(birthdate: string, currentDate: Date): {
remainingAgeYears: number;
remainingAgeMonths: number;
remainingAgeDays: number;
};
/**
* Calculate the remaining age based on the birth date and current date.
*
* @param {string} birthdate - The birth date string
* @param {Date} [currentDate] - Optional parameter for the current date
* @return {string} The remaining age in years, months, and days
*/
export declare function calculateRemainingAge(birthdate: string, currentDate?: Date | undefined): {
remainingAgeYears: number;
remainingAgeMonths: number;
remainingAgeDays: number;
};
/**
* Calculate the remaining age based on the birth date and current date.
*
* @param {string} birthdate - The birth date string
* @return {string} The remaining age in years, months, and days
*/
export declare function calculateRemainingAge(birthdate: string): {
remainingAgeYears: number;
remainingAgeMonths: number;
remainingAgeDays: number;
};
/**
* A helper function to normalize patient data.
*
* @param {Patient} patient - the patient object to be normalized
* @return {PatientNormalization} the normalized patient object
*/
export declare function patientNormalizationHelper(patient: Patient, patientHelperOption?: PatientHelperOption): PatientNormalization;
export declare class PatientFhirHelper {
/**
* The URL of the FHIR server.
* @private
*/
private fhirServer;
/**
* The authentication token.
* @private
*/
private token;
private medicalRecordNumber;
private headers;
private currentDate;
/**
* Constructor for initializing the FHIR server and token.
*
* @param {string} fhirServer - the URL of the FHIR server
* @param {string} token - the authentication token
*/
constructor(fhirServer: string, token?: string);
/**
* Initializes the FHIR server and token for the API.
*
* @param {string} fhirServer - The URL of the FHIR server.
* @param {string} token - The authentication token.
*/
initialisation(fhirServer: string, token: string): void;
/**
* Sets the token for the class.
*
* @param {string} token - The token to be set.
*/
setToken(token: string): void;
/**
* Sets the option values for the PatientHelper.
*
* @param {PatientHelperOption} option - The options to set for the PatientHelper.
*/
setOption(option: PatientHelperOption): void;
/**
* Get options for PatientHelper.
*
* This function returns an object that contains the current option values
* for the PatientHelper class. The properties of the returned object are:
*
* - medicalRecordNumber: A boolean value that indicates whether the
* Medical Record Number (MR) should be included in the search results.
* - headers: The headers to be used in the request.
* - currentDate: The current date to be used.
*
* @param {PatientHelperOption} option - An object that contains the option
* values to override the default values.
* @return {PatientHelperOption} The options object.
*/
private getOptions;
/**
* Set the headers for the request.
*
* @param {HeadersInit} headers - the headers to be set
* @return {void}
*/
setHearders(headers: Headers): void;
/**
* Set the timing using the current date.
*
* @param {Date} currentDate - the current date to set
* @return {void}
*/
setTiming(currentDate: Date): void;
/**
* Find a patient by identifier.
*
* @param {string} identifier - The identifier of the patient
* @param {PatientHelperOption} option - An option object to configure the behavior of the function
* @return {Promise<any>} A Promise that resolves with the patient resource if found, otherwise rejects with an error
*/
findPatientByIdentifier(identifier: string, option?: PatientHelperOption): Promise<PatientNormalization>;
}
export {};
//# sourceMappingURL=index.d.ts.map