Skip to content
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
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ snprc_ehr/resources/views/HelloApp*.*
snprc_ehr/resources/views/helloWorld*.*
snprc_ehr/resources/views/NewAnimalPage*.*
snprc_ehr/resources/views/BirthRecordReport*.*
snprc_ehr/resources/views/ChipReader*.*
snprc_ehr/cmd-here.exe
snprc_ehr/resources/referenceStudy/*.xlsx
snprc_ehr/resources/web/snprc_ehr/snprcReports.js.gz
snprc_ehr/resources/web/snprc_ehr/gen/*
snprc_mobile
/snprc_ehr.2020*.zip
/snprc_ehr.2020*.7z
/snprc_ehr/.editorconfig
/snprc_ehr/cmd-here.exe
snprc_ehr.2020*.zip
snprc_ehr.2020*.7z
snprc_ehr/.editorconfig
snprc_ehr/cmd-here.exe
snprc_ehr/resources/referenceStudy/LoadTaqmanData
snprc_ehr/resources/referenceStudy/datasetImport/LoadTaqmanData
7 changes: 4 additions & 3 deletions snprc_ehr/.babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"presets":[
"@babel/preset-env",
"@babel/preset-react"
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"transform-class-properties",
"@babel/plugin-proposal-object-rest-spread"
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-transform-runtime"
]
}
1 change: 1 addition & 0 deletions snprc_ehr/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"error",
"as-needed"
],
"lines-between-class-members": ["error", "never"],
"react/jsx-filename-extension": 0,
"react/sort-comp": 0,
"global-require": 0,
Expand Down
52 changes: 52 additions & 0 deletions snprc_ehr/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions snprc_ehr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"@babel/core": "^7.10.2",
"@babel/plugin-proposal-class-properties": "^7.10.1",
"@babel/plugin-proposal-object-rest-spread": "^7.10.1",
"@babel/plugin-transform-runtime": "^7.11.0",
"@babel/polyfill": "7.4.4",
"@babel/preset-env": "7.4.5",
"@babel/preset-react": "7.0.0",
Expand Down
7 changes: 1 addition & 6 deletions snprc_ehr/resources/queries/study/idHistory.query.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
<metadata>
<tables xmlns="http://labkey.org/data/xml">
<table tableName="idHistory" tableDbType="TABLE" useColumnOrder="true">
<tableUrl />
<insertUrl />
<importUrl />
<updateUrl />
<deleteUrl />
<columns>
<column columnName="Id">
<columnTitle>TxBiomed ID</columnTitle>
Expand Down Expand Up @@ -57,4 +52,4 @@
</table>
</tables>
</metadata>
</query>
</query>
1 change: 1 addition & 0 deletions snprc_ehr/resources/views/begin.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
},
items: [
{ name: 'Compare Lists of Animals', url: '<%=contextPath%>/ehr' + ctx['EHRStudyContainer'] + '/utilities.view?' },
{name: 'Chip Reader',url: '<%=contextPath%>/snprc_ehr' + ctx['EHRStudyContainer'] + '/ChipReader.view?'}
//{name: 'Drug Formulary', url: '<%=contextPath%>/query' + ctx['EHRStudyContainer'] + '/executeQuery.view?schemaName=ehr_lookups&query.queryName=drug_defaults'},
//{name: 'Procedure List', url: '<%=contextPath%>/query' + ctx['EHRStudyContainer'] + '/executeQuery.view?schemaName=ehr_lookups&query.queryName=procedures&query.viewName=Active Procedures'},
//{name: 'Search Center SNOMED Codes', url: '<%=contextPath%>/query' + ctx['EHRStudyContainer'] + '/executeQuery.view?schemaName=ehr_lookups&query.queryName=snomed'},
Expand Down
145 changes: 145 additions & 0 deletions snprc_ehr/src/client/ChipReader/ChipReader.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* eslint-disable no-alert */

import React from 'react'
import { LoadingSpinner } from '@labkey/components'
import './styles/chipReader.scss'
import ChipReaderState from './constants/chipReaderState'
import constants from './constants/index'
import InfoPanel from '../Shared/components/InfoPanel'
import ChipDataPanel from './components/ChipDataPanel'
import SummaryGridPanel from './components/SummaryGridPanel'
import fetchAnimalId from './api/fetchAnimalId'
import { close } from './services/serialService'

export default class ChipReader extends React.Component {
state = new ChipReaderState();
notSupportedMessage = constants.notSupportedMessage
debug = constants.debug;
isSerialSupported = ('serial' in navigator) || this.props.debug
previousChipId = undefined
componentDidMount() {
window.addEventListener('beforeunload', this.beforeunload.bind(this))

this.setState(prevState => (
{
...prevState,
serialOptions: constants.defaultSerialOptions,
isLoading: false
}
))
}
componentWillUnmount() {
window.removeEventListener('beforeunload', this.beforeunload.bind(this))
}
beforeunload(e) {
if (this.state.connection) {
close(this.state.connection)
e.preventDefault()
e.returnValue = true
}
}
handleSetConnection = connection => {
this.setState(prevState => (
{
...prevState,
connection
}
))
}
handleDataChange = async value => {
const data = value || { chipId: undefined, animalId: undefined, temperature: undefined }

if (!data.chipId || data.chipId === this.previousChipId) return

// console.log(`chipId = ${data.chipId}`)
this.previousChipId = data.chipId

if (data.chipId && !data.animalId) {
data.animalId = await fetchAnimalId(data.chipId).catch(error => {
this.setState(prevState => (
{
...prevState,
errorMessage: error.message
}
))
})
}

this.setState(prevState => ({
...prevState,
chipData: data,
...(data.animalId && { errorMessage: undefined }), // clear error message
...(data.animalId && {
summaryData: [
...prevState.summaryData,
{ ...data }
]
})
}))
}
handleErrorMessage = error => {
this.setState(prevState => (
{
...prevState,
errorMessage: error
}
))
}
render() {
// allow debug mode to be triggered for running test suite
this.debug = this.props.debug !== undefined ? this.props.debug : constants.debug

const { isLoading } = this.state

if (isLoading) {
return (
<LoadingSpinner msg="Loading app..." />
)
}

return (
<div>
{ this.isSerialSupported
&& (
<div className="split-panel">
<div className="parent-panel">
<div className="panel-heading">
<p>Current Animal</p>
</div>
<div className="wizard-panel">
<ChipDataPanel
chipData={ this.state.chipData }
connection={ this.state.connection }
errorMessage={ this.state.errorMessage }
handleDataChange={ this.handleDataChange }
handleErrorMessage={ this.handleErrorMessage }
handleSetConnection={ this.handleSetConnection }
serialOptions={ this.state.serialOptions }
/>
</div>

</div>

<div className="right-panel">
<div>
<div className="panel-heading">
<p>Animals Seen</p>
</div>
<div className="wizard-right">
<SummaryGridPanel
summaryData={ this.state.summaryData }
/>
</div>
</div>
</div>
</div>
) }
<InfoPanel
errorMessages={ (!this.isSerialSupported
&& [{ propTest: true, colName: this.notSupportedMessage }])
|| (this.state.errorMessage && [{ propTest: true, colName: this.state.errorMessage }]) }
/>
</div>
)
}
}
30 changes: 30 additions & 0 deletions snprc_ehr/src/client/ChipReader/api/fetchAnimalId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { executeSql } from '../../Shared/api/api'
import moment from 'moment'

const parse = rows => {
return rows.map(({ data }) => {
return { value: data.Id.value, url: data.Id.url, location: data.location.value, time: moment() }
})
}

const fetchAnimalId = chipId => {
const sql = `SELECT ih.Id AS Id, ih.Id.curLocation.location as location
FROM study.idHistory as ih
WHERE ih.value = '${chipId}'`

return new Promise((resolve, reject) => {

executeSql({
schemaName: 'study',
sql
}).then(({ rows }) => {
const parseRows = parse(rows)
if (parseRows.length !== 1)
throw new Error ("Animal not found")
resolve(parseRows[0])
}).catch(error => {
reject(error)
})
})
}
export default fetchAnimalId
9 changes: 9 additions & 0 deletions snprc_ehr/src/client/ChipReader/app.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom'

import ChipReader from './ChipReader'

// Need to wait for container element to be available in labkey wrapper before render
window.addEventListener('DOMContentLoaded', () => {
ReactDOM.render(<ChipReader />, document.getElementById('app'))
})
Loading