Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
feat(patients): add very simple create patient page
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmeyer committed Nov 20, 2019
1 parent c220b96 commit bb94ef0
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/client/pouchdb.ts → src/clients/db/patients-db.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import PouchDB from 'pouchdb';
import { patients } from '../../config/pouchdb';

const db = new PouchDB('hospitalrun');
export async function getAll() {
return patients.allDocs();
}

export async function deleteDocument(document: any) {
return db.remove(document);
return patients.remove(document);
}

export async function deleteDocumentById(id: string, revId: string) {
return db.remove(id, revId);
return patients.remove(id, revId);
}

export async function saveOrUpdate(document: any) {
Expand All @@ -18,19 +20,21 @@ export async function saveOrUpdate(document: any) {
_rev: existingDocument._rev,
...document
}
return db.put(updatedDcoument)
return patients.put(updatedDcoument)
} catch(error) {
if(error.status === 404) {
return save(document)
}
}

return null;
}

export async function save(document: any) {
await db.post(document);
return patients.post(document);
}

export async function get(id: string) {
const document = await db.get(id);
const document = await patients.get(id);
return document;
}
}
65 changes: 62 additions & 3 deletions src/components/NewPatient.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
import React, { Component } from 'react';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import { TextInput, Button } from '@hospitalrun/components';
import * as patientsDb from '../clients/db/patients-db';

interface Props extends RouteComponentProps {

}

interface State {
firstName: string
lastName: string
}


class NewPatient extends Component<Props, State> {

constructor(props: Props) {
super(props);
this.onFirstNameChange = this.onFirstNameChange.bind(this)
this.onLastNameChange = this.onLastNameChange.bind(this);
this.onSaveButtonClick = this.onSaveButtonClick.bind(this);

this.state = {
firstName: '',
lastName: '',
};
}


onFirstNameChange(event: any) {
this.setState({
firstName: event.target.value,
})
}

onLastNameChange(event: any) {
this.setState({
lastName: event.target.value,
})
}

async onSaveButtonClick() {
const newPatient = (await patientsDb.save(this.state)) as any
this.props.history.push(`/patients/${newPatient.id}`);
}

class NewPatient extends Component {
render() {
return (
<h1>New Patient</h1>
<div>
<h1>New Patient</h1>
<div className="container">
<form>
<div className="row">
<h3>First Name:</h3>
<TextInput onChange={this.onFirstNameChange}/>
</div>
<div className="row">
<h3>Last Name:</h3>
<TextInput onChange={this.onLastNameChange}/>
</div>
<Button onClick={this.onSaveButtonClick}>Save</Button>
</form>
</div>
</div>
);
}
}

export default NewPatient;
export default withRouter(NewPatient);
7 changes: 7 additions & 0 deletions src/components/Patients.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React, { Component } from 'react';
import * as patientsDb from '../clients/db/patients-db';

class Patients extends Component {

async componentDidMount() {
const patients = await patientsDb.getAll();
console.log(patients);
}

render() {
return (
<div>
Expand Down
3 changes: 3 additions & 0 deletions src/config/pouchdb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PouchDB from 'pouchdb';

export const patients = new PouchDB('patients');
9 changes: 9 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<<<<<<< HEAD
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'
import * as serviceWorker from './serviceWorker'
=======
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
// import './client/pouchdb';
import * as serviceWorker from './serviceWorker';
>>>>>>> feat(patients): add very simple create patient page

ReactDOM.render(<App />, document.getElementById('root'))

Expand Down

0 comments on commit bb94ef0

Please sign in to comment.