label.dart 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:vitalapp/rpc.dart';
  3. import 'package:vitalapp/store/store.dart';
  4. import 'interfaces/label.dart';
  5. import 'package:fis_common/logger/logger.dart';
  6. import 'interfaces/models/crowd_labels.dart';
  7. class LabelManager implements ILabelManager {
  8. @override
  9. Future<List<LabelDTO>?> getLabelListByKey(String key) async {
  10. try {
  11. final result = await rpc.vitalLabel.getLabelListByKeyAsync(
  12. GetLabelListByKeyRequest(key: key, token: Store.user.token),
  13. );
  14. return result;
  15. } catch (e) {
  16. logger.e("LabelManager get labels by key-$key error.", e);
  17. return null;
  18. }
  19. }
  20. @override
  21. Future<List<LabelDTO>> getAllLabels() async {
  22. List<LabelDTO> result = [];
  23. result = await rpc.vitalLabel.getCrowdLabelsAsync(
  24. GetCrowdLabelsRequest(token: Store.user.token),
  25. );
  26. return result;
  27. }
  28. @override
  29. Future<List<LabelDTO>> getNormalCrowdLabels() async {
  30. return (await getLabelListByKey("RQFL")) ?? [];
  31. }
  32. @override
  33. Future<List<LabelDTO>> getDiseaseCrowdLabels() async {
  34. return (await getLabelListByKey("CJJB")) ?? [];
  35. }
  36. @override
  37. Future<List<LabelDTO>> getSpecialCareCrowdLabels() async {
  38. return (await getLabelListByKey("TSZG")) ?? [];
  39. }
  40. @override
  41. String transparent(String e) {
  42. switch (e) {
  43. case CrowdLabelKeys.CHILDREN:
  44. return CrowdLabels.CHILDREN;
  45. case CrowdLabelKeys.ELDERLY:
  46. return CrowdLabels.ELDERLY;
  47. case CrowdLabelKeys.HYPERTENSION:
  48. return CrowdLabels.HYPERTENSION;
  49. case CrowdLabelKeys.MENTAlDISORDER:
  50. return CrowdLabels.MENTAlDISORDER;
  51. case CrowdLabelKeys.TYPE2_DIABETES:
  52. return CrowdLabels.TYPE2_DIABETES;
  53. case CrowdLabelKeys.TUBERCULOSIS:
  54. return CrowdLabels.TUBERCULOSIS;
  55. case CrowdLabelKeys.PREGNAMTWOMAN:
  56. return CrowdLabels.PREGNAMTWOMAN;
  57. }
  58. return "";
  59. }
  60. }