-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added AACN field * Improved AACN field behavior, added NCLEX field * Shortened AACN error message
- Loading branch information
Showing
8 changed files
with
179 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import classnames from 'classnames'; | ||
import Exercise from '../../models/exercises/exercise'; | ||
import { observer } from 'mobx-react'; | ||
import { action, computed, observable, modelize } from 'shared/model'; | ||
import TagModel from 'shared/model/exercise/tag'; | ||
import { Icon } from 'shared'; | ||
import Error from './error'; | ||
import { nursingBooks } from './nursingBooks'; | ||
import Wrapper from './wrapper'; | ||
|
||
const pattern = '##.#[a-z]'; | ||
|
||
@observer | ||
class Input extends React.Component { | ||
static propTypes = { | ||
exercise: PropTypes.instanceOf(Exercise).isRequired, | ||
tag: PropTypes.instanceOf(TagModel).isRequired, | ||
}; | ||
|
||
@observable aacn = this.props.tag.value; | ||
|
||
isValid(aacn) { | ||
return aacn && aacn.match(/^\d{1,2}\.\d[a-z]$/); | ||
} | ||
|
||
@computed get errorMsg() { | ||
if (this.isValid(this.aacn)) { | ||
return null; | ||
} else { | ||
return `Must match AACN pattern of ${pattern}`; | ||
} | ||
} | ||
|
||
constructor(props) { | ||
super(props) | ||
modelize(this); | ||
} | ||
|
||
@action.bound onTextChange(ev) { | ||
this.aacn = ev.target.value.toLowerCase().replace(/[^0-9a-z.]+/, ''); | ||
} | ||
|
||
@action.bound onTextBlur() { | ||
this.props.tag.value = this.isValid(this.aacn) ? this.aacn : ''; | ||
} | ||
|
||
@action.bound onDelete() { | ||
this.props.exercise.tags.remove(this.props.tag); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className={classnames('tag', { 'has-error': this.errorMsg })}> | ||
<input | ||
className="form-control" | ||
type="text" | ||
onChange={this.onTextChange} | ||
onBlur={this.onTextBlur} | ||
value={this.aacn} | ||
placeholder={pattern} | ||
/> | ||
<Error error={this.errorMsg} /> | ||
<span className="controls"> | ||
<Icon type="trash" onClick={this.onDelete} /> | ||
</span> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
@observer | ||
class AACNTags extends React.Component { | ||
static propTypes = { | ||
exercise: PropTypes.instanceOf(Exercise).isRequired, | ||
}; | ||
|
||
constructor(props) { | ||
super(props) | ||
modelize(this); | ||
} | ||
|
||
@action.bound onAdd() { | ||
this.props.exercise.tags.push({ type: 'nursing', specifier: 'aacn', value: '' }); | ||
} | ||
|
||
render() { | ||
const { exercise } = this.props; | ||
|
||
const bookTags = exercise.tags.withType('book', { multiple: true }); | ||
if (!bookTags.find(tag => nursingBooks.includes(tag.value))) { | ||
return null; | ||
} | ||
|
||
const nursingTags = exercise.tags.withType('nursing', { multiple: true }); | ||
const aacnTags = nursingTags.filter(tag => tag.specifier === 'aacn'); | ||
|
||
return ( | ||
<Wrapper label="AACN" onAdd={this.onAdd}> | ||
{aacnTags.map((tag, i) => <Input key={i} {...this.props} tag={tag} />)} | ||
</Wrapper> | ||
); | ||
} | ||
} | ||
|
||
export default AACNTags; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { observer } from 'mobx-react'; | ||
import Exercise from '../../models/exercises/exercise'; | ||
import { nursingBooks } from './nursingBooks'; | ||
import SingleDropdown from './single-dropdown'; | ||
|
||
const CHOICES = { 'y': 'Yes', 'n': 'No' }; | ||
|
||
function NCLEXTag(props) { | ||
const bookTags = props.exercise.tags.withType('book', { multiple: true }); | ||
if (!bookTags.find(tag => nursingBooks.includes(tag.value))) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SingleDropdown {...props} label="NCLEX" type="nursing" specifier="nclex" choices={CHOICES} /> | ||
); | ||
} | ||
|
||
NCLEXTag.propTypes = { | ||
exercise: PropTypes.instanceOf(Exercise).isRequired, | ||
}; | ||
|
||
export default observer(NCLEXTag); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const nursingBooks = [ | ||
'stax-matnewborn', | ||
'stax-medsurg', | ||
'stax-nursingfundamentals', | ||
'stax-nursingskills', | ||
'stax-nutrition', | ||
'stax-pharmacology', | ||
'stax-pophealth', | ||
'stax-psychnursing', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters