Skip to content

Commit

Permalink
Merge pull request #100 from PulseTile/features/23-07-2019
Browse files Browse the repository at this point in the history
Features 23-07-2019
  • Loading branch information
tony-shannon authored Jul 24, 2019
2 parents 735a185 + fe2b4fc commit 63d6d50
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 67 deletions.
6 changes: 4 additions & 2 deletions src/core/common/ResourseTemplates/CreateTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ const styles = theme => ({
* @author Bogdan Shcherban <bsc@piogroup.net>
* @param {shape} classes
* @param {boolean} isCustom
* @param {string} resourceUrl
* @param {shape} history
* @param {boolean} isListOpened
* @param {func} toggleListBlock
* @param {string} blockTitle
* @param {shape} children
* @param {shape} rest
*/
const CreateTemplate = ({ classes, isCustom, isListOpened, toggleListBlock, blockTitle, children, ...rest }) => (
const CreateTemplate = ({ classes, isCustom, resourceUrl, history, isListOpened, toggleListBlock, blockTitle, children, ...rest }) => (
<Grid item xs={12} sm={isListOpened ? 6 : 12}>
<div className={classes.blockTitle}>
<Typography className={classes.title}>{blockTitle}</Typography>
Expand All @@ -74,7 +76,7 @@ const CreateTemplate = ({ classes, isCustom, isListOpened, toggleListBlock, bloc
{ !isCustom
?
<Create {...rest}>
<SimpleForm className={classes.createForm} toolbar={<CreateFormToolbar />}>
<SimpleForm className={classes.createForm} toolbar={<CreateFormToolbar resourceUrl={resourceUrl} history={history} />}>
{children}
</SimpleForm>
</Create>
Expand Down
15 changes: 12 additions & 3 deletions src/core/common/ResourseTemplates/ListTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ class ListTemplate extends Component {
* @return {string}
*/
getCreateUrl = () => {
return "/" + this.props.resourceUrl + "/create";
let currentPage = null;
const search = get(this.props, 'location.search', null);
if (search) {
const params = new URLSearchParams(search);
currentPage = params.get('page');
}
let createPage = "/" + this.props.resourceUrl + "/create";
return currentPage ? (createPage + "?page=" + currentPage + "&perPage=10") : createPage;
};

/**
Expand All @@ -158,7 +165,8 @@ class ListTemplate extends Component {
* @return {string}
*/
isCreatePage = () => {
return (this.props.location.pathname === this.getCreateUrl());
const defaultCreateUrl = "/" + this.props.resourceUrl + "/create";
return (this.props.location.pathname === defaultCreateUrl);
};

/**
Expand Down Expand Up @@ -327,6 +335,7 @@ class ListTemplate extends Component {
];
const CreateBlock = create;
const createUrl = this.getCreateUrl();
const defaultCreateUrl = "/" + this.props.resourceUrl + "/create";

let titleTable = title;

Expand Down Expand Up @@ -418,7 +427,7 @@ class ListTemplate extends Component {
/>
:
<Route
path={createUrl}
path={defaultCreateUrl}
render={({ match }) => <CreateBlock isListOpened={isListOpened} toggleListBlock={this.toggleListBlock} id={match.params.id} {...this.props} />}
/>
}
Expand Down
22 changes: 20 additions & 2 deletions src/core/common/ResourseTemplates/fragments/CustomDatagridRow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from "react";
import get from "lodash/get";
import {Datagrid, DatagridRow} from 'react-admin';

import { withStyles } from "@material-ui/core/styles";
import TableRow from '@material-ui/core/TableRow';
Expand Down Expand Up @@ -32,12 +33,29 @@ class CustomDatagridRow extends Component {
return id === sourceId;
};

getCurrentPage = () => {
const { location } = this.props;
let result = 1;
const search = get(location, 'search', null);
if (search) {
const params = new URLSearchParams(search);
result = params.get('page');
}
return result;
};

getUrl = () => {
const { id, basePath } = this.props;
const currentPage = this.getCurrentPage();
return (currentPage > 1) ? (basePath + '/' + id + '?page=' + currentPage + '&perPage=10') : (basePath + '/' + id);
};

render() {
const { classes, record, id, history, basePath, children } = this.props;
const { classes, record, history, children } = this.props;
if (!record) {
return null;
}
const detailsPath = basePath + '/' + id;
const detailsPath = this.getUrl();
const isActiveRow = this.isActiveRow();
return (
<TableRow className={isActiveRow ? classes.tableRowActive : classes.tableRow} key={record.id} onClick={() => history.push(detailsPath)}>
Expand Down
14 changes: 0 additions & 14 deletions src/core/common/ResourseTemplates/fragments/TableContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,6 @@ const styles = theme => ({
}
});


function getPath(id, basePath, record) {

console.log('++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++')
console.log('id', id);
console.log('basePath', basePath);
console.log('record', record);

return 'show'

}

const CustomDatagridBody = ({ CustomRow, location, hiddenColumns, history, ...rest }) => {
return (
<DatagridBody
Expand All @@ -77,7 +65,6 @@ const CustomDatagridBody = ({ CustomRow, location, hiddenColumns, history, ...re
const CustomDatagrid = ({ classes, history, CustomRow, CustomTableHead, hiddenColumns, location, ...rest }) => {
return (
<Datagrid
rowClick={(id, basePath, record) => getPath(id, basePath, record)}
body={
<CustomDatagridBody
location={location}
Expand Down Expand Up @@ -113,7 +100,6 @@ const DatagridBlock = ({ classes, location, hiddenColumns, isCustomDatagrid, chi
<Datagrid
className={classes.tableList}
classes={{ rowEven: classes.rowEven, rowOdd: classes.rowOdd }}
rowClick={(id, basePath, record) => getPath(id, basePath, record)}
{...rest}
>
{children}
Expand Down
17 changes: 13 additions & 4 deletions src/core/common/Toolbars/CreateFormToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { withStyles } from '@material-ui/core/styles';
import BlockIcon from '@material-ui/icons/Block';

import CustomSaveButton from "../../common/Buttons/CustomSaveButton";
import Tooltip from "@material-ui/core/Tooltip";
import IconButton from "@material-ui/core/IconButton";

const styles = theme => ({
listButton: {
Expand Down Expand Up @@ -43,13 +45,20 @@ const styles = theme => ({
* This component returns toolbar without delete button for create forms
*
* @author Bogdan Shcherban <bsc@piogroup.net>
* @param {shape} classes
* @param {shape} props
* @param {shape} classes
* @param {string} resourceUrl
* @param {shape} history
* @param {shape} props
*/
const CreateFormToolbar = ({ classes, ...props}) => {
const CreateFormToolbar = ({ classes, resourceUrl, history, ...props}) => {
return (
<Toolbar className={classes.toolbar} {...props} >
<ListButton label="Cancel" icon={<BlockIcon />} className={classes.listButton} />
<Tooltip title="Cancel" disableHoverListener={true}>
<IconButton type="button" className={classes.listButton} onClick={() => history.push('/' + resourceUrl)}>
<BlockIcon />
Cancel
</IconButton>
</Tooltip>
<CustomSaveButton {...props} />
</Toolbar>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,7 @@ class AdvancedSearchDialog extends Component {
this.props.removeUserSearch();
this.props.removeClinicalQuery();
this.props.setAdvancedSearch(advancedSearchData);

if (nhsNumber) {
this.props.setUserId(nhsNumber);
} else if (lastName) {
this.props.setUserSearch(lastName.toLowerCase());
} else if (searchDateOfBirth) {
this.props.setSearchType('by_birthdate', searchDateOfBirth);
} else if (gender) {
this.props.setSearchType('by_gender', gender);
} else if (age) {
this.props.setSearchType('by_age', age);
}
this.props.setSearchType('advanced', advancedSearchData);

window.location.replace('/#/patients');
this.props.onClose();
Expand Down
85 changes: 76 additions & 9 deletions src/core/dataProviders/patientsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ function getRequestUrl(params) {
let result = null;
if (searchType === 'id') {
result = `${domainName}/mpi/Patient/${search}`;
} else if (searchType === 'by_city' && search) {
result = `${domainName}/mpi/Patient/search/searchByCity`;
} else if (searchType === 'clinicalQuery' && clinicalSearchType) {
result = `${domainName}/api/patient/clinicalSearch/${clinicalSearchType}`;
} else if (searchType === 'by_age' && search) {
result = `${domainName}/mpi/Patient/search/advanced?type=by_age&from=${search[0]}&to=${search[1]}`;
} else if (searchType !== 'name' && search) {
result = `${domainName}/mpi/Patient/search/advanced?type=${searchType}&value=${search.toLowerCase()}`;
} else if ((searchType === 'by_age' || searchType !== 'name') && search) {
result = `${domainName}/mpi/Patient/search/advanced`;
} else if (search) {
result = `${domainName}/mpi/Patient?name=${search}`;
}
Expand All @@ -63,14 +63,45 @@ function getRequestUrl(params) {

function getRequestMethod(params) {
const isClinicalQuery = get(params, 'filter.clinicalQuery', null);
return isClinicalQuery ? 'POST' : 'GET';
const searchType = get(params, 'filter.filterType', null);
const isSearchByCity = (searchType === 'by_city');
const isSearchByAge = (searchType === 'by_age');
const isAdvancedSearch = (searchType === 'advanced');
return (isClinicalQuery || isSearchByCity || isSearchByAge || isAdvancedSearch) ? 'POST' : 'GET';
}

function getRequestBody(params) {
const isClinicalQuery = get(params, 'filter.clinicalQuery', null);
if (!isClinicalQuery) {
return null;
function getAdvancedSearchBody(params) {
const searchParams = get(params, 'filter.filterText', null);
const nhsNumber = get(searchParams, 'nhsNumber', null);
const firstName = get(searchParams, 'firstName', null);
const lastName = get(searchParams, 'lastName', null);
const gender = get(searchParams, 'gender', null);
const birthDate = get(searchParams, 'dateOfBirth', null);
const from = get(searchParams, 'minAge', 0);
const to = get(searchParams, 'maxAge', 100);
let requestBody = {};
if (birthDate) {
requestBody = {
nhsNumber: nhsNumber,
firstName: firstName,
lastName : lastName,
gender: gender,
birthDate: birthDate
}
} else {
requestBody = {
from: from,
to: to,
nhsNumber: nhsNumber,
firstName: firstName,
lastName : lastName,
gender: gender,
}
}
return requestBody;
}

function getClinicalQueryBody(params) {
let requestBody = {
query: get(params, 'filter.clinicalQuery.searchValue', null),
gender: get(params, 'filter.clinicalQuery.gender', null),
Expand All @@ -84,6 +115,38 @@ function getRequestBody(params) {
requestBody.from = from;
requestBody.to = to;
}
return requestBody;
}

function getRequestBody(params) {

const isClinicalQuery = get(params, 'filter.clinicalQuery', null);
const searchType = get(params, 'filter.filterType', null);
const isSearchByCity = (searchType === 'by_city');
const isSearchByAge = (searchType === 'by_age');
const isAdvancedSearch = (searchType === 'advanced');

if (!isClinicalQuery && !isSearchByCity && !isSearchByAge && !isAdvancedSearch) {
return null;
}

let requestBody = {};
if (isClinicalQuery) {
requestBody = getClinicalQueryBody(params);
} else if (isSearchByCity) {
requestBody = {
city: get(params, 'filter.filterText', null),
}
} else if (isAdvancedSearch) {
requestBody = getAdvancedSearchBody(params);
} else if (isSearchByAge) {
const ageRange = get(params, 'filter.filterText', [0, 100]);
requestBody = {
from: ageRange[0],
to: ageRange[1],
};
}

return JSON.stringify(requestBody);
}

Expand Down Expand Up @@ -405,6 +468,10 @@ function getSortedResults(results, params) {

export default (type, resource, params) => {
let { url, options } = convertPatientsDataRequestToHTTP(type, resource, params);
if (!url) {
return null;
}

let responseInfo = {};
return fetch(url, options).then(response => {
responseInfo.status = get(response, 'status', null);
Expand Down
6 changes: 0 additions & 6 deletions src/core/pages/PatientSummary/fragments/EventsTimeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,8 @@ const CustomHeader = ({ classes, items }) => {

const dateAndTime = items[0];
const events = items[1];

console.log('dateAndTime', dateAndTime)

const dateForPoint = moment.unix(dateAndTime).format('Do MMM')

console.log('dateForPoint', dateForPoint)

// Use your own CSS
return (
<Content>
Expand Down Expand Up @@ -165,7 +160,6 @@ const EventsTimeline = ({ classes }) => {

const eventsGroupByDateArray = Object.entries(eventsGroupByDate);

console.log('eventsGroupByDate', eventsGroupByDate)
return (
<div className={classes.timeline}>
<Timeline>
Expand Down
12 changes: 9 additions & 3 deletions src/core/pages/PatientsList/PatientShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ const styles = {
*/
const PatientShow = ({ classes, ...rest }) => (
<PatientShowTemplate pageTitle="Patient" {...rest}>
<TextField className={classes.labelBlock} label="Name" source="name" />
<DateField className={classes.labelBlock} label="Date of Birth" source="dateOfBirth" />
<TextField className={classes.labelBlock} label="Name" source="firstName" />
<TextField className={classes.labelBlock} label="Surname" source="lastName" />
<DateField className={classes.labelBlock} label="Date of Birth" source="birthDate" />
<TextField className={classes.labelBlock} label="Gender" source="gender" />
<TextField className={classes.labelBlock} label="Address" source="totalAddress" />
<TextField className={classes.labelBlock} label="Address" source="address" />
<TextField className={classes.labelBlock} label="District" source="district" />
<TextField className={classes.labelBlock} label="City" source="city" />
<TextField className={classes.labelBlock} label="Country" source="country" />
<TextField className={classes.labelBlock} label="Telephone Number" source="phone" />
<TextField className={classes.labelBlock} label="NHS number" source="nhsNumber" />
</PatientShowTemplate>
);

Expand Down
2 changes: 0 additions & 2 deletions src/core/pages/PatientsList/fragments/DatagridRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class PatientDatagridRow extends Component {
const isPermissionRequired = get(themeCommonElements, 'patientSummaryPermission', false);
const open = Boolean(anchorEl);

console.log('record', record)

return (
<CustomDatagridRow {...this.props} >
<TableCell key={`${record.id}-name`}>
Expand Down
Loading

0 comments on commit 63d6d50

Please sign in to comment.