Advertisement
Guest User

steak

a guest
May 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.02 KB | None | 0 0
  1. import React, { Component } from "react";
  2.  
  3. import InputTextHOC from "../CommonCode/HOC/InputTextHOC";
  4. import InputRadioHOC from "../CommonCode/HOC/InputRadioHOC";
  5.  
  6. import { Button, Table } from "reactstrap";
  7. import ReactTooltip from "react-tooltip";
  8. import { map, filter, isEmpty } from "lodash";
  9.  
  10. class AdmissionData extends Component {
  11. state = {
  12. add_item_1: "",
  13. add_item_1Options: [{ value: "Dizzy", label: "Dizzy" }],
  14. // add_item_2_opt1: '',
  15. // add_item_2_opt2: '',
  16. add_item_3: "",
  17. add_item_4: [],
  18. checkedValue: "",
  19. radioData: "",
  20. disabled: true
  21. };
  22.  
  23. items = {
  24. add_item_4: {
  25. type: "table",
  26. value: this.state.add_item_4, /* Get data from props.data */
  27. color: "",
  28. label: this.props.element.ElemCaption,
  29. datatype: ""
  30. }
  31. }
  32.  
  33. componentDidMount() {
  34. //fill add_item_1Options (options od Dx);
  35. //fill add_item_4 (grid value)
  36. this.setState({
  37. radioData: "add_item_2_opt1ᴥConfirmed¿add_item_2_opt2ᴥPresumed"
  38. });
  39. }
  40.  
  41. handleAddClick = () => {
  42. let { add_item_4 } = this.state;
  43. let tempObj = {};
  44. let editedElement = {};
  45. let { add_item_1, checkedValue, add_item_3 } = this.state;
  46.  
  47. if (checkedValue === "add_item_2_opt1") checkedValue = "Confirmed";
  48. else if (checkedValue === "add_item_2_opt2") checkedValue = "Presumed";
  49. else checkedValue = "Confirmed";
  50. if (!isEmpty(add_item_4)) {
  51. editedElement = filter(add_item_4, val => {
  52. return val.Diagnosis === add_item_1;
  53. });
  54. }
  55.  
  56. if (!isEmpty(editedElement)) {
  57. editedElement[0].Status = checkedValue;
  58. editedElement[0].Note = add_item_3;
  59. } else {
  60. tempObj = {
  61. Diagnosis: add_item_1,
  62. Status: checkedValue,
  63. Note: add_item_3
  64. };
  65. add_item_4.push(tempObj);
  66. }
  67.  
  68. this.setState({
  69. add_item_1: "",
  70. checkedValue: "",
  71. add_item_3: "",
  72. add_item_4,
  73. disabled: true
  74. });
  75. };
  76.  
  77. handleClearClick = () => {
  78. this.setState({ add_item_1: "", checkedValue: "", add_item_3: "" });
  79. };
  80.  
  81. handleEdit = key => e => {
  82. let { add_item_4 } = this.state;
  83. let editedElement = filter(add_item_4, (val, tempKey) => {
  84. return tempKey === key;
  85. });
  86. this.setState({
  87. add_item_1: editedElement[0].Diagnosis,
  88. checkedValue:
  89. editedElement[0].Status === "Confirmed"
  90. ? "add_item_2_opt1"
  91. : "add_item_2_opt2",
  92. add_item_3: editedElement[0].Note
  93. });
  94. };
  95.  
  96. handleDelete = key => e => {
  97. let { add_item_4 } = this.state;
  98. add_item_4.splice(key, 1);
  99. this.setState({
  100. add_item_1: "",
  101. checkedValue: "",
  102. add_item_3: "",
  103. add_item_4
  104. });
  105. };
  106.  
  107. handleSelectChange = name => e => {
  108. let { disabled } = this.state;
  109. let value = "";
  110.  
  111. if (e && e.value) {
  112. value = e.value;
  113. } else {
  114. value = "";
  115. }
  116.  
  117. if (value && value !== "") disabled = false;
  118. else disabled = true;
  119.  
  120. this.setState({ [name]: value, disabled });
  121. };
  122.  
  123. handleTextChange = e => {
  124. this.setState({ [e.target.name]: e.target.value });
  125. };
  126.  
  127. handleCheckChange = e => {
  128. this.setState({ checkedValue: e.target.value });
  129. };
  130.  
  131. handleSave = () => {
  132. //save add_item_4 (Grid)
  133. };
  134.  
  135. render() {
  136. return (
  137. <div>
  138. <div className="row">
  139. <label className="col-12">Diagnosis</label>
  140. </div>
  141. <div style={{ color: "silver", marginBottom: "5px" }}>
  142. Recently used:
  143. </div>
  144. <div className="divider-dashed" />
  145. <div className="row" style={{ color: "silver" }}>
  146. <label className="col-12">Enter a new diagnosis:</label>
  147. </div>
  148. <div className="row">
  149. <div className="col-12 col-md-4" style={{ marginBottom: "3px" }}>
  150. <InputTextHOC
  151. Ele_DataType="typeahead"
  152. value={this.state.add_item_1}
  153. placeholder="Diagnosis"
  154. onChange={this.handleSelectChange("add_item_1")}
  155. name="add_item_1"
  156. Creatable={true}
  157. options={this.state.add_item_1Options}
  158. dontOpenOnClick={true}
  159. className="form-control"
  160. />
  161. </div>
  162. <div className="col-6 col-md-3">
  163. <InputRadioHOC
  164. radioData={this.state.radioData}
  165. radioGroupName="add_item_2"
  166. className="padding-radio-label flat form-control"
  167. handleCheckChange={this.handleCheckChange}
  168. getPreviousData={this.state.checkedValue}
  169. />
  170. </div>
  171. <div className="col-12 col-md-3" style={{ marginBottom: "3px" }}>
  172. <InputTextHOC
  173. value={this.state.add_item_3}
  174. className="form-control"
  175. placeholder="Note"
  176. onChange={this.handleTextChange}
  177. name="add_item_3"
  178. />
  179. </div>
  180. <div className="col-2" style={{ marginBottom: "3px" }}>
  181. <Button
  182. data-tip
  183. data-for="confirmation"
  184. name="add-admissiondata-ok"
  185. id="add-admissiondata-ok"
  186. disabled={this.state.disabled}
  187. onClick={this.handleAddClick}
  188. className="btn btn-success"
  189. >
  190. <i className="fa fa-check" />
  191. </Button>
  192. <ReactTooltip id="confirmation">
  193. <span>Confirmation</span>
  194. </ReactTooltip>
  195. {/* </div>
  196. <div className="col-1" style={{marginBottom: '3px'}}> */}
  197. <Button
  198. data-tip
  199. data-for="clear"
  200. name="add-admissiondata-clear"
  201. id="add-admissiondata-clear"
  202. onClick={this.handleClearClick}
  203. className="btn btn-danger btn-clear"
  204. >
  205. <i className="fa fa-times" />
  206. </Button>
  207. <ReactTooltip id="clear">
  208. <span>Clear</span>
  209. </ReactTooltip>
  210. </div>
  211. </div>
  212. <div className="divider-dashed" />
  213. <div className="row x_panel" style={{ marginLeft: "0px" }}>
  214. <div className="col-12 x_content">
  215. <Table
  216. responsive
  217. className="table table-hover gen-elem"
  218. id="add_item_4"
  219. >
  220. <thead>
  221. <tr>
  222. <th style={{ textAlign: "left", width: "25%" }}>Diagnosis</th>
  223. <th style={{ textAlign: "left", width: "35%" }}>Status</th>
  224. <th style={{ textAlign: "left", width: "20%" }}>Note</th>
  225. <th style={{ textAlign: "left", width: "20%" }} />
  226. </tr>
  227. </thead>
  228. <tbody>
  229. {map(this.state.add_item_4, (value, key) => {
  230. return (
  231. <tr key={key}>
  232. <td>{value.Diagnosis}</td>
  233. <td>{value.Status}</td>
  234. <td>{value.Note}</td>
  235. <td>
  236. {this.state.direction !== "read-only" && [
  237. <a
  238. key={1}
  239. className="actionLink"
  240. onClick={this.handleEdit(key)}
  241. >
  242. Edit
  243. </a>,
  244. <span key={2}> |&nbsp;</span>,
  245. <a
  246. key={3}
  247. className="actionLink"
  248. onClick={this.handleDelete(key)}
  249. >
  250. <span>Delete</span>
  251. </a>
  252. ]}
  253. </td>
  254. </tr>
  255. );
  256. })}
  257. </tbody>
  258. </Table>
  259. </div>
  260. </div>
  261. </div>
  262. );
  263. }
  264. }
  265.  
  266. export default AdmissionData;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement