Untitled
unknown
plain_text
a year ago
6.4 kB
7
Indexable
import { LocalStorageUtils } from "services-lib";
import { TextUtils } from "./textUtils";
import { LocaleUtils } from "./locale-utils";
import { DentalNotationType } from "../models/dental-notation-type.model";
export class DentalNotationTypeUtils {
public static logged: boolean = true;
private static LocalStorageKey = 'dental_notation_id'
private static readonly AlphanumericNotationMAP = new Map<number, string>([
// adult maxilla
[18, 'UR8'],
[17, 'UR7'],
[16, 'UR6'],
[15, 'URE'],
[14, 'UR4'],
[13, 'UR3'],
[12, 'UR2'],
[11, 'UR1'],
[21, 'UL1'],
[22, 'UL2'],
[23, 'UL3'],
[24, 'UL4'],
[25, 'UL5'],
[26, 'UL6'],
[27, 'UL7'],
[28, 'UL8'],
//adult mandible
[48, 'LR8'],
[47, 'LR7'],
[46, 'LR6'],
[45, 'LR5'],
[44, 'LR4'],
[43, 'LR3'],
[42, 'LR2'],
[41, 'LR1'],
[31, 'LL1'],
[32, 'LL2'],
[33, 'LL3'],
[34, 'LL4'],
[35, 'LL5'],
[36, 'LL6'],
[37, 'LL7'],
[38, 'LL8'],
//infant maxilla
[55, 'URE'],
[54, 'URD'],
[53, 'URC'],
[52, 'URB'],
[51, 'URA'],
[61, 'ULA'],
[62, 'ULB'],
[63, 'ULC'],
[64, 'ULD'],
[65, 'ULE'],
//infant mandible
[85, 'LRE'],
[84, 'LRD'],
[83, 'LRC'],
[82, 'LRB'],
[81, 'LRA'],
[71, 'LLA'],
[72, 'LLB'],
[73, 'LLC'],
[74, 'LLD'],
[75, 'LLE'],
]);
//usa
private static readonly UniversalMap = new Map<number, number | string>([
// adult maxilla
[18, 1],
[17, 2],
[16, 3],
[15, 4],
[14, 5],
[13, 6],
[12, 7],
[11, 8],
[21, 9],
[22, 10],
[23, 11],
[24, 12],
[25, 13],
[26, 14],
[27, 15],
[28, 16],
//adult mandible
[48, 32],
[47, 31],
[46, 30],
[45, 29],
[44, 28],
[43, 27],
[42, 26],
[41, 25],
[31, 24],
[32, 23],
[33, 22],
[34, 21],
[35, 20],
[36, 19],
[37, 18],
[38, 17],
//infant maxilla
[55, 'A'],
[54, 'B'],
[53, 'C'],
[52, 'D'],
[51, 'E'],
[61, 'F'],
[62, 'G'],
[63, 'H'],
[64, 'I'],
[65, 'J'],
//infant mandible
[85, 'T'],
[84, 'S'],
[83, 'R'],
[82, 'Q'],
[81, 'P'],
[71, 'O'],
[72, 'N'],
[73, 'M'],
[74, 'L'],
[75, 'K'],
]);
private static getAlphanumericNotationCode(fdiToothNumber: number): string {
if (fdiToothNumber) {
return DentalNotationTypeUtils
.AlphanumericNotationMAP
.get(fdiToothNumber.valueOf());
}
return '';
}
private static getUniversalCode(fdiToothNumber: number): string {
if (!DentalNotationTypeUtils.logged) {
console.log("2-" + fdiToothNumber.valueOf());
console.log("3-" + DentalNotationTypeUtils
.UniversalMap
.get(fdiToothNumber.valueOf())
);
}
DentalNotationTypeUtils.logged = true;
if (fdiToothNumber) {
const result = DentalNotationTypeUtils
.UniversalMap
.get(fdiToothNumber.valueOf());
if (result) return result.toString();
}
return '';
}
public static getToothCode(fdiToothNumber: number | string, isShort: boolean = false): string {
let fdiCode: number;
if (TextUtils.isString(fdiToothNumber)) {
if (!Number.isNaN(fdiToothNumber)) fdiCode = Number(fdiToothNumber);
else return <string>fdiToothNumber;
} else
if (TextUtils.isNumber(fdiToothNumber))
fdiCode = <number>fdiToothNumber;
if (!DentalNotationTypeUtils.logged) {
console.log("1-" + fdiCode);
}
let result: string;
const dentalNotationType: DentalNotationType = DentalNotationTypeUtils.getActiveDentalNotationType();
switch (dentalNotationType.id) {
case DentalNotationType.FDI.id:
result = fdiCode.toString();
break;
case DentalNotationType.UniversalNumberingSystem.id:
result = DentalNotationTypeUtils.getUniversalCode(fdiCode);
break;
case DentalNotationType.AlphanumericNotation.id:
result = DentalNotationTypeUtils.getAlphanumericNotationCode(fdiCode);
if (isShort) {
result = result.substring(result.length - 1);
}
break;
}
return result;
}
public static setDentalNotationCodeInLocalStorage(dentalNotationType: DentalNotationType) {
LocalStorageUtils.setLocalStorageItem<number>(DentalNotationTypeUtils.LocalStorageKey, dentalNotationType.id);
}
public static getActiveDentalNotationType(): DentalNotationType {
// intenta leerlo del local storage
const dentalNotationTypeId = LocalStorageUtils.getLocalStorageItem<number>(DentalNotationTypeUtils.LocalStorageKey);
let dentalNotationType: DentalNotationType = null;
if (dentalNotationTypeId !== undefined && dentalNotationTypeId !== null) {
dentalNotationType = DentalNotationType.getById(dentalNotationTypeId);
if (dentalNotationType === undefined || dentalNotationType === null) dentalNotationType = DentalNotationType.FDI;
} else { // si no esta en localStorage
// toma la región por el ip del cliente
const countryCode = LocaleUtils.getcountryIdByIp();
// busca en el mapa si está esa región
dentalNotationType = DentalNotationType.getCountryCodeMap().get(countryCode);
// si no está definida le da valor FDI por defecto
if (dentalNotationType === undefined || dentalNotationType === null) dentalNotationType = DentalNotationType.FDI;
}
return dentalNotationType;
}
}Editor is loading...
Leave a Comment