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

fix/HIV app and Guppy #558

Merged
merged 10 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/GuppyDataExplorer/ExplorerFilter/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class ExplorerFilter extends React.Component {
}
}
}
return null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to address a warning found in console while testing using dev.html.
Warning: ExplorerFilter.getSnapshotBeforeUpdate(): A snapshot value (or null) must be returned. You have returned undefined.

}

componentDidUpdate() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to address a warning found in console while testing using dev.html.
Warning: ExplorerFilter: getSnapshotBeforeUpdate() should be used with componentDidUpdate(). This component defines getSnapshotBeforeUpdate() only.

}

/**
Expand Down
56 changes: 54 additions & 2 deletions src/HIVCohortFilter/ECCase.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './HIVCohortFilter.css';
import CohortECSvg from '../img/cohort-EC.svg';
import Spinner from '../components/Spinner';
import HIVCohortFilterCase from './HIVCohortFilterCase';
import { useGuppyForExplorer } from '../configs';

class ECCase extends HIVCohortFilterCase {
/*
Expand Down Expand Up @@ -46,7 +47,58 @@ class ECCase extends HIVCohortFilterCase {
// This is because the EC and LTNP cases uses this function to find people who have
// never received haart treatments; we need to look at *all* their followups.
// (Read the function getBucketByKey() defined in the HIVCohortFilterCase class.)
const query = `
if (useGuppyForExplorer) {
const queryString = `
query ($filter: JSON) {
_aggregation {
follow_up (filter: $filter) {
${bucketKey} {
histogram {
key
count
}
}
}
}
}
`;
const variableString = ` {
"filter": {
"AND": [
{
"${isHAART ? '=' : '!='}": {
"thrpyv": "HAART"
}
},
{
"=": {
"hiv_status": "positive"
}
}
]
}
}`;
return HIVCohortFilterCase.performQuery(queryString, variableString).then((res) => {
/* eslint-disable no-underscore-dangle */
if (!res
|| !res.data
|| !res.data._aggregation
|| !res.data._aggregation.follow_up) {
throw new Error('Error when query subjects with HIV');
}
const result = res.data._aggregation.follow_up[bucketKey].histogram;
const resultList = [];
result.forEach(item => (resultList.push({
key: item.key,
doc_count: item.count,
})));
return resultList;
});
// eslint-enable no-underscore-dangle
}

// below are for arranger only
const queryString = `
{
follow_up {
aggregations(filters: {first: 10000, op: "and", content: [
Expand All @@ -63,7 +115,7 @@ class ECCase extends HIVCohortFilterCase {
}
}
`;
return HIVCohortFilterCase.performQuery(query).then((res) => {
return HIVCohortFilterCase.performQuery(queryString).then((res) => {
if (!res || !res.data) {
throw new Error('Error while querying subjects with HIV');
}
Expand Down
66 changes: 61 additions & 5 deletions src/HIVCohortFilter/HIVCohortFilterCase.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import React from 'react';
import FileSaver from 'file-saver';
import { arrangerGraphqlPath } from '../localconf';
import { fetchWithCreds } from '../actions';
import {
guppyGraphQLUrl,
arrangerGraphqlPath,
useGuppyForExplorer,
} from '../configs';

class HIVCohortFilterCase extends React.Component {
// Base class for the 3 NDH cohort filter apps. Meant to facilitate code reuse
static performQuery(queryString) {
static performQuery(queryString, variableString) {
const graphqlUrl = useGuppyForExplorer ? guppyGraphQLUrl : arrangerGraphqlPath;
return fetchWithCreds({
path: `${arrangerGraphqlPath}`,
body: JSON.stringify({
path: `${graphqlUrl}`,
body: variableString ? JSON.stringify({
query: queryString,
variables: JSON.parse(variableString),
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case where we use arranger, variableString will be undefined right? And I think that will lead to the error Uncaught SyntaxError: Unexpected token u in JSON at position 0

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nice catch! fixed in 1dd7906

}) : JSON.stringify({
query: queryString,
}),
method: 'POST',
Expand Down Expand Up @@ -87,6 +95,55 @@ class HIVCohortFilterCase extends React.Component {
}

getFollowupsBuckets = (key, keyRange) => {
if (useGuppyForExplorer) {
const queryString = `
query ($filter: JSON) {
follow_up (filter: $filter, accessibility: all, first: 10000) {
subject_id
visit_number
thrpyv
visit_date
fposdate
frstdthd
leu3n
submitter_id
viral_load
}
_aggregation {
follow_up (filter: $filter, accessibility: all) {
_totalCount
}
}
}
`;
const variableString = `
{
"filter": {
"AND": [
{
"in": {
"${key}": ["${keyRange.join('","')}"]
}
},
{
"=": {
"hiv_status": "positive"
}
}
]
}
}`;
return HIVCohortFilterCase.performQuery(queryString, variableString).then((res) => {
if (!res
|| !res.data
|| !res.data.follow_up) {
throw new Error('Error while querying subjects with HIV');
}
return res.data.follow_up;
});
}

// below are for arranger
const query = `
{
follow_up {
Expand Down Expand Up @@ -115,7 +172,6 @@ class HIVCohortFilterCase extends React.Component {
viral_load
}
}

}
}
}`;
Expand Down
62 changes: 60 additions & 2 deletions src/HIVCohortFilter/LTNPCase.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import './HIVCohortFilter.css';
import CohortLTNPSvg from '../img/cohort-LTNP.svg';
import Spinner from '../components/Spinner';
import HIVCohortFilterCase from './HIVCohortFilterCase';
import { useGuppyForExplorer } from '../configs';

class LTNPCase extends HIVCohortFilterCase {
/*
Expand Down Expand Up @@ -52,7 +53,64 @@ class LTNPCase extends HIVCohortFilterCase {
getBucketByKeyWithHAARTVAR = (bucketKey, isHAART) => {
const d = new Date();
const currentYear = d.getFullYear();
const query = `

if (useGuppyForExplorer) {
const queryString = `
query ($filter: JSON) {
_aggregation {
follow_up (filter: $filter) {
${bucketKey} {
histogram {
key
count
}
}
}
}
}
`;
const variableString = ` {
"filter": {
"AND": [
{
"${isHAART ? '=' : '!='}": {
"thrpyv": "HAART"
}
},
{
"<=": {
"fposdate": ${currentYear - this.state.numConsecutiveYearsFromUser}
}
},
{
"=": {
"hiv_status": "positive"
}
}
]
}
}`;
return HIVCohortFilterCase.performQuery(queryString, variableString).then((res) => {
/* eslint-disable no-underscore-dangle */
if (!res
|| !res.data
|| !res.data._aggregation
|| !res.data._aggregation.follow_up) {
throw new Error('Error when query subjects with HIV');
}
const result = res.data._aggregation.follow_up[bucketKey].histogram;
const resultList = [];
result.forEach(item => (resultList.push({
key: item.key,
doc_count: item.count,
})));
return resultList;
// eslint-enable no-underscore-dangle
});
}

// below are for arranger only
const queryString = `
{
follow_up {
aggregations(filters: {first: 10000, op: "and", content: [
Expand All @@ -70,7 +128,7 @@ class LTNPCase extends HIVCohortFilterCase {
}
}
`;
return HIVCohortFilterCase.performQuery(query).then((res) => {
return HIVCohortFilterCase.performQuery(queryString).then((res) => {
if (!res || !res.data || !res.data.follow_up || !res.data.follow_up.aggregations) {
throw new Error('Error while querying subjects with HIV');
}
Expand Down
62 changes: 60 additions & 2 deletions src/HIVCohortFilter/PTCCase.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable no-underscore-dangle */
import React from 'react';
import FileSaver from 'file-saver';
import Button from '@gen3/ui-component/dist/components/Button';
import './HIVCohortFilter.css';
import CohortPTCSvg from '../img/cohort-PTC.svg';
import Spinner from '../components/Spinner';
import HIVCohortFilterCase from './HIVCohortFilterCase';
import { useGuppyForExplorer } from '../configs';

class PTCCase extends HIVCohortFilterCase {
/*
Expand Down Expand Up @@ -49,7 +51,63 @@ class PTCCase extends HIVCohortFilterCase {
getBucketByKeyWithHAARTVAR = (bucketKey, isHAART) => {
// The viral_load check in the below query ensures that
// the subjects retrieved have *at least* one follow_up with viral_load < viralLoadFromUser
const query = `
if (useGuppyForExplorer) {
const queryString = `
query ($filter: JSON) {
_aggregation {
follow_up (filter: $filter) {
${bucketKey} {
histogram {
key
count
}
}
}
}
}
`;
const variableString = ` {
"filter": {
"AND": [
{
"${isHAART ? '=' : '!='}": {
"thrpyv": "HAART"
}
},
{
"<": {
"viral_load": ${this.state.viralLoadFromUser}
}
},
{
"=": {
"hiv_status": "positive"
}
}
]
}
}`;
return HIVCohortFilterCase.performQuery(queryString, variableString).then((res) => {
// eslint-disable no-underscore-dangle
if (!res
|| !res.data
|| !res.data._aggregation
|| !res.data._aggregation.follow_up) {
throw new Error('Error when query subjects with HIV');
}
const result = res.data._aggregation.follow_up[bucketKey].histogram;
const resultList = [];
result.forEach(item => (resultList.push({
key: item.key,
doc_count: item.count,
})));
return resultList;
// eslint-enable no-underscore-dangle
});
}

// below are for arranger
const queryString = `
{
follow_up {
aggregations(filters: {first: 10000, op: "and", content: [
Expand All @@ -67,7 +125,7 @@ class PTCCase extends HIVCohortFilterCase {
}
}
`;
return HIVCohortFilterCase.performQuery(query).then((res) => {
return HIVCohortFilterCase.performQuery(queryString).then((res) => {
if (!res || !res.data) {
throw new Error('Error when query subjects with HIV');
}
Expand Down