Skip to content
This repository was archived by the owner on Aug 3, 2020. It is now read-only.

Commit 626aaba

Browse files
author
Alex Nolasco
committed
Merge branch 'develop'
# Conflicts: # ccdaviewer/Cartfile.resolved
2 parents b3eb7f1 + 4c74a66 commit 626aaba

26 files changed

+914
-45
lines changed

ccdaparser/ccdaparser.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@
406406
56A585A61CB287A4007B8F3E /* HL7Analyzer.m in Sources */ = {isa = PBXBuildFile; fileRef = 56A585A01CB287A4007B8F3E /* HL7Analyzer.m */; };
407407
56A585A91CB287A4007B8F3E /* HL7Element+Additions.h in Headers */ = {isa = PBXBuildFile; fileRef = 56A585A31CB287A4007B8F3E /* HL7Element+Additions.h */; };
408408
56A585AA1CB287A4007B8F3E /* HL7Element+Additions.m in Sources */ = {isa = PBXBuildFile; fileRef = 56A585A41CB287A4007B8F3E /* HL7Element+Additions.m */; };
409+
56AC55611D9385A5004DED7E /* HL7ResultRangeAnalyzer.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AC555F1D9385A5004DED7E /* HL7ResultRangeAnalyzer.h */; };
410+
56AC55621D9385A5004DED7E /* HL7ResultRangeAnalyzer.m in Sources */ = {isa = PBXBuildFile; fileRef = 56AC55601D9385A5004DED7E /* HL7ResultRangeAnalyzer.m */; };
411+
56AC55641D94B1FF004DED7E /* ResultRanges.plist in Resources */ = {isa = PBXBuildFile; fileRef = 56AC55631D94B1FF004DED7E /* ResultRanges.plist */; };
412+
56AC55681D94D538004DED7E /* HL7ResultRangeAnalyzerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 56AC55671D94D538004DED7E /* HL7ResultRangeAnalyzerTests.m */; };
409413
56AE28441CC84CFC00EF8908 /* HL7Period.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE28421CC84CFC00EF8908 /* HL7Period.h */; };
410414
56AE28451CC84CFC00EF8908 /* HL7Period.m in Sources */ = {isa = PBXBuildFile; fileRef = 56AE28431CC84CFC00EF8908 /* HL7Period.m */; };
411415
56AE28481CC854B100EF8908 /* HL7SubstanceAdministration.h in Headers */ = {isa = PBXBuildFile; fileRef = 56AE28461CC854B100EF8908 /* HL7SubstanceAdministration.h */; };
@@ -963,6 +967,10 @@
963967
56A585A01CB287A4007B8F3E /* HL7Analyzer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HL7Analyzer.m; sourceTree = "<group>"; };
964968
56A585A31CB287A4007B8F3E /* HL7Element+Additions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "HL7Element+Additions.h"; path = "../analyzer/HL7Element+Additions.h"; sourceTree = "<group>"; };
965969
56A585A41CB287A4007B8F3E /* HL7Element+Additions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "HL7Element+Additions.m"; path = "../analyzer/HL7Element+Additions.m"; sourceTree = "<group>"; };
970+
56AC555F1D9385A5004DED7E /* HL7ResultRangeAnalyzer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HL7ResultRangeAnalyzer.h; sourceTree = "<group>"; };
971+
56AC55601D9385A5004DED7E /* HL7ResultRangeAnalyzer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HL7ResultRangeAnalyzer.m; sourceTree = "<group>"; };
972+
56AC55631D94B1FF004DED7E /* ResultRanges.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ResultRanges.plist; sourceTree = "<group>"; };
973+
56AC55671D94D538004DED7E /* HL7ResultRangeAnalyzerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HL7ResultRangeAnalyzerTests.m; sourceTree = "<group>"; };
966974
56AE28421CC84CFC00EF8908 /* HL7Period.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HL7Period.h; sourceTree = "<group>"; };
967975
56AE28431CC84CFC00EF8908 /* HL7Period.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HL7Period.m; sourceTree = "<group>"; };
968976
56AE28461CC854B100EF8908 /* HL7SubstanceAdministration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HL7SubstanceAdministration.h; sourceTree = "<group>"; };
@@ -1192,8 +1200,11 @@
11921200
560C156F1CCDA2A300C07482 /* results */ = {
11931201
isa = PBXGroup;
11941202
children = (
1203+
56AC55631D94B1FF004DED7E /* ResultRanges.plist */,
11951204
560C15701CCDA2CF00C07482 /* HL7ResultAnalyzer.h */,
11961205
560C15711CCDA2CF00C07482 /* HL7ResultAnalyzer.m */,
1206+
56AC555F1D9385A5004DED7E /* HL7ResultRangeAnalyzer.h */,
1207+
56AC55601D9385A5004DED7E /* HL7ResultRangeAnalyzer.m */,
11971208
);
11981209
path = results;
11991210
sourceTree = "<group>";
@@ -1565,6 +1576,7 @@
15651576
56A583B91CB20529007B8F3E /* ccdaparserTests */ = {
15661577
isa = PBXGroup;
15671578
children = (
1579+
56AC55671D94D538004DED7E /* HL7ResultRangeAnalyzerTests.m */,
15681580
56BC02DC1CFCAF140013C380 /* removeSpacesTests.m */,
15691581
56EF9AF51CDE6E51002ED9B3 /* HL7SectionMapperTests.m */,
15701582
560C15841CCDB3E900C07482 /* HL7InterpretationCodeTests.m */,
@@ -2461,6 +2473,7 @@
24612473
56D420901CD59D93006748CD /* HL7ProcedureSection.h in Headers */,
24622474
56BC02DA1CFCAE2F0013C380 /* NSString+StripSpaces.h in Headers */,
24632475
56AE28651CC9A22900EF8908 /* HL7MedicationSubstanceAdministrationParser.h in Headers */,
2476+
56AC55611D9385A5004DED7E /* HL7ResultRangeAnalyzer.h in Headers */,
24642477
56A585A51CB287A4007B8F3E /* HL7Analyzer.h in Headers */,
24652478
56E1928C1CD6D345009AD1B5 /* HL7EncounterActivityParser.h in Headers */,
24662479
5678C7CE1CE56D510023F2EC /* NSString+ObjectiveSugar.h in Headers */,
@@ -2658,6 +2671,7 @@
26582671
buildActionMask = 2147483647;
26592672
files = (
26602673
560C15811CCDA5FC00C07482 /* Localizable.strings in Resources */,
2674+
56AC55641D94B1FF004DED7E /* ResultRanges.plist in Resources */,
26612675
);
26622676
runOnlyForDeploymentPostprocessing = 0;
26632677
};
@@ -2744,6 +2758,7 @@
27442758
56E1925A1CD6878C009AD1B5 /* HL7ProcedureActivityObservation.m in Sources */,
27452759
560C15731CCDA2D000C07482 /* HL7ResultAnalyzer.m in Sources */,
27462760
56A5847F1CB2183E007B8F3E /* HL7Telecom.m in Sources */,
2761+
56AC55621D9385A5004DED7E /* HL7ResultRangeAnalyzer.m in Sources */,
27472762
5670F2A21CD2D2AF001C5FCF /* HL7PatientInstructionsSectionParser.m in Sources */,
27482763
56A584871CB2183E007B8F3E /* HL7Time.m in Sources */,
27492764
56245BA51CC45D0100EBCC79 /* HL7InterpretationCode.m in Sources */,
@@ -2920,6 +2935,7 @@
29202935
56A585921CB21F16007B8F3E /* HL7IdentifierFromReaderTests.m in Sources */,
29212936
56A585961CB21F16007B8F3E /* HL7AddrTests.m in Sources */,
29222937
56245BCB1CC49D6200EBCC79 /* HL7VitalSignsSectionParserTests.m in Sources */,
2938+
56AC55681D94D538004DED7E /* HL7ResultRangeAnalyzerTests.m in Sources */,
29232939
56BC02DD1CFCAF140013C380 /* removeSpacesTests.m in Sources */,
29242940
56A585951CB21F16007B8F3E /* HL7GuardianParserTests.m in Sources */,
29252941
560FEE801CB492EB00131529 /* HL7OriginalTextTests.m in Sources */,

ccdaparser/ccdaparser/analyzer/section/results/HL7ResultAnalyzer.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,35 @@
3232
#import "HL7ResultSection.h"
3333
#import "HL7ResultObservation.h"
3434
#import "HL7ResultOrganizer.h"
35+
#import "HL7ResultRangeAnalyzer.h"
36+
#import "HL7ClinicalDocument.h"
37+
#import "HL7PatientRole.h"
38+
#import "HL7Patient.h"
39+
40+
@interface HL7ResultAnalyzer ()
41+
@property (nonatomic, strong) HL7ResultRangeAnalyzer * resultRangeAnalyzer;
42+
@end
3543

3644
@implementation HL7ResultAnalyzer
45+
- (HL7ResultRangeAnalyzer *) resultRangeAnalyzer
46+
{
47+
if (_resultRangeAnalyzer == nil) {
48+
_resultRangeAnalyzer = [HL7ResultRangeAnalyzer new];
49+
}
50+
return _resultRangeAnalyzer;
51+
}
52+
3753
- (NSString *_Nullable)templateId
3854
{
3955
return HL7TemplateResultsEntriesRequired;
4056
}
4157

42-
- (HL7ResultSummaryEntry *_Nullable)createSummaryEntryFromElement:(HL7ResultObservation *)observation
58+
- (HL7ResultSummaryEntry *_Nullable)createSummaryEntryFromElement:(HL7ResultObservation *)observation genderCode:(HL7AdministrativeGenderCode) genderCode
4359
{
4460
if (![observation isEmpty]) {
45-
return [[HL7ResultSummaryEntry alloc] initWithObservation:observation];
61+
HL7ResultSummaryEntry * summaryEntry = [[HL7ResultSummaryEntry alloc] initWithObservation:observation];
62+
summaryEntry.resultRange = [self.resultRangeAnalyzer resultRangeForSummaryEntry:observation forGender:genderCode];
63+
return summaryEntry;
4664
}
4765
return nil;
4866
}
@@ -52,9 +70,11 @@ - (HL7ResultSummaryEntry *_Nullable)createSummaryEntryFromElement:(HL7ResultObse
5270
HL7ResultSection *section = (HL7ResultSection *)[document getSectionByTemplateId:[self templateId]];
5371
HL7ResultSummary *summary = [[HL7ResultSummary alloc] initWithElement:section];
5472

73+
5574
for (HL7ResultEntry *entry in [section entries]) {
5675
for (HL7ResultObservation *observation in [[entry organizer] observations]) {
57-
HL7ResultSummaryEntry *summaryEntry = [self createSummaryEntryFromElement:observation];
76+
// gender must have been analyzed prior to this section
77+
HL7ResultSummaryEntry *summaryEntry = [self createSummaryEntryFromElement:observation genderCode:document.clinicalDocument.patientRole.patient.gender];
5878
if (summaryEntry != nil) {
5979
[[summary entries] addObject:summaryEntry];
6080
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/********************************************************************************
2+
* The MIT License (MIT) *
3+
* *
4+
* Copyright (C) 2016 Alex Nolasco *
5+
* *
6+
*Permission is hereby granted, free of charge, to any person obtaining a copy *
7+
*of this software and associated documentation files (the "Software"), to deal *
8+
*in the Software without restriction, including without limitation the rights *
9+
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
10+
*copies of the Software, and to permit persons to whom the Software is *
11+
*furnished to do so, subject to the following conditions: *
12+
*The above copyright notice and this permission notice shall be included in *
13+
*all copies or substantial portions of the Software. *
14+
* *
15+
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
16+
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
17+
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
18+
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19+
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
20+
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
21+
*THE SOFTWARE. *
22+
*********************************************************************************/
23+
24+
25+
#import <Foundation/Foundation.h>
26+
#import "HL7Enums.h"
27+
@class HL7ResultObservation;
28+
29+
@interface HL7ResultRangeAnalyzer : NSObject
30+
- (HL7ResultRange) resultRangeForSummaryEntry: (HL7ResultObservation *)resultObservation forGender:(HL7AdministrativeGenderCode) genderCode;
31+
@end
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/********************************************************************************
2+
* The MIT License (MIT) *
3+
* *
4+
* Copyright (C) 2016 Alex Nolasco *
5+
* *
6+
*Permission is hereby granted, free of charge, to any person obtaining a copy *
7+
*of this software and associated documentation files (the "Software"), to deal *
8+
*in the Software without restriction, including without limitation the rights *
9+
*to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
10+
*copies of the Software, and to permit persons to whom the Software is *
11+
*furnished to do so, subject to the following conditions: *
12+
*The above copyright notice and this permission notice shall be included in *
13+
*all copies or substantial portions of the Software. *
14+
* *
15+
*THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
16+
*IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
17+
*FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
18+
*AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19+
*LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
20+
*OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
21+
*THE SOFTWARE. *
22+
*********************************************************************************/
23+
24+
25+
#import "HL7ResultRangeAnalyzer.h"
26+
#import "HL7ResultObservation.h"
27+
#import "HL7Code.h"
28+
#import "HL7ResultReferenceRange.h"
29+
#import "HL7ResultObservationRange.h"
30+
#import "HL7Value.h"
31+
32+
const static NSString* kHL7ResultRangeAnalyzerClassType = @"classType";
33+
const static NSString* kHL7ResultRangeAnalyzerUnits = @"units";
34+
const static NSString* kHL7ResultRangeAnalyzerRanges = @"ranges";
35+
const static NSString* kHL7ResultRangeAnalyzerBoth = @"both";
36+
const static NSString* kHL7ResultRangeAnalyzerFemale = @"female";
37+
const static NSString* kHL7ResultRangeAnalyzerMale = @"male";
38+
const static NSString* kHL7ResultRangeAnalyzerMinimum = @"min";
39+
const static NSString* kHL7ResultRangeAnalyzerMaximum = @"max";
40+
41+
@interface HL7ResultRangeAnalyzer()
42+
@property (nonatomic, strong) NSDictionary * loincCodes;
43+
@end
44+
45+
@implementation HL7ResultRangeAnalyzer
46+
47+
- (NSDictionary *) loadDictionaryFromBundleWithName: (NSString *) name
48+
{
49+
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
50+
NSString *plistPath = [bundle pathForResource:name ofType:@"plist"];
51+
return [NSDictionary dictionaryWithContentsOfFile:plistPath];
52+
}
53+
54+
- (NSDictionary *) loincCodes
55+
{
56+
if (_loincCodes == nil) {
57+
_loincCodes = [self loadDictionaryFromBundleWithName:@"ResultRanges"];
58+
}
59+
return _loincCodes;
60+
}
61+
62+
63+
- (HL7ResultRange) resultRangeForSummaryEntry: (HL7ResultObservation *)resultObservation forGender:(HL7AdministrativeGenderCode) genderCode
64+
{
65+
HL7Value * resultValue = resultObservation.value;
66+
67+
68+
if (!resultValue || (genderCode!=HL7AdministrativeGenderCodeFemale && genderCode!=HL7AdministrativeGenderCodeMale)) { // no value
69+
return HL7ResultRangeUnknown;
70+
}
71+
72+
if (![resultValue.value length]) {
73+
return HL7ResultRangeUnknown;
74+
}
75+
76+
NSDictionary * codeInfo = [self.loincCodes objectForKey:resultObservation.code.code];
77+
if (!codeInfo) { // no matching code in info file
78+
return HL7ResultRangeUnknown;
79+
}
80+
81+
NSDictionary * ranges = [[codeInfo objectForKey:kHL7ResultRangeAnalyzerUnits] objectForKey:resultValue.unit];
82+
83+
if (ranges == nil) { // no ranges found, bad info file
84+
return HL7ResultRangeUnknown;
85+
}
86+
87+
// See if it is gender specific
88+
NSDictionary * genderRange = [ranges objectForKey:kHL7ResultRangeAnalyzerBoth];
89+
if (genderRange == nil && genderCode == HL7AdministrativeGenderCodeFemale) {
90+
genderRange = [ranges objectForKey:kHL7ResultRangeAnalyzerFemale];
91+
}
92+
else if (genderRange == nil && genderCode == HL7AdministrativeGenderCodeMale) {
93+
genderRange = [ranges objectForKey:kHL7ResultRangeAnalyzerMale];
94+
}
95+
96+
if (genderRange == nil) {
97+
return HL7ResultRangeUnknown;
98+
}
99+
100+
101+
NSNumber * minimum = [genderRange objectForKey:kHL7ResultRangeAnalyzerMinimum];
102+
NSNumber * maximum = [genderRange objectForKey:kHL7ResultRangeAnalyzerMaximum];
103+
104+
105+
if (maximum == nil || minimum == nil) {
106+
return HL7ResultRangeUnknown;
107+
}
108+
109+
if ([resultValue.valueAsDecimalNumber floatValue] < [minimum floatValue]) {
110+
return HL7ResultRangeBelowNormal;
111+
}
112+
113+
if ([resultValue.valueAsDecimalNumber floatValue] > [maximum floatValue]) {
114+
return HL7ResultRangeAboveNormal;
115+
}
116+
117+
return HL7ResultRangeNormal;
118+
}
119+
@end

0 commit comments

Comments
 (0)