dataquantals commited on
Commit
7c7ce00
·
verified ·
1 Parent(s): 7549acf

undefined - Initial Deployment

Browse files
Files changed (1) hide show
  1. index.html +169 -104
index.html CHANGED
@@ -1308,120 +1308,179 @@
1308
  }
1309
  };
1310
 
1311
- class ConsentManager {
1312
- constructor() {
1313
- this.currentParticipant = null;
1314
- this.currentProject = null;
1315
- this.modal = null;
1316
- this.signaturePad = null;
1317
- this.identityVerified = false;
1318
- }
1319
-
1320
- async initializeConsent(participantId) {
1321
  try {
 
1322
  const user = await this.fetchCurrentUser();
1323
  if (user.role !== 'RESEARCHER') {
1324
  this.auditLog('CONSENT_ACCESS_DENIED', { userId: user.id });
1325
  return;
1326
  }
1327
 
 
 
 
 
 
 
1328
  this.currentParticipant = await this.fetchParticipant(participantId);
1329
  this.currentProject = await this.fetchCurrentProject();
1330
- this.showConsentModal();
1331
  } catch (error) {
1332
  this.handleError(error);
1333
  }
1334
- }
1335
 
1336
  async fetchCurrentUser() {
1337
- // Simulated API call
1338
- return API_RESPONSES.USER;
1339
- }
 
 
1340
 
1341
  async fetchParticipant(participantId) {
1342
- // Simulated API call
1343
  return {
1344
- ...API_RESPONSES.PARTICIPANT,
1345
- id: participantId
 
1346
  };
1347
- }
1348
 
1349
  async fetchCurrentProject() {
1350
- // Simulated API call
1351
- return API_RESPONSES.PROJECT;
1352
- }
1353
-
1354
- async fetchConsentForms(params) {
1355
- // Simulated API call
1356
- return [{
1357
- ...API_RESPONSES.CONSENT_FORM,
1358
- language: params.locale
1359
- }];
1360
- }
1361
-
1362
- createAuditTrail() {
1363
  return {
1364
- "timestamp": new Date().toISOString(),
1365
- "user": {
1366
- "id": this.currentUser.id,
1367
- "role": this.currentUser.role
1368
- },
1369
- "action": "CONSENT_UPDATE",
1370
- "metadata": {
1371
- "formVersion": this.modal.querySelector('#consentVersion').value,
1372
- "language": this.modal.querySelector('#consentLanguage').value,
1373
- "signatureType": this.modal.querySelector('input[name="signatureType"]:checked').value,
1374
- "deviceInfo": {
1375
- "type": this.getDeviceType(),
1376
- "offline": !navigator.onLine
1377
- }
1378
- }
1379
  };
1380
- }
1381
 
1382
- async processPhotoId(file) {
1383
- // Simulated photo processing
1384
- return {
1385
- "success": true,
1386
- "edgesDetected": true,
1387
- "previewUrl": URL.createObjectURL(file),
1388
- "metadata": {
1389
- "fileType": file.type,
1390
- "fileSize": file.size,
1391
- "timestamp": new Date().toISOString()
1392
- }
1393
- };
1394
- }
1395
 
1396
- async generateConsentPDF(data) {
1397
- // Simulated PDF generation
1398
- return {
1399
- "participant": {
1400
- "id": data.participant.id,
1401
- "language": data.participant.language
1402
- },
1403
- "form": {
1404
- "version": data.formVersion,
1405
- "language": this.modal.querySelector('#consentLanguage').value
1406
- },
1407
- "signature": {
1408
- "type": data.signature.type,
1409
- "image": "Base64 encoded signature",
1410
- "timestamp": new Date().toISOString()
1411
- },
1412
- "metadata": {
1413
- "generatedAt": new Date().toISOString(),
1414
- "deviceInfo": this.getDeviceType()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1415
  }
1416
- };
1417
- }
1418
 
1419
- async saveConsent(pdfBlob) {
1420
- const formData = new FormData();
1421
- formData.append('participant_id', this.currentParticipant.id);
1422
- formData.append('pdf', pdfBlob);
1423
- formData.append('audit_trail', JSON.stringify(this.createAuditTrail()));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1424
 
 
 
 
 
1425
  const response = await fetch('/api/consents', {
1426
  method: 'POST',
1427
  body: formData
@@ -1432,7 +1491,7 @@
1432
  }
1433
 
1434
  return await response.json();
1435
- }
1436
 
1437
  async updateParticipantStatus() {
1438
  const newStatus = this.currentParticipant.consentStatus === 'WITHDRAWN' ? 'ACTIVE' : 'ACTIVE';
@@ -1442,9 +1501,9 @@
1442
  'Content-Type': 'application/json'
1443
  },
1444
  body: JSON.stringify({
1445
- "consentStatus": newStatus,
1446
- "updatedAt": new Date().toISOString(),
1447
- "updatedBy": this.currentUser.id
1448
  })
1449
  });
1450
 
@@ -1453,33 +1512,39 @@
1453
  }
1454
 
1455
  return await response.json();
1456
- }
1457
-
1458
- getDeviceType() {
1459
- return /Mobile|Tablet|iPad|iPhone|Android/.test(navigator.userAgent) ? 'mobile' : 'desktop';
1460
- }
1461
 
1462
  handleError(error) {
1463
  console.error('Consent error:', error);
1464
  this.showError(error.message);
1465
- }
1466
 
1467
  showError(message) {
1468
- // Implement error display logic
1469
  alert(message);
1470
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1471
 
1472
  auditLog(action, data) {
1473
  console.log('Audit:', action, data);
1474
  }
1475
- }
1476
-
1477
- // Initialize consent manager
1478
- const consentManager = new ConsentManager();
1479
 
1480
  // Update the existing updateConsent function
1481
  function updateConsent(participantId) {
1482
- consentManager.initializeConsent(participantId);
1483
  }
1484
 
1485
  function closeConsentModal() {
 
1308
  }
1309
  };
1310
 
1311
+ // Consent Management
1312
+ const ConsentManager = {
1313
+ currentParticipant: null,
1314
+ currentProject: null,
1315
+ modal: null,
1316
+ signaturePad: null,
1317
+ identityVerified: false,
1318
+
1319
+ async initialize(participantId) {
 
1320
  try {
1321
+ // Check user role
1322
  const user = await this.fetchCurrentUser();
1323
  if (user.role !== 'RESEARCHER') {
1324
  this.auditLog('CONSENT_ACCESS_DENIED', { userId: user.id });
1325
  return;
1326
  }
1327
 
1328
+ // Check offline status
1329
+ if (!navigator.onLine) {
1330
+ this.handleOfflineMode(participantId);
1331
+ return;
1332
+ }
1333
+
1334
  this.currentParticipant = await this.fetchParticipant(participantId);
1335
  this.currentProject = await this.fetchCurrentProject();
1336
+ this.showModal();
1337
  } catch (error) {
1338
  this.handleError(error);
1339
  }
1340
+ },
1341
 
1342
  async fetchCurrentUser() {
1343
+ return {
1344
+ id: 'user-123',
1345
+ role: 'RESEARCHER'
1346
+ };
1347
+ },
1348
 
1349
  async fetchParticipant(participantId) {
 
1350
  return {
1351
+ id: participantId,
1352
+ language: 'bem_ZM',
1353
+ consentStatus: 'ACTIVE'
1354
  };
1355
+ },
1356
 
1357
  async fetchCurrentProject() {
 
 
 
 
 
 
 
 
 
 
 
 
 
1358
  return {
1359
+ id: 'urban-sustainability',
1360
+ methodology: 'QUALITATIVE'
 
 
 
 
 
 
 
 
 
 
 
 
 
1361
  };
1362
+ },
1363
 
1364
+ showModal() {
1365
+ const template = document.getElementById('consentUpdateModal');
1366
+ const modalContent = template.content.cloneNode(true);
1367
+ this.modal = document.createElement('div');
1368
+ this.modal.appendChild(modalContent);
1369
+ document.body.appendChild(this.modal);
 
 
 
 
 
 
 
1370
 
1371
+ this.initializeSignaturePad();
1372
+ this.loadConsentForms();
1373
+ this.addEventListeners();
1374
+ },
1375
+
1376
+ initializeSignaturePad() {
1377
+ const canvas = this.modal.querySelector('#signaturePad');
1378
+ this.signaturePad = new SignaturePad(canvas, {
1379
+ backgroundColor: 'rgb(255, 255, 255)',
1380
+ penColor: 'rgb(0, 0, 0)'
1381
+ });
1382
+ },
1383
+
1384
+ addEventListeners() {
1385
+ // Language change
1386
+ this.modal.querySelector('#consentLanguage').addEventListener('change', (e) => {
1387
+ this.loadConsentForms(e.target.value);
1388
+ });
1389
+
1390
+ // Signature type change
1391
+ this.modal.querySelectorAll('input[name="signatureType"]').forEach(radio => {
1392
+ radio.addEventListener('change', (e) => {
1393
+ this.handleSignatureTypeChange(e.target.value);
1394
+ });
1395
+ });
1396
+
1397
+ // Process consent
1398
+ this.modal.querySelector('button[onclick="processConsent()"]')
1399
+ .addEventListener('click', () => this.processConsent());
1400
+ },
1401
+
1402
+ async handleSignatureTypeChange(type) {
1403
+ const signaturePad = this.modal.querySelector('#signaturePad');
1404
+ const typeInput = this.modal.querySelector('#typeSignature');
1405
+
1406
+ if (type === 'type') {
1407
+ signaturePad.style.display = 'none';
1408
+ typeInput.style.display = 'block';
1409
+ } else {
1410
+ signaturePad.style.display = 'block';
1411
+ typeInput.style.display = 'none';
1412
+ }
1413
+ },
1414
+
1415
+ async processConsent() {
1416
+ if (!this.identityVerified) {
1417
+ this.showError('Identity verification required');
1418
+ return;
1419
+ }
1420
+
1421
+ try {
1422
+ const signatureData = await this.getSignatureData();
1423
+ if (!signatureData) {
1424
+ this.showError('Signature required');
1425
+ return;
1426
  }
 
 
1427
 
1428
+ const consentData = {
1429
+ participant: this.currentParticipant,
1430
+ formVersion: this.modal.querySelector('#consentVersion').value,
1431
+ language: this.modal.querySelector('#consentLanguage').value,
1432
+ signature: signatureData,
1433
+ metadata: {
1434
+ timestamp: new Date().toISOString(),
1435
+ user: this.currentUser.id
1436
+ }
1437
+ };
1438
+
1439
+ await this.saveConsent(consentData);
1440
+ this.updateParticipantStatus();
1441
+ this.closeModal();
1442
+ this.showSuccess('Consent updated successfully');
1443
+ } catch (error) {
1444
+ this.handleError(error);
1445
+ }
1446
+ },
1447
+
1448
+ async getSignatureData() {
1449
+ const signatureType = this.modal.querySelector('input[name="signatureType"]:checked').value;
1450
+
1451
+ switch (signatureType) {
1452
+ case 'draw':
1453
+ if (this.signaturePad.isEmpty()) return null;
1454
+ return {
1455
+ type: 'DIGITAL',
1456
+ image: await this.signaturePad.toDataURL()
1457
+ };
1458
+
1459
+ case 'type':
1460
+ const typedName = this.modal.querySelector('#typeSignature').value;
1461
+ if (!typedName) return null;
1462
+ return {
1463
+ type: 'TYPED',
1464
+ text: typedName
1465
+ };
1466
+
1467
+ case 'witness':
1468
+ const witnessData = await this.getWitnessSignature();
1469
+ if (!witnessData) return null;
1470
+ return {
1471
+ type: 'WITNESS',
1472
+ ...witnessData
1473
+ };
1474
+
1475
+ default:
1476
+ return null;
1477
+ }
1478
+ },
1479
 
1480
+ async saveConsent(consentData) {
1481
+ const formData = new FormData();
1482
+ formData.append('consent', JSON.stringify(consentData));
1483
+
1484
  const response = await fetch('/api/consents', {
1485
  method: 'POST',
1486
  body: formData
 
1491
  }
1492
 
1493
  return await response.json();
1494
+ },
1495
 
1496
  async updateParticipantStatus() {
1497
  const newStatus = this.currentParticipant.consentStatus === 'WITHDRAWN' ? 'ACTIVE' : 'ACTIVE';
 
1501
  'Content-Type': 'application/json'
1502
  },
1503
  body: JSON.stringify({
1504
+ consentStatus: newStatus,
1505
+ updatedAt: new Date().toISOString(),
1506
+ updatedBy: this.currentUser.id
1507
  })
1508
  });
1509
 
 
1512
  }
1513
 
1514
  return await response.json();
1515
+ },
 
 
 
 
1516
 
1517
  handleError(error) {
1518
  console.error('Consent error:', error);
1519
  this.showError(error.message);
1520
+ },
1521
 
1522
  showError(message) {
 
1523
  alert(message);
1524
+ },
1525
+
1526
+ showSuccess(message) {
1527
+ const toast = document.createElement('div');
1528
+ toast.className = 'fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded shadow-lg';
1529
+ toast.textContent = message;
1530
+ document.body.appendChild(toast);
1531
+ setTimeout(() => toast.remove(), 3000);
1532
+ },
1533
+
1534
+ closeModal() {
1535
+ if (this.modal) {
1536
+ this.modal.remove();
1537
+ }
1538
+ },
1539
 
1540
  auditLog(action, data) {
1541
  console.log('Audit:', action, data);
1542
  }
1543
+ };
 
 
 
1544
 
1545
  // Update the existing updateConsent function
1546
  function updateConsent(participantId) {
1547
+ ConsentManager.initialize(participantId);
1548
  }
1549
 
1550
  function closeConsentModal() {