Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions scripts/generate-drug-masterlist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function transformSnapshotToProtocols(snapshot) {
const protocols = [];

for (const drug of snapshot.drugs || []) {
const drugName = drug.title;
const drugName = drug.dream?.drug_name || drug.title;
const category = drug.dream?.category || '';
const sourceSlug = drug.slug;
const lastReviewed = drug.last_reviewed;
Expand Down Expand Up @@ -61,11 +61,13 @@ export function transformSnapshotToProtocols(snapshot) {
idtSteps: (protocol.idt || []).map((step) => ({
ratio: step.dilution || '',
concentration: step.concentration || '',
...(step.preparation ? { preparation: step.preparation } : {}),
})),
challengeSteps: [],
protocolLabel: protocol.label,
sourceSlug,
underReview,
...(protocol.review_note ? { reviewNote: protocol.review_note } : {}),
lastReviewed,
...(needsPharmacyVerification ? { needsPharmacyVerification: true } : {}),
});
Expand All @@ -89,6 +91,7 @@ export function transformSnapshotToProtocols(snapshot) {
protocolLabel: `${protocol.label} Challenge`,
sourceSlug,
underReview,
...(protocol.review_note ? { reviewNote: protocol.review_note } : {}),
lastReviewed,
...(needsPharmacyVerification ? { needsPharmacyVerification: true } : {}),
});
Expand All @@ -112,6 +115,7 @@ export function transformSnapshotToProtocols(snapshot) {
protocolLabel: protocol.label,
sourceSlug,
underReview,
...(protocol.review_note ? { reviewNote: protocol.review_note } : {}),
lastReviewed,
...(needsPharmacyVerification ? { needsPharmacyVerification: true } : {}),
});
Expand All @@ -128,11 +132,13 @@ export function transformSnapshotToProtocols(snapshot) {
idtSteps: (protocol.idt || []).map((step) => ({
ratio: step.dilution || '',
concentration: step.concentration || '',
...(step.preparation ? { preparation: step.preparation } : {}),
})),
challengeSteps: [],
protocolLabel: protocol.label,
sourceSlug,
underReview,
...(protocol.review_note ? { reviewNote: protocol.review_note } : {}),
lastReviewed,
...(needsPharmacyVerification ? { needsPharmacyVerification: true } : {}),
});
Expand All @@ -155,7 +161,7 @@ export function generateTypeScript(protocols) {
"import type { DrugProtocol, IDTStep, ChallengeStep } from '@features/testing/types';",
'',
'// Compact helpers for readability',
'const s = (ratio: string, concentration: string): IDTStep => ({ ratio, concentration });',
'const s = (ratio: string, concentration: string, preparation?: string): IDTStep => (preparation ? { ratio, concentration, preparation } : { ratio, concentration });',
'const c = (step: number, dose: string, volume: string, cumulative: string): ChallengeStep => ({ step, dose, volume, cumulative });',
'',
'export const GENERATED_PROTOCOLS: DrugProtocol[] = [',
Expand All @@ -178,7 +184,12 @@ export function generateTypeScript(protocols) {
lines.push(' idtSteps: [],');
} else {
const idtFormatted = p.idtSteps
.map((step) => `s(${formatStringLiteral(step.ratio)}, ${formatStringLiteral(step.concentration)})`)
.map((step) => {
if (step.preparation) {
return `s(${formatStringLiteral(step.ratio)}, ${formatStringLiteral(step.concentration)}, ${formatStringLiteral(step.preparation)})`;
}
return `s(${formatStringLiteral(step.ratio)}, ${formatStringLiteral(step.concentration)})`;
})
.join(', ');
lines.push(` idtSteps: [${idtFormatted}],`);
}
Expand All @@ -199,6 +210,9 @@ export function generateTypeScript(protocols) {
if (p.underReview !== undefined) {
lines.push(` underReview: ${p.underReview},`);
}
if (p.reviewNote) {
lines.push(` reviewNote: ${formatStringLiteral(p.reviewNote)},`);
}
if (p.lastReviewed) {
lines.push(` lastReviewed: ${formatStringLiteral(p.lastReviewed)},`);
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/sync-protocols.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function computeDoseLevelDiff(oldSnapshot, newSnapshot) {
}

const pChanges = [];
const scalarFields = ['label', 'test_type', 'presentation', 'diluent', 'under_review', 'needs_pharmacy_verification'];
const scalarFields = ['label', 'test_type', 'presentation', 'diluent', 'under_review', 'review_note', 'needs_pharmacy_verification'];
for (const field of scalarFields) {
if (oldP[field] !== newP[field]) {
pChanges.push(`${field}: ${JSON.stringify(oldP[field])} -> ${JSON.stringify(newP[field])}`);
Expand Down
Loading