-
Notifications
You must be signed in to change notification settings - Fork 2
/
MLInteractionsCart.m
116 lines (97 loc) · 4.57 KB
/
MLInteractionsCart.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
Copyright (c) 2017 Max Lungarella <[email protected]>
Created on 11/08/2017.
This file is part of AmiKo for OSX.
AmiKo for OSX is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
------------------------------------------------------------------------ */
#import "MLInteractionsCart.h"
#import "MLMedication.h"
@implementation MLInteractionsCart
@synthesize cart;
- (id) init
{
cart = [[NSMutableDictionary alloc] init];
return [super init];
}
- (NSInteger) size
{
return [cart count];
}
- (NSString *) interactionsAsHtmlForAdapter:(MLInteractionsAdapter *)adapter withTitles:(NSMutableArray *)titles andIds:(NSMutableArray *)ids
{
NSMutableString *htmlStr = [[NSMutableString alloc] initWithString:@""];
// Check if there are meds in the "Medikamentenkorb"
if ([self size]>1) {
// First sort them alphabetically
NSArray *sortedNames = [[cart allKeys] sortedArrayUsingSelector: @selector(compare:)];
// Big loop
for (NSString *name1 in sortedNames) {
for (NSString *name2 in sortedNames) {
if (![name1 isEqualToString:name2]) {
// Extract meds by names from interaction basket
MLMedication *med1 = [cart valueForKey:name1];
MLMedication *med2 = [cart valueForKey:name2];
// Get ATC codes from interaction db
NSArray *m_code1 = [[med1 atccode] componentsSeparatedByString:@";"];
NSArray *m_code2 = [[med2 atccode] componentsSeparatedByString:@";"];
NSArray *atc1 = nil;
NSArray *atc2 = nil;
if ([m_code1 count]>1)
atc1 = [[m_code1 objectAtIndex:0] componentsSeparatedByString:@","];
if ([m_code2 count]>1)
atc2 = [[m_code2 objectAtIndex:0] componentsSeparatedByString:@","];
NSString *atc_code1 = @"";
NSString *atc_code2 = @"";
if (atc1!=nil && [atc1 count]>0) {
for (atc_code1 in atc1) {
if (atc2!=nil && [atc2 count]>0) {
for (atc_code2 in atc2) {
NSString *html = [adapter getInteractionHtmlBetween:atc_code1 and:atc_code2];
if (html!=nil) {
// Replace all occurrences of atc codes by med names apart from the FIRST one!
NSRange range1 = [html rangeOfString:atc_code1 options:NSBackwardsSearch];
html = [html stringByReplacingCharactersInRange:range1 withString:name1];
NSRange range2 = [html rangeOfString:atc_code2 options:NSBackwardsSearch];
html = [html stringByReplacingCharactersInRange:range2 withString:name2];
// Concatenate strings
[htmlStr appendString:html];
// Add to title and anchor lists
[titles addObject:[NSString stringWithFormat:@"%@ \u2192 %@", name1, name2]];
[ids addObject:[NSString stringWithFormat:@"%@-%@", atc_code1, atc_code2]];
}
}
}
}
}
}
}
}
}
return htmlStr;
}
- (NSInteger) inferRiskClass:(NSString *)str
{
if ([str containsString:@"paragraphA"]) {
return 0;
} else if ([str containsString:@"paragraphB"]) {
return 1;
} else if ([str containsString:@"paragraphC"]) {
return 2;
} else if ([str containsString:@"paragraphD"]) {
return 3;
} else if ([str containsString:@"paragraphX"]) {
return 4;
} else {
return 10;
}
}
@end