-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
306 additions
and
32 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
File renamed without changes.
80 changes: 80 additions & 0 deletions
80
snprc_ehr/src/client/SndEventsWidget/actions/fetchEvent.ts
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,80 @@ | ||
import {ActionURL, getServerContext } from "@labkey/api"; | ||
|
||
export const fetchEvent = async (eventID: string | undefined): Promise<FetchAnimalEventResponse> => { | ||
const url = ActionURL.buildURL('snd', 'getEvent.api') | ||
const headers = { | ||
'Content-Type': 'application/json', | ||
accept: 'application/json', | ||
'X-LABKEY-CSRF': getServerContext().CSRF | ||
} | ||
|
||
const body = JSON.stringify({ | ||
eventId: eventID, | ||
getTextNarrative: false, | ||
getRedactedNarrative: false, | ||
getHtmlNarrative: false, | ||
getRedactedHtmlNarrative: false, | ||
}) | ||
|
||
return fetch(url, { | ||
headers, | ||
body, | ||
method: 'post', | ||
credentials: 'include', | ||
}).then(async response => { | ||
const data = await response.json() | ||
if (!data.success) { | ||
throw new Error(data.event.exception.message) | ||
} | ||
if(response.status === 200) | ||
return data.event | ||
}) | ||
} | ||
|
||
export type FetchAnimalEventResponse = { | ||
date: string | ||
eventData: SuperPackageEventData[] | ||
eventId: number | ||
extraFields: Field[] | ||
htmlNarrative: string | ||
note: string | ||
projectIdRev: string | ||
qcState: QCState | ||
redactedHtmlNarrative: string | ||
subjectId: string | ||
textNarrative: string | ||
} | ||
|
||
type SuperPackageEventData = { | ||
attributes: [] | ||
eventDataId: number | ||
extraFields: Field[] | ||
narrativeTemplate: string | ||
subPackages: SuperPackageEventData[] | ||
superPkgId: number | ||
} | ||
|
||
type Field = { | ||
} | ||
|
||
type QCState = 'Completed' | 'In Progress' | 'Review Required' | 'Rejected' | ||
|
||
type ResponseError = { | ||
exception: string | ||
} | ||
|
||
export class ResponseHadErrorException extends Error { | ||
stackTrace: string[] | ||
|
||
constructor({ exception, exceptionClass, stackTrace }: ResponseWithError) { | ||
super(exception) | ||
this.name = exceptionClass | ||
this.stackTrace = stackTrace | ||
} | ||
} | ||
|
||
interface ResponseWithError { | ||
exception: string | ||
exceptionClass: string | ||
stackTrace: string[] | ||
} |
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,89 @@ | ||
import { ActionURL, getServerContext } from '@labkey/api'; | ||
|
||
export const saveEvent = async (eventToSave: EventToSave): Promise<SaveEventResponse> => { | ||
const url = ActionURL.buildURL('snd', 'saveEvent.api').replace('.org//', '.org/') | ||
|
||
const response = await fetch(url, { | ||
method: 'POST', | ||
body: JSON.stringify(eventToSave), | ||
credentials: 'include', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
accept: 'application/json', | ||
'X-LABKEY-CSRF': getServerContext().CSRF, | ||
}, | ||
}) | ||
|
||
const json = await response.json() | ||
|
||
if (response?.status === 500) { | ||
throw new LabkeyError(json) | ||
} | ||
|
||
if (response?.status !== 200) { | ||
// @todo, investigate if this is needed | ||
throw new LabkeyError(json) | ||
} | ||
|
||
if (!json.success) { | ||
throw new LabkeyError(json) | ||
} | ||
|
||
return json | ||
} | ||
|
||
export interface EventToSave { | ||
eventId?: number, | ||
date: string, // YYYY-MM-DDTHH:mm:ss | ||
projectIdRev: string | ||
subjectId: string, | ||
qcState: QCState, | ||
note?: string, | ||
extraFields?: PropertyDescriptor[], | ||
eventData: EventData[] | ||
} | ||
|
||
export interface SaveEventResponse { | ||
success: boolean | ||
event: Event | ||
} | ||
|
||
class LabkeyError extends Error { | ||
constructor({ exception, exceptionClass, stackTrace }) { | ||
const message = ` | ||
${exception} | ||
${stackTrace.join('\n\t').toString()} | ||
`.trim() | ||
|
||
super(message) | ||
this.name = exceptionClass | ||
this.stack = stackTrace | ||
} | ||
} | ||
|
||
interface EventData { | ||
eventDataId?: number, | ||
exception?: Exception | ||
superPkgId: number, | ||
narrativeTemplate?: string, | ||
extraFields?: PropertyDescriptor[], | ||
attributes: Attribute[] | ||
subPackages: EventData[] | ||
} | ||
|
||
export interface Attribute { | ||
propertyId: number, | ||
propertyName?: string, | ||
value: string | number, | ||
propertyDescriptor?: PropertyDescriptor | ||
exception?: Exception | ||
} | ||
|
||
|
||
interface Exception { | ||
message: string, | ||
severity: string | ||
} | ||
|
||
type QCState = 'Completed' | 'Rejected' | 'Review Required' | 'In Progress' |
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
2 changes: 1 addition & 1 deletion
2
snprc_ehr/src/client/SndEventsWidget/components/AdmissionInfoPopover.tsx
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
71 changes: 71 additions & 0 deletions
71
snprc_ehr/src/client/SndEventsWidget/components/DeleteModal.tsx
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,71 @@ | ||
import React, { FC, memo, ReactNode, useState } from 'react'; | ||
import { ConfirmModal, resolveErrorMessage } from '@labkey/components'; | ||
import { FetchAnimalEventResponse, fetchEvent } from '../actions/fetchEvent'; | ||
import { EventToSave, saveEvent } from '../actions/saveEvent'; | ||
|
||
interface Props { | ||
onCancel: () => any, | ||
onComplete: (message, status) => any, | ||
onError: (message) => any, | ||
eventId: string, | ||
} | ||
export const DeleteModal: FC<Props> = memo((props: Props) => { | ||
const {onCancel, onComplete, onError, eventId } = props; | ||
const [error, setError] = useState<ReactNode>(undefined); | ||
const [isSubmitting, setIsSubmitting] = useState<boolean>(false); | ||
|
||
const handleDelete = async () => { | ||
setIsSubmitting(true); | ||
|
||
const event: FetchAnimalEventResponse | void = await fetchEvent(eventId).catch(error => { | ||
console.error(error); | ||
setError(resolveErrorMessage(error, "Event", "Event" + 's', 'delete')); | ||
setIsSubmitting(false); | ||
}); | ||
|
||
if (event) { | ||
const deleteRequest: EventToSave = { | ||
eventId: event.eventId, | ||
date: event.date, | ||
projectIdRev: event.projectIdRev, | ||
subjectId: event.subjectId, | ||
qcState: event.qcState, | ||
note: '', | ||
extraFields: event.extraFields, | ||
eventData: [] | ||
} | ||
|
||
saveEvent(deleteRequest) | ||
.then(t => { | ||
if (t.success) { | ||
onComplete('Successfully deleted Event', 'success'); | ||
} else { | ||
onComplete('There was a problem deleting the Event', 'danger'); | ||
} | ||
|
||
}) | ||
.catch(error => { | ||
console.error(error); | ||
setError(resolveErrorMessage(error, "Event", "Event" + 's', 'delete')); | ||
setIsSubmitting(false); | ||
}); | ||
} | ||
|
||
} | ||
|
||
return ( | ||
<div className={'delete-modal'}> | ||
<ConfirmModal | ||
title={'Delete Event'} | ||
onConfirm={handleDelete} | ||
onCancel={onCancel} | ||
confirmVariant={'danger'} | ||
confirmButtonText={'Yes, Permanently delete Event'} | ||
cancelButtonText={'Cancel'} | ||
submitting={isSubmitting} | ||
> | ||
<p><b>Event for this Procedure will be permanently deleted. Do you want to proceed?</b></p> | ||
</ConfirmModal> | ||
</div> | ||
) | ||
}) |
Oops, something went wrong.