-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 progress: Record patient changes on insert/update.
- Loading branch information
1 parent
9b7a812
commit 9e147ba
Showing
21 changed files
with
558 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type Changes<T> = { | ||
$set?: Partial<T>; | ||
$unset?: { | ||
[K in keyof T]?: boolean; | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,9 +1,31 @@ | ||
import {type Document as MongoDocument} from 'mongodb'; | ||
|
||
import schema from '../lib/schema'; | ||
|
||
type Document = MongoDocument; | ||
const literalSchema = schema.union([ | ||
schema.string(), | ||
schema.number(), | ||
schema.boolean(), | ||
schema.undefined(), // TODO: Keep in document, remove from updates. | ||
schema.null(), // TODO: Remove from document, add to update. | ||
schema.date(), | ||
]); | ||
|
||
type Literal = schema.infer<typeof literalSchema>; | ||
|
||
type DocumentValue = Literal | {[key: string]: DocumentValue} | DocumentValue[]; | ||
|
||
const documentValue: schema.ZodType<DocumentValue> = schema.lazy(() => | ||
schema.union([ | ||
literalSchema, | ||
schema.record(schema.string(), documentValue), | ||
schema.array(documentValue), | ||
]), | ||
); | ||
|
||
const documentKey = schema.string(); | ||
|
||
export const document = schema.record(schema.string(), schema.any()); | ||
export const document = schema.record(documentKey, documentValue); | ||
// TODO: The following does not work: | ||
// type Document = schema.infer<typeof document>; | ||
type Document = {[key: string]: DocumentValue | any}; | ||
|
||
export default Document; |
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,59 @@ | ||
import schema from '../../lib/schema'; | ||
import { document } from '../Document'; | ||
import define from './define'; | ||
|
||
const changeDocument = schema.object({ | ||
_id: schema.string(), | ||
owner: schema.string(), | ||
when: schema.date(), | ||
who: schema.object({ | ||
type: schema.literal('user'), | ||
_id: schema.string(), | ||
}), | ||
why: schema.object({ | ||
method: schema.string(), | ||
source: schema.union([ | ||
schema.object({ | ||
type: schema.literal('manual') | ||
}), | ||
schema.object({ | ||
type: schema.literal('entity'), | ||
collection: schema.string(), | ||
_id: schema.string(), | ||
}), | ||
]) | ||
}), | ||
what: schema.object({ | ||
type: schema.union([ | ||
schema.literal('patient'), | ||
schema.never(), | ||
]), | ||
_id: schema.string(), | ||
}), | ||
operation: schema.union([ | ||
schema.object({ | ||
type: schema.literal('update'), | ||
$set: document.optional(), | ||
$unset: schema.record( | ||
schema.string(), | ||
schema.boolean(), | ||
).optional(), | ||
}), | ||
schema.object({ | ||
type: schema.literal('create'), | ||
$set: document.optional(), | ||
}), | ||
schema.object({ | ||
type: schema.literal('read'), | ||
}), | ||
schema.object({ | ||
type: schema.literal('delete'), | ||
}), | ||
]) | ||
}); | ||
|
||
export type ChangeDocument = schema.infer<typeof changeDocument>; | ||
|
||
|
||
const collection = 'changes'; | ||
export const Changes = define<ChangeDocument>(collection); |
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
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
Oops, something went wrong.