-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#3061 - Fix NPE when Measure refers to non-existent library #3187
Conversation
I applied a fix before the holiday that corrected a category of NPE errors related to execution against a measure or library resources that don't exist. It turns out that wasn't the core of the issue 3061. This goes back and addresses when a valid measure reference is used, but that Measure refers to a Library resource that does not exist. I also added some handling that allows resolution of Library resources by reference in addition to by canonical URL in the registry and also updated the error handling around retrieving the primary library reference from the Measure resource. Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com>
please update the copyright dates. otherwise, looks good to me. |
Bundle.Builder reports = Bundle.builder().type(BundleType.COLLECTION); | ||
|
||
AtomicInteger count = new AtomicInteger(0); | ||
cursor.forEach(resource -> { | ||
for(Object resource : cursor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for(Object resource : cursor) { | |
for (Object resource : cursor) { |
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return loadResourceById(resourceHelper, ResourceType.MEASURE, reference); | ||
} | ||
|
||
public static Library loadLibraryByReference(FHIRResourceHelpers resourceHelper, String reference) throws FHIROperationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadocs for consistency would be great.
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when(resourceHelper.doRead(eq("Library"), eq(primaryLibrary.getId()), anyBoolean(), anyBoolean(), any())).thenAnswer(x -> TestHelper.asResult(primaryLibrary)); | ||
|
||
fhirLibraries.stream().forEach( l -> when(mockRegistry.getResource( canonical(l.getUrl(), l.getVersion()).getValue(), Library.class )).thenReturn(l) ); | ||
if( exists ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if( exists ) { | |
if (exists) { |
@@ -86,19 +79,16 @@ public RetrieveProvider getRetrieveProvider(FHIRResourceHelpers resourceHelper, | |||
return retrieveProvider; | |||
} | |||
|
|||
public MeasureReport.Builder doMeasureEvaluation(Measure measure, ZoneOffset zoneOffset, Interval measurementPeriod, String subjectOrPractitionerId, | |||
public MeasureReport.Builder doMeasureEvaluation(FHIRResourceHelpers resourceHelpers, Measure measure, ZoneOffset zoneOffset, Interval measurementPeriod, String subjectOrPractitionerId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, copyright updates (as Lee mentioned)
* Utility methods for working with Measure resources | ||
*/ | ||
public class MeasureHelper { | ||
public static String getPrimaryLibraryId(Measure measure) throws FHIROperationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc
public class MeasureHelper { | ||
public static String getPrimaryLibraryId(Measure measure) throws FHIROperationException { | ||
String primaryLibraryId = null; | ||
if( measure.getLibrary() != null && measure.getLibrary().size() == 1 ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (measure.getLibrary() ...
@@ -98,16 +98,16 @@ protected Parameters doInvoke(FHIROperationContext operationContext, Class<? ext | |||
} | |||
} | |||
|
|||
protected Bundle processAllMeasures(FHIRBundleCursor cursor, String subject, ZoneOffset zoneOffset, Interval measurementPeriod, FHIRResourceHelpers resourceHelper, TerminologyProvider termProvider, Map<String,DataProvider> dataProviders) { | |||
protected Bundle processAllMeasures(FHIRBundleCursor cursor, String subject, ZoneOffset zoneOffset, Interval measurementPeriod, FHIRResourceHelpers resourceHelper, TerminologyProvider termProvider, Map<String,DataProvider> dataProviders) throws FHIROperationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc nice to have (must have for public methods)
import com.ibm.fhir.registry.FHIRRegistry; | ||
import com.ibm.fhir.server.spi.operation.FHIRResourceHelpers; | ||
|
||
public class OperationHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc
return result; | ||
} | ||
|
||
public static Measure loadMeasureByReference(FHIRResourceHelpers resourceHelper, String reference) throws FHIROperationException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
javadoc...for all the public methods in this class
when(resourceHelper.doRead(eq("Library"), eq(primaryLibrary.getId()), anyBoolean(), anyBoolean(), any())).thenAnswer(x -> TestHelper.asResult(primaryLibrary)); | ||
|
||
fhirLibraries.stream().forEach( l -> when(mockRegistry.getResource( canonical(l.getUrl(), l.getVersion()).getValue(), Library.class )).thenReturn(l) ); | ||
if( exists ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (exists)
Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com>
Signed-off-by: Corey Sanders <corey.thecolonel@gmail.com>
4d78598
to
03bae4e
Compare
I applied a fix before the holiday that corrected a category of NPE
errors related to execution against measure or library resources that
don't exist. It turns out that wasn't the core of the issue 3061. This
goes back and addresses when a valid measure reference is used, but that
Measure refers to a Library resource that does not exist. I also added
some handling that allows resolution of Library resources by reference
in addition to by canonical URL in the registry and also updated the
error handling around retrieving the primary library reference from the
Measure resource.
Signed-off-by: Corey Sanders corey.thecolonel@gmail.com