Repository navigation
feat(patient): autoavaliação local no pilar A, sem sessão nem registro no servidor (C-11, #132) #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(patient): autoavaliação local no pilar A, sem sessão nem registro no servidor (C-11, #132) #161
Changes from all commits
4074264
23fc500
15fd57b
7d9c665
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,7 @@ import 'package:sinalacs_patient/core/storage/local_data_control.dart'; | |
| import 'package:sinalacs_patient/core/storage/local_database_key.dart' | ||
| show LocalDatabaseUnavailableException; | ||
| import 'package:sinalacs_patient/core/services/emergency_dialer.dart'; | ||
| import 'package:sinalacs_patient/core/triage/self_assessment.dart'; | ||
| import 'package:sinalacs_patient/core/services/theme_controller.dart'; | ||
|
|
||
| class SinalAcsApp extends StatefulWidget { | ||
|
|
@@ -687,6 +688,21 @@ class _PatientLoginScreenState extends State<PatientLoginScreen> { | |
| label: const Text('Biblioteca de saúde (sem cadastro)'), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 12), | ||
| // Pilar A (C-11, RF22): a autoavaliação roda no | ||
| // aparelho, sem conta e sem rede. | ||
| SizedBox( | ||
| width: double.infinity, | ||
| child: OutlinedButton.icon( | ||
| key: const Key('login_self_assessment_button'), | ||
| style: OutlinedButton.styleFrom(minimumSize: const Size(48, 52)), | ||
| onPressed: () => Navigator.of(context).push( | ||
| MaterialPageRoute(builder: (_) => const LocalSelfAssessmentScreen()), | ||
| ), | ||
| icon: const Icon(Icons.assignment_outlined), | ||
| label: const Text('Autoavaliação (sem cadastro)'), | ||
| ), | ||
| ), | ||
| const SizedBox(height: 4), | ||
| TextButton( | ||
| key: const Key('login_legal_link'), | ||
|
|
@@ -1550,9 +1566,15 @@ class _EmergencyScreenState extends State<EmergencyScreen> { | |
| } | ||
|
|
||
| class TriageScreen extends StatefulWidget { | ||
| const TriageScreen({super.key, this.onComplete, this.onFailure}); | ||
| const TriageScreen({super.key, this.onComplete, this.onFailure, this.local = false}); | ||
| final VoidCallback? onComplete; | ||
|
|
||
| /// Pilar A (C-11, #132): `true` roda a árvore no aparelho | ||
| /// ([SelfAssessmentEngine]), sem `accessToken`, sem rede e sem gravar em | ||
| /// `triage_sessions`. `false` (pilar B, com sessão) chama `triage.evaluate`. | ||
| /// No modo local a tela nunca lê o `BackendScope`. | ||
| final bool local; | ||
|
|
||
| /// Relata ao shell a falha capturada nesta tela. Ver | ||
| /// `_PatientHomeShellState._reportFailure`. | ||
| final ValueChanged<BackendFailure>? onFailure; | ||
|
|
@@ -1612,7 +1634,7 @@ class _TriageScreenState extends State<TriageScreen> { | |
| }); | ||
|
|
||
| try { | ||
| final risk = await BackendScope.of(context).evaluateTriage( | ||
| final risk = widget.local ? _evaluateOnDevice() : await BackendScope.of(context).evaluateTriage( | ||
| chestPain: _answers[TriageSymptom.chestPain] ?? false, | ||
| difficultyBreathing: _answers[TriageSymptom.difficultyBreathing] ?? false, | ||
| fever: _answers[TriageSymptom.fever] ?? false, | ||
|
|
@@ -1639,6 +1661,22 @@ class _TriageScreenState extends State<TriageScreen> { | |
| } | ||
| } | ||
|
|
||
| /// Mesma árvore do `TriageEngine` do backend, no aparelho (C-11). A paridade | ||
| /// nas 64 combinações é provada por | ||
| /// `backend/sinalacs_server/test/unit/self_assessment_parity_test.dart`. | ||
| /// A tradução para [RiskLevel] é por **nome**, nunca por índice. | ||
| RiskLevel _evaluateOnDevice() { | ||
| final level = const SelfAssessmentEngine().evaluate( | ||
| chestPain: _answers[TriageSymptom.chestPain] ?? false, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pedido. A paridade prova que o motor do aparelho é igual ao do backend, mas nada prova que a tela entrega a resposta certa a cada parâmetro. Conferi por mutação: trocando esta linha por Como a INV-02 agora depende também desta ligação, peço um teste que responda cada sinal sozinho (mais "nenhum"; hoje faltam dor no peito, falta de ar e fraqueza, que nenhum teste responde isolados) e compare a saída da tela com |
||
| difficultyBreathing: _answers[TriageSymptom.difficultyBreathing] ?? false, | ||
| fever: _answers[TriageSymptom.fever] ?? false, | ||
| persistentVomiting: _answers[TriageSymptom.persistentVomiting] ?? false, | ||
| bleeding: _answers[TriageSymptom.bleeding] ?? false, | ||
| severeWeakness: _answers[TriageSymptom.severeWeakness] ?? false, | ||
| ); | ||
| return RiskLevel.values.byName(level.name); | ||
| } | ||
|
|
||
| /// Saída de maior gravidade: só a orientação "Ligar 192" (P-09, C-04). | ||
| /// | ||
| /// **Nenhum pedido de contato sai daqui** — nada de `createRedAlert`; o | ||
|
|
@@ -1660,7 +1698,9 @@ class _TriageScreenState extends State<TriageScreen> { | |
| @override | ||
| Widget build(BuildContext context) { | ||
| final risk = _risk; | ||
| if (risk != null) return _TriageResult(risk: risk, onContinue: widget.onComplete); | ||
| if (risk != null) { | ||
| return _TriageResult(risk: risk, onContinue: widget.onComplete, local: widget.local); | ||
| } | ||
|
|
||
| final symptom = _symptoms[_step]; | ||
| final answer = _answers[symptom]; | ||
|
|
@@ -1731,11 +1771,16 @@ class _TriageScreenState extends State<TriageScreen> { | |
| /// A cor é sinal clínico, nunca decoração: vermelho/amarelo/verde mapeiam | ||
| /// estritamente o [RiskLevel]. | ||
| class _TriageResult extends StatelessWidget { | ||
| const _TriageResult({required this.risk, this.onContinue}); | ||
| const _TriageResult({required this.risk, this.onContinue, this.local = false}); | ||
|
|
||
| final RiskLevel risk; | ||
| final VoidCallback? onContinue; | ||
|
|
||
| /// Resultado da autoavaliação local (C-11): nada foi enviado, então a tela | ||
| /// não pode falar de "solicitação" nem de agente que entrará em contato. | ||
| /// Os textos finais das três saídas são da C-08 (#130). | ||
| final bool local; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| // `color` só é usada como texto/ícone sobre o card (nenhum botão herda | ||
|
|
@@ -1780,7 +1825,13 @@ class _TriageResult extends StatelessWidget { | |
| style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: color), | ||
| ), | ||
| const SizedBox(height: 12), | ||
| Text(guidance, textAlign: TextAlign.center), | ||
| Text( | ||
| local | ||
| ? 'Esta autoavaliação ficou só neste aparelho: nada foi enviado ao agente nem ao servidor.' | ||
| : guidance, | ||
| key: const Key('triage_guidance'), | ||
| textAlign: TextAlign.center, | ||
| ), | ||
| const SizedBox(height: 8), | ||
| Text( | ||
| 'Classificação feita pelo protocolo da equipe de saúde.', | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sugestão. No modo local esta frase continua aparecendo: "Classificação feita pelo protocolo da equipe de saúde." No pilar A não há equipe nem sessão, o projeto não tem vínculo com unidade de saúde, e o RF04 do piloto pede "nunca 'classificação de risco'". Como esta PR já troca a frase de orientação quando |
||
|
|
@@ -1796,13 +1847,33 @@ class _TriageResult extends StatelessWidget { | |
| key: const Key('triage_continue'), | ||
| onPressed: onContinue, | ||
| style: FilledButton.styleFrom(minimumSize: const Size(48, 52)), | ||
| child: const Text('Acompanhar solicitação'), | ||
| child: Text(local ? 'Concluir' : 'Acompanhar solicitação'), | ||
| ), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Autoavaliação do pilar A, aberta pela tela de entrada sem conta (C-11, #132; | ||
| /// RF04, RF22, RNF09): roda no aparelho, sem sessão, sem rede e sem registro no | ||
| /// servidor. A saída de maior gravidade é a orientação "Ligar 192" (C-04). | ||
| class LocalSelfAssessmentScreen extends StatelessWidget { | ||
| const LocalSelfAssessmentScreen({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar(title: const Text('Autoavaliação')), | ||
| body: SafeArea( | ||
| child: TriageScreen( | ||
| local: true, | ||
| onComplete: () => Navigator.of(context).pop(), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Catálogo de condições que a tela oferece para marcar/desmarcar — mesmo | ||
| /// conjunto que `spec/idea.md` documenta como a origem do produto ("Perfil | ||
| /// Clínico e Cadastro de Crônicos"): diabetes, hipertensão, uso contínuo de | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,59 @@ | ||
| /// Motor de autoavaliação no aparelho (C-11, #132; RF04, RF16, INV-02). | ||
| /// | ||
| /// No pilar A (sem login) a autoavaliação roda **aqui**, sem rede, sem | ||
| /// `accessToken` e sem gravar em `triage_sessions`. No pilar B (com sessão) o | ||
| /// app continua chamando `triage.evaluate`, que roda o `TriageEngine` do | ||
| /// backend e grava a sessão. | ||
| /// | ||
| /// São, portanto, **duas implementações da mesma árvore de decisão fechada**, e | ||
| /// a INV-02 passa a depender de elas serem iguais. Quem prova isso é | ||
| /// `backend/sinalacs_server/test/unit/self_assessment_parity_test.dart`, que | ||
| /// importa ESTE arquivo e compara as duas nas 64 combinações dos seis sinais. | ||
| /// Ele roda no job `serverpod-backend` do CI em todo PR, seja qual for o motor | ||
| /// alterado. | ||
| /// | ||
| /// **Este arquivo não pode importar nada** — nem Flutter, nem | ||
| /// `sinalacs_client`: o teste de paridade o carrega na VM do backend, que não | ||
| /// tem esses pacotes. | ||
| library; | ||
|
|
||
| /// Versão da árvore de decisão da autoavaliação (RF16, INV-02). | ||
| /// | ||
| /// Vai no evento local da saída "Ligar 192" (C-04, `spec/requisitos_piloto.md` | ||
| /// §INV-03 no piloto: "evento com data, hora e versão do motor"). Quem mudar | ||
| /// as regras da árvore — no backend (`TriageEngine`) ou no aparelho — sobe | ||
| /// esta versão no mesmo commit, para que um evento antigo continue dizendo | ||
| /// qual regra o produziu. | ||
| /// as regras da árvore — no backend (`TriageEngine`) ou aqui — sobe esta | ||
| /// versão no mesmo commit, para que um evento antigo continue dizendo qual | ||
| /// regra o produziu. | ||
| const selfAssessmentEngineVersion = 'arvore-v1'; | ||
|
|
||
| /// Saída do motor. Os nomes são os mesmos do `RiskLevel` do backend e do | ||
| /// cliente gerado; a tela traduz por **nome**, nunca por índice. | ||
| enum SelfAssessmentLevel { red, yellow, green } | ||
|
|
||
| /// Mesma árvore do `TriageEngine` do backend | ||
| /// (`backend/sinalacs_server/lib/src/application/triage/triage_engine.dart`). | ||
| /// | ||
| /// Determinística: mesma entrada, mesma saída, sem estado, relógio, sorteio ou | ||
| /// campo editável (INV-02). | ||
| class SelfAssessmentEngine { | ||
| const SelfAssessmentEngine(); | ||
|
|
||
| SelfAssessmentLevel evaluate({ | ||
| required bool chestPain, | ||
| required bool difficultyBreathing, | ||
| required bool fever, | ||
| required bool persistentVomiting, | ||
| required bool bleeding, | ||
| required bool severeWeakness, | ||
| }) { | ||
| if (chestPain || difficultyBreathing || severeWeakness || bleeding) { | ||
| return SelfAssessmentLevel.red; | ||
| } | ||
|
|
||
| if (fever || persistentVomiting) { | ||
| return SelfAssessmentLevel.yellow; | ||
| } | ||
|
|
||
| return SelfAssessmentLevel.green; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedido. O
CONTRIBUTING.mdpede para não gravar contagens de testes nos documentos ("elas envelhecem a cada PR"). Sugiro tirar "355 testes", "(5)" e "4 dos 5" desta linha e deixar as contagens só no corpo da PR, por exemplo: