123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- import 'package:fis_measure/interfaces/date_types/vector.dart';
- import 'package:fis_measure/interfaces/process/calculators/values.dart';
- import 'package:fis_measure/interfaces/process/items/terms.dart';
- import 'package:fis_measure/process/calcuators/formulas/urology.dart';
- import 'package:fis_measure/process/primitives/combos/two_straightline.dart';
- import 'package:fis_measure/process/primitives/straightline.dart';
- import 'package:vid/us/vid_us_unit.dart';
- import 'calculator.dart';
- import 'formulas/general.dart';
- import 'lv_study.dart';
- class TwoDistanceCalBase extends Calculator<TwoStraightLine, double> {
- TwoDistanceCalBase(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- // TODO: implement calculate
- }
- }
- class ResidualUrineCal extends Calculator<TwoStraightLine, double> {
- ResidualUrineCal(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final x = _pickChildValue(ref.x);
- final y = _pickChildValue(ref.y);
- final feature = ref.feature!;
- final viewport = feature.hostVisualArea!.viewport!;
- if (x != null && y != null) {
- final value = UrologyFormulas.calcRUV(
- x,
- y,
- );
- updateFloatValue(value);
- }
- }
- double? _pickChildValue(StraightLine item) {
- if (item.calculator == null) return null;
- ValueBase? value;
- if (item.measuredFeatures.isNotEmpty) {
- value = item.measuredFeatures.first.value;
- } else if (item.feature != null) {
- value = item.feature!.value;
- }
- if (value != null) {
- return (value as FloatValue).value ?? 0;
- }
- return null;
- }
- }
- class TwoDistanceVolumeCal extends Calculator<TwoStraightLine, double> {
- TwoDistanceVolumeCal(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final f1 = findChildFeature(ref.child1);
- final f2 = findChildFeature(ref.child2);
- if (f1 == null || f2 == null) return;
- final feature = ref.feature!;
- final val1 = f1.value?.pickFloat() ?? 0;
- final val2 = f2.value?.pickFloat() ?? 0;
- final unitY = f1.hostVisualArea!.viewport!.yUnit;
- for (var ouput in ref.meta.outputs) {
- if (ouput.name == MeasureTerms.Volume) {
- var volume = GeneralFormulas.volumeTwoLine(val1, val2);
- final unit = unitY == VidUsUnit.cm ? VidUsUnit.cm3 : VidUsUnit.None;
- feature.updateFloatValue(
- ouput,
- roundDouble(volume, ouput.fractionalDigits),
- unit,
- );
- } else if (ouput.name == MeasureTerms.AvgDistance) {
- double avg = (val1 + val2) / 2;
- feature.updateFloatValue(
- ouput,
- roundDouble(avg, ouput.fractionalDigits),
- unitY,
- );
- }
- }
- }
- }
- class TwoDistanceSumCal extends Calculator<TwoStraightLine, double> {
- TwoDistanceSumCal(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final f1 = findChildFeature(ref.child1);
- final f2 = findChildFeature(ref.child2);
- if (f1 == null || f2 == null) return;
- final feature = ref.feature!;
- final val1 = f1.value?.pickFloat() ?? 0;
- final val2 = f2.value?.pickFloat() ?? 0;
- var unitY = f1.hostVisualArea!.viewport!.yUnit;
- if (unitY == VidUsUnit.None) {
- if (f1.value != null) {
- unitY = f1.value!.unit;
- }
- }
- for (var ouput in ref.meta.outputs) {
- if (ouput.name == MeasureTerms.Distance) {
- var dis = val1 + val2;
- feature.updateFloatValue(
- ouput,
- roundDouble(dis, ouput.fractionalDigits),
- unitY,
- );
- } else if (ouput.name == MeasureTerms.AvgDistance) {
- double avg = (val1 + val2) / 2;
- feature.updateFloatValue(
- ouput,
- roundDouble(avg, ouput.fractionalDigits),
- unitY,
- );
- }
- }
- }
- }
- class TwoStraightLineAngleCal extends Calculator<TwoStraightLine, double> {
- TwoStraightLineAngleCal(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final f1 = findChildFeature(ref.child1);
- final f2 = findChildFeature(ref.child2);
- if (f1 == null || f2 == null) return;
- if (f1.innerPoints.length == f2.innerPoints.length) {
- var l1 = f1.innerPoints[0] - f1.innerPoints[1];
- var l2 = f2.innerPoints[0] - f2.innerPoints[1];
- var value = (DVector.angleBetween(l1, l2)).abs();
- updateFloatValue(value, unit: VidUsUnit.degree, useRound: true);
- }
- }
- }
- class IvsThckCal extends Calculator<TwoStraightLine, double> {
- IvsThckCal(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final len1 = pickChildFloatValue(ref.child1) ?? 0;
- final len2 = pickChildFloatValue(ref.child2) ?? 0;
- final ivs = calcIvs(len1, len2);
- updateFloatValue(ivs, unit: VidUsUnit.percent, useRound: true);
- }
- static double calcIvs(double ivsd, double ivss) {
- if (ivsd == 0) {
- return 0;
- }
- return (ivss - ivsd) / ivsd * 100;
- }
- }
- abstract class EfCal extends LvStudyCalculatorBase<TwoStraightLine> {
- late final StraightLine kidLVIDd;
- late final StraightLine kidLVIDs;
- EfCal(super.ref) {
- kidLVIDd = ref.child1;
- kidLVIDs = ref.child2;
- }
- @override
- void calculate() {
- if (ref.feature == null) return;
- updateStringValue('');
- restoreVals();
- uv.lvidd = pickChildToFloatValue(kidLVIDd)?.toUnitFloatValue();
- uv.lvids = pickChildToFloatValue(kidLVIDs)?.toUnitFloatValue();
- for (var output in ref.meta.outputs) {
- switch (output.name) {
- case MeasureTerms.LVEDV:
- updateLVEDV();
- break;
- case MeasureTerms.LVESV:
- updateLVESV();
- break;
- case MeasureTerms.EF:
- updateEF();
- break;
- case MeasureTerms.CO:
- updateCO();
- break;
- }
- }
- }
- }
- class EfTeichCal extends EfCal {
- EfTeichCal(TwoStraightLine ref) : super(ref);
- }
- class RvStudyCal extends TwoDistanceCalBase {
- RvStudyCal(super.ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final feature = ref.feature!;
- for (var output in ref.meta.outputs) {
- switch (output.name) {
- case MeasureTerms.RVStudy:
- feature.updateStringValue(output, "");
- break;
- case MeasureTerms.RVIDd:
- final rvidd = pickChildFloatValue(ref.x);
- if (rvidd != null) {
- feature.updateFloatValue(output, rvidd, VidUsUnit.cm);
- }
- break;
- case MeasureTerms.RVIDs:
- final rvids = pickChildFloatValue(ref.y);
- if (rvids != null) {
- feature.updateFloatValue(output, rvids, VidUsUnit.cm);
- }
- break;
- }
- }
- }
- }
- class AreaPerimeterByLAndWCal extends Calculator<TwoStraightLine, double> {
- AreaPerimeterByLAndWCal(TwoStraightLine ref) : super(ref);
- @override
- void calculate() {
- if (ref.feature == null) return;
- final f1 = findChildFeature(ref.child1);
- final f2 = findChildFeature(ref.child2);
- if (f1 == null || f2 == null) return;
- final feature = ref.feature!;
- final val1 = f1.value?.pickFloat() ?? 0;
- final val2 = f2.value?.pickFloat() ?? 0;
- var unitY = f1.hostVisualArea!.viewport!.yUnit;
- if (unitY == VidUsUnit.None) {
- if (f1.value != null) {
- unitY = f1.value!.unit;
- }
- }
- for (var ouput in ref.meta.outputs) {
- if (ouput.name == MeasureTerms.Area) {
- var area = GeneralFormulas.area(val1, val2);
- feature.updateFloatValue(
- ouput,
- roundDouble(area, ouput.fractionalDigits),
- unitY,
- );
- } else if (ouput.name == MeasureTerms.Perimeter) {
- var perimeter = GeneralFormulas.perimeter(val1, val2);
- feature.updateFloatValue(
- ouput,
- roundDouble(perimeter, ouput.fractionalDigits),
- unitY,
- );
- }
- }
- }
- }
|