Skip to content

Commit f6ae1b1

Browse files
committed
Apply logic transformation to interaction search. #2
1 parent f885734 commit f6ae1b1

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

app/src/scenes/Combos/combos.reducer.js

+36-2
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,54 @@ export const getComboCount = (state: State) => {
120120
return (count * (count - 1)) / 2;
121121
};
122122

123+
// NOTE: This is copied from the logic here:
124+
// https://github.com/TripSit/factsheets/blob/058f9efde34de0a61d1530781f3513046ddb814a/routes/index.js#L294-L310
125+
const transformIdForInteractionSearch = (substance: Substance): string => {
126+
if (substance.id.match(/^do.$/i)) {
127+
return "dox";
128+
} else if (substance.id.match(/^2c-.$/i)) {
129+
return "2c-x";
130+
} else if (substance.id.match(/^5-meo-..t$/i)) {
131+
return "5-meo-xxt";
132+
} else if (includes("benzodiazepine", substance.categories)) {
133+
return "benzodiazepines";
134+
} else if (includes("opioid", substance.categories)) {
135+
return "opioids";
136+
} else if (includes("stimulant", substance.categories)) {
137+
return "amphetamines";
138+
}
139+
return substance.id;
140+
};
141+
123142
const defaultInteraction = {
124143
interaction: "unknown",
125144
status: "unknown",
126145
description: "",
127146
};
128147

129148
export const getInteraction = (ids: string[]): Interaction => {
149+
const first = getSubstance(ids[0]);
150+
const second = getSubstance(ids[1]);
151+
152+
const firstSearchId = transformIdForInteractionSearch(first);
153+
const secondSearchId = transformIdForInteractionSearch(second);
154+
155+
const searchIds = [firstSearchId, secondSearchId];
156+
130157
const interaction = find((interaction: Interaction) => {
131158
// If the difference between this substance's IDs array and our target IDs
132159
// array is empty, then this interaction is a match.
133-
return isEmpty(difference(interaction.ids, ids));
160+
return isEmpty(difference(interaction.ids, searchIds));
134161
})(interactions);
135162

136-
return isEmpty(interaction) ? { ...defaultInteraction, ids } : interaction;
163+
// If we find a real interaction for these 2 substances, then return it now,
164+
// this is our best case scenario. Otherwise we fall back on alternative
165+
// matching methods.
166+
if (!isEmpty(interaction)) {
167+
return interaction;
168+
}
169+
170+
return { ...defaultInteraction, ids };
137171
};
138172

139173
type Combo = [string, string];

0 commit comments

Comments
 (0)