|
| 1 | +// app/lib/generators/medical-information-generator.js |
| 2 | + |
| 3 | +const { generateSymptoms } = require('./medical-information/symptoms-generator') |
| 4 | +const { generateHRT } = require('./medical-information/hrt-generator') |
| 5 | +const { |
| 6 | + generatePregnancyAndBreastfeeding |
| 7 | +} = require('./medical-information/pregnancy-and-breastfeeding-generator') |
| 8 | +const { |
| 9 | + generateOtherMedicalInformation |
| 10 | +} = require('./medical-information/other-medical-information-generator') |
| 11 | +const { |
| 12 | + generateBreastFeatures |
| 13 | +} = require('./medical-information/breast-features-generator') |
| 14 | +const { |
| 15 | + generateMedicalHistory |
| 16 | +} = require('./medical-information/medical-history-generator') |
| 17 | + |
| 18 | +/** |
| 19 | + * Generate complete medical information for an event |
| 20 | + * |
| 21 | + * All medical information is attributed to the user who ran the appointment |
| 22 | + * |
| 23 | + * @param {object} options - Generation options |
| 24 | + * @param {string} [options.addedByUserId] - User ID who collected this information (typically from sessionDetails.startedBy) |
| 25 | + * @param {number} [options.probabilityOfSymptoms=0.15] - Chance of having symptoms |
| 26 | + * @param {number} [options.probabilityOfHRT=0.30] - Chance of having HRT data |
| 27 | + * @param {number} [options.probabilityOfPregnancyBreastfeeding=0.05] - Chance of having pregnancy/breastfeeding data |
| 28 | + * @param {number} [options.probabilityOfOtherMedicalInfo=0.20] - Chance of having other medical information |
| 29 | + * @param {number} [options.probabilityOfBreastFeatures=0.15] - Chance of having breast features |
| 30 | + * @param {number} [options.probabilityOfMedicalHistory=0.50] - Chance of having medical history |
| 31 | + * @param {Array} [options.forceMedicalHistoryTypes] - Array of medical history types to force generation (e.g. ['breastCancer', 'cysts']) |
| 32 | + * @param {object} [options.config] - Participant config for overrides and forced generation |
| 33 | + * @returns {object} Complete medicalInformation object |
| 34 | + */ |
| 35 | +const generateMedicalInformation = (options = {}) => { |
| 36 | + const { |
| 37 | + addedByUserId, |
| 38 | + probabilityOfSymptoms = 0.15, |
| 39 | + probabilityOfHRT = 0.3, |
| 40 | + probabilityOfPregnancyBreastfeeding = 0.05, |
| 41 | + probabilityOfOtherMedicalInfo = 0.2, |
| 42 | + probabilityOfBreastFeatures = 0.15, |
| 43 | + probabilityOfMedicalHistory = 0.5, |
| 44 | + forceMedicalHistoryTypes, |
| 45 | + config |
| 46 | + } = options |
| 47 | + |
| 48 | + const medicalInfo = {} |
| 49 | + |
| 50 | + // Generate symptoms |
| 51 | + const symptoms = generateSymptoms({ |
| 52 | + probabilityOfSymptoms, |
| 53 | + addedByUserId |
| 54 | + }) |
| 55 | + |
| 56 | + if (symptoms.length > 0) { |
| 57 | + medicalInfo.symptoms = symptoms |
| 58 | + } |
| 59 | + |
| 60 | + // Generate HRT information |
| 61 | + const hrt = generateHRT({ |
| 62 | + probability: probabilityOfHRT |
| 63 | + }) |
| 64 | + |
| 65 | + if (hrt) { |
| 66 | + medicalInfo.hrt = hrt |
| 67 | + } |
| 68 | + |
| 69 | + // Generate pregnancy and breastfeeding information |
| 70 | + const pregnancyAndBreastfeeding = generatePregnancyAndBreastfeeding({ |
| 71 | + probability: probabilityOfPregnancyBreastfeeding |
| 72 | + }) |
| 73 | + |
| 74 | + if (pregnancyAndBreastfeeding) { |
| 75 | + medicalInfo.pregnancyAndBreastfeeding = pregnancyAndBreastfeeding |
| 76 | + } |
| 77 | + |
| 78 | + // Generate other medical information |
| 79 | + const otherMedicalInformation = generateOtherMedicalInformation({ |
| 80 | + probability: probabilityOfOtherMedicalInfo |
| 81 | + }) |
| 82 | + |
| 83 | + if (otherMedicalInformation) { |
| 84 | + medicalInfo.otherMedicalInformation = otherMedicalInformation |
| 85 | + } |
| 86 | + |
| 87 | + // Generate medical history |
| 88 | + const medicalHistory = generateMedicalHistory({ |
| 89 | + addedByUserId, |
| 90 | + probability: probabilityOfMedicalHistory, |
| 91 | + forceMedicalHistoryTypes, |
| 92 | + config |
| 93 | + }) |
| 94 | + |
| 95 | + if (Object.keys(medicalHistory).length > 0) { |
| 96 | + medicalInfo.medicalHistory = medicalHistory |
| 97 | + } |
| 98 | + |
| 99 | + // Generate breast features |
| 100 | + const breastFeatures = generateBreastFeatures({ |
| 101 | + probabilityOfAnyFeatures: probabilityOfBreastFeatures, |
| 102 | + config |
| 103 | + }) |
| 104 | + |
| 105 | + if (breastFeatures && breastFeatures.length > 0) { |
| 106 | + medicalInfo.breastFeatures = breastFeatures |
| 107 | + } |
| 108 | + |
| 109 | + return medicalInfo |
| 110 | +} |
| 111 | + |
| 112 | +module.exports = { |
| 113 | + generateMedicalInformation |
| 114 | +} |
0 commit comments