Adding dynamic input system, and some minor improvements in types.ts, registry.ts and test.ts
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { Calculator, Input, Interpretation } from "../types";
|
||||
import { Calculator, Input, Interpretation, Values } from "../types";
|
||||
|
||||
const parameters:Input[] = [
|
||||
{
|
||||
id:"gender",
|
||||
type:"radio",
|
||||
name:"Gender",
|
||||
placeholder:"Enter your gender",
|
||||
type:"select",
|
||||
inputOptions:[
|
||||
{
|
||||
label:"Male",
|
||||
@@ -19,6 +21,8 @@ const parameters:Input[] = [
|
||||
{
|
||||
id:"age",
|
||||
type:"number",
|
||||
name:"Age",
|
||||
placeholder:"Enter your age",
|
||||
min:18,
|
||||
max:95,
|
||||
required:true
|
||||
@@ -26,6 +30,8 @@ const parameters:Input[] = [
|
||||
{
|
||||
id:"creatinine",
|
||||
type:"number",
|
||||
name:"Creatinine",
|
||||
placeholder:"Enter your serum creatinine values",
|
||||
min:0.2,
|
||||
max:20,
|
||||
required:true
|
||||
@@ -33,11 +39,18 @@ const parameters:Input[] = [
|
||||
{
|
||||
id:"weight",
|
||||
type:"number",
|
||||
min:0,
|
||||
name:"Weight",
|
||||
placeholder:"Enter your weight in kilograms",
|
||||
min:10,
|
||||
max:100 ,
|
||||
required:true
|
||||
}
|
||||
];
|
||||
function calc_func(gender:"male" | "female", age:number, creatinine:number, weight:number):number{
|
||||
function calc_func(values : Values):number{
|
||||
const gender = values.gender as "male" | "female";
|
||||
const age = values.age as number;
|
||||
const weight = values.weight as number;
|
||||
const creatinine = values.creatinine as number;
|
||||
return gender === "male"
|
||||
? ((140 - age) * weight)/(72 * creatinine)
|
||||
: (((140 - age) * weight)/(72 * creatinine)) * 0.85;
|
||||
|
||||
10
src/app/utils/calculators/miscellaneous/test.ts
Normal file
10
src/app/utils/calculators/miscellaneous/test.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { CalculatorRegistry } from "../registry";
|
||||
const calculator = CalculatorRegistry.miscellaneous.calculators[0].calc_func;
|
||||
console.log(calculator(
|
||||
{
|
||||
gender:"male",
|
||||
age:43,
|
||||
creatinine:5,
|
||||
weight:60
|
||||
}
|
||||
));
|
||||
15
src/app/utils/calculators/registry.js
Normal file
15
src/app/utils/calculators/registry.js
Normal file
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.CalculatorRegistry = void 0;
|
||||
var cockcroft_gault_eq_1 = require("./miscellaneous/cockcroft-gault-eq");
|
||||
exports.CalculatorRegistry = {
|
||||
miscellaneous: {
|
||||
id: "miscellaneous",
|
||||
displayName: "Miscellaneous",
|
||||
textColor: "#ccc",
|
||||
svg: "",
|
||||
calculators: [
|
||||
cockcroft_gault_eq_1.cockcroftGault
|
||||
]
|
||||
}
|
||||
};
|
||||
2
src/app/utils/calculators/types.js
Normal file
2
src/app/utils/calculators/types.js
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
@@ -5,15 +5,18 @@ export interface Calculator {
|
||||
unit?:string,
|
||||
inputs:Input[],
|
||||
calc_func:Function,
|
||||
interpret_func:Function
|
||||
interpret_func:Function,
|
||||
customComponent?:React.FC
|
||||
}
|
||||
interface inputOptions {
|
||||
label:string,
|
||||
value:string | number | Date;
|
||||
value:string | number ;
|
||||
}
|
||||
export interface Input{
|
||||
id:string,
|
||||
type: "number" | "text" | "radio",
|
||||
name:string,
|
||||
placeholder:string,
|
||||
type: "number" | "text" | "select",
|
||||
inputOptions?:inputOptions[],
|
||||
min?:number,
|
||||
max?:number,
|
||||
@@ -35,3 +38,5 @@ export interface Section {
|
||||
svg:string,
|
||||
calculators:Calculator[]
|
||||
}
|
||||
|
||||
export type Values = Record<string, string | number >;
|
||||
|
||||
Reference in New Issue
Block a user