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

[DC-781] Create service endpoint stub for creating a Snapshot Request #1537

Merged
merged 17 commits into from
Nov 17, 2023

Conversation

rjohanek
Copy link
Contributor

@rjohanek rjohanek commented Nov 9, 2023

Create stub service endpoint for requesting access to a snapshot (creating a request)

Copy link
Member

@pshapiro4broad pshapiro4broad left a comment

Choose a reason for hiding this comment

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

I'm not sure the oneOf yaml will work; adding a test that specifies a complete snapshot request would be a way to help validate this.

description: Criteria Group specifying a Cohort.

SnapshotBuilderAnyCriteria:
oneOf:
Copy link
Member

Choose a reason for hiding this comment

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

Wow, it will be great if oneOf really works now. I've been avoiding it for a while because the java codegen wasn't usable.

Looking at the code this generates, I'm not sure it's working yet. This generates a type SnapshotBuilderAnyCriteria which is what SnapshotBuilderCriteriaGroup uses for its criteria field. However the oneOf subtypes SnapshotBuilderDomainOption and SnapshotBuilderProgramDataOption are not subtypes of SnapshotBuilderAnyCriteria. They are subtypes of OneOfSnapshotBuilderAnyCriteria (which make them sibling types of SnapshotBuilderAnyCriteria).

Long story short, I don't see how in Java we can get from SnapshotBuilderCriteriaGroup.criteria to a subtype class like SnapshotBuilderDomainOption. I'd like to see an example of that before merging this change in.

Copy link
Contributor Author

@rjohanek rjohanek Nov 14, 2023

Choose a reason for hiding this comment

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

Ah okay I see I will look into this. Instead of defining AnyCriteria as its own component, I could define SnapshotBuilderCriteriaGroup.criteria as a list of type SnapshotBuilderDomainOption or SnapshotBuilderProgramDataOption maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay removing the explicit definition of AnyCriteria seems to get rid of the extra class definition. So now there is OneOfSnapshotBuilderCriteriaGroupCriteriaItems which has two subtypes SnapshotBuilderDomainOption or SnapshotBuilderProgramDataOption. The name is not ideal, but I wonder what you think of this approach.

new SnapshotBuilderAccessRequest()
.name("name")
.researchPurposeStatement("purpose")
.datasetRequest(new SnapshotBuilderRequest());
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit messy but I think we need to test the entire API as specified in the yaml, so the request needs to include cohorts, concept sets and value set.

post:
tags:
- datasets
description: Create a new snapshot request.
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if a user journey type description would be helpful here. Something like "As a researcher, create a snapshot request for a dataset, given a set of criteria and required concept sets and values."?

type: array
items:
oneOf:
- $ref: '#/components/schemas/SnapshotBuilderDomainOption'
Copy link
Member

Choose a reason for hiding this comment

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

I think you may need a new type for this. The Option versions of these types are like "prototype" or "source" versions. For a selected domain option, the only value needed is the option's concept code. The Domain root (which I think the UI calls category) may also be helpful to include for non-OMOP cases. For OMOP data the code is unique across all categories so it's sufficient by itself.

Note that a future version of the cohort builder will support other constraints on the codes, like occurrence count and occurrence times.

items:
oneOf:
- $ref: '#/components/schemas/SnapshotBuilderDomainOption'
- $ref: '#/components/schemas/SnapshotBuilderProgramDataOption'
Copy link
Member

Choose a reason for hiding this comment

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

ProgramDataOption might work fine for both cases, even though it is representing a different thing. It may be that the same data is needed for both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could also do SnapshotBuilderConcept (which is the root of DomainOption) and ProgramDataOption, just to keep them separate.

void testCreateSnapshotRequest() throws Exception {
mockValidators();
SnapshotBuilderAccessRequest expected =
new SnapshotBuilderAccessRequest()
Copy link
Member

Choose a reason for hiding this comment

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

Another approach here would be to write the object as JSON. If it's less code I would do it that way instead.

@@ -24,6 +25,12 @@ public SnapshotBuilderSettings updateSnapshotBuilderSettings(
return snapshotBuilderSettingsDao.upsertSnapshotBuilderSettingsByDataset(id, settings);
}

public SnapshotBuilderAccessRequest createSnapshotRequest(
// TODO: add given request to the database, return real JobModel with the id of the new entry.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This comment is no longer accurate wrt the JobModel. Also, could you reference the specific ticket number?

Copy link
Member

@pshapiro4broad pshapiro4broad left a comment

Choose a reason for hiding this comment

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

Looks good, just a few minor comments left

conceptSets:
type: array
items:
$ref: '#/components/schemas/SnapshotBuilderDatasetConceptSets'
Copy link
Member

Choose a reason for hiding this comment

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

I think this type should be called SnapshotBuilderDatasetConceptSet since it's a single concept set. It's an existing type but it'd be good to rename it now if it's not a lot of extra work.

Suggested change
$ref: '#/components/schemas/SnapshotBuilderDatasetConceptSets'
$ref: '#/components/schemas/SnapshotBuilderDatasetConceptSet'

Comment on lines +6833 to +6838
discriminator:
propertyName: kind
mapping:
list: '#/components/schemas/SnapshotBuilderProgramDataListCriteria'
range: '#/components/schemas/SnapshotBuilderProgramDataRangeCriteria'
domain: '#/components/schemas/SnapshotBuilderCriteria'
Copy link
Member

Choose a reason for hiding this comment

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

🎉

@@ -239,6 +245,61 @@ void testUpdateSnapshotBuilderSettings() throws Exception {
verify(snapshotBuilderService).updateSnapshotBuilderSettings(DATASET_ID, SETTINGS);
}

@Test
void testCreateCriteriaData() throws Exception {
TestUtils.mapFromJson(
Copy link
Member

Choose a reason for hiding this comment

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

I realize the point here is that the json conversion doesn't throw, but I think a test should have at least one assert per conversion. Something like

    var criteria = TestUtils.mapFromJson(...);
    assertThat(critera.name(), is("name"));

.addCohortsItem(
new SnapshotBuilderCohort()
.name("cohort")
.addCriteriaGroupsItem(new SnapshotBuilderCriteriaGroup()))
Copy link
Member

Choose a reason for hiding this comment

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

Can you add at least one criteria to the group? It'd be good to have another check for round-trip operations on the oneOf objects.

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

83.3% 83.3% Coverage
0.0% 0.0% Duplication

@rjohanek rjohanek merged commit d460c6b into develop Nov 17, 2023
@rjohanek rjohanek deleted the DC-781 branch November 17, 2023 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants