Skip to content
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

Merged
merged 3 commits into from
Jan 14, 2022
Merged

Conversation

csandersdev
Copy link
Contributor

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

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>
@lmsurpre
Copy link
Member

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(Object resource : cursor) {
for (Object resource : cursor) {

Comment on lines 63 to 64


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return loadResourceById(resourceHelper, ResourceType.MEASURE, reference);
}

public static Library loadLibraryByReference(FHIRResourceHelpers resourceHelper, String reference) throws FHIROperationException {
Copy link
Contributor

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.

Comment on lines 72 to 73


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

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 ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc

Copy link
Contributor

@prb112 prb112 left a 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 {
Copy link
Collaborator

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 ) {
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

@punktilious punktilious Jan 13, 2022

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 ) {
Copy link
Collaborator

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants