@@ -120,20 +120,54 @@ export const getComboCount = (state: State) => {
120
120
return ( count * ( count - 1 ) ) / 2 ;
121
121
} ;
122
122
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 ( / ^ d o .$ / i) ) {
127
+ return "dox" ;
128
+ } else if ( substance . id . match ( / ^ 2 c - .$ / i) ) {
129
+ return "2c-x" ;
130
+ } else if ( substance . id . match ( / ^ 5 - m e o - ..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
+
123
142
const defaultInteraction = {
124
143
interaction : "unknown" ,
125
144
status : "unknown" ,
126
145
description : "" ,
127
146
} ;
128
147
129
148
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
+
130
157
const interaction = find ( ( interaction : Interaction ) => {
131
158
// If the difference between this substance's IDs array and our target IDs
132
159
// array is empty, then this interaction is a match.
133
- return isEmpty ( difference ( interaction . ids , ids ) ) ;
160
+ return isEmpty ( difference ( interaction . ids , searchIds ) ) ;
134
161
} ) ( interactions ) ;
135
162
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 } ;
137
171
} ;
138
172
139
173
type Combo = [ string , string ] ;
0 commit comments