UNPKG

@vidal-community/vidal-web-components

Version:

Vidal Web Components

33 lines 1.28 kB
import { Gender } from './gender'; export class Patient { constructor(sex, dateOfBirth, nowSupplier) { this.sex = this.from(sex); if (dateOfBirth) { const timestamp = dateOfBirth instanceof Date ? dateOfBirth.getTime() : Date.parse(dateOfBirth); const hasCorrectFormat = (typeof dateOfBirth === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(dateOfBirth)) || dateOfBirth instanceof Date; if (isNaN(timestamp) || !hasCorrectFormat) { this.dateOfBirth = undefined; } else { this.dateOfBirth = new Date(timestamp); const timeDelta = new Date(nowSupplier() - this.dateOfBirth.getTime()); const age = timeDelta.getUTCFullYear() - 1970; this.age = age > 0 ? age : undefined; } } } from(sex) { if ((sex === null || sex === void 0 ? void 0 : sex.toLocaleLowerCase()) === 'male') { return Gender.MALE; } if ((sex === null || sex === void 0 ? void 0 : sex.toLocaleLowerCase()) === 'female') { return Gender.FEMALE; } return undefined; } } //# sourceMappingURL=patient.js.map