@@ -5,9 +5,19 @@ import {
55 AuditEventType ,
66 PatientStatus ,
77 ProgrammeType ,
8+ SessionPresetName ,
9+ SessionType ,
810 VaccinationOutcome
911} from '../enums.js'
10- import { PatientProgramme , Patient , Programme , Vaccination } from '../models.js'
12+ import {
13+ PatientProgramme ,
14+ Patient ,
15+ Programme ,
16+ Vaccination ,
17+ PatientSession ,
18+ Session
19+ } from '../models.js'
20+ import { today } from '../utils/date.js'
1121import { getResults , getPagination } from '../utils/pagination.js'
1222import { formatYearGroup } from '../utils/string.js'
1323
@@ -388,6 +398,41 @@ export const patientController = {
388398 response . redirect ( patient . uri )
389399 } ,
390400
401+ record ( request , response ) {
402+ const { account } = request . app . locals
403+ const { programme_id } = request . params
404+ const { data } = request . session
405+ const { patient } = response . locals
406+
407+ const session = Session . create (
408+ {
409+ createdBy_uid : account . uid ,
410+ date : today ( ) ,
411+ type : SessionType . Clinic ,
412+ presetNames : SessionPresetName . Flu ,
413+ clinic_id : 'X99999'
414+ } ,
415+ data
416+ )
417+
418+ const createdPatientSession = PatientSession . create (
419+ {
420+ createdBy_uid : account . uid ,
421+ patient_uuid : patient . uuid ,
422+ programme_id,
423+ session_id : session . id
424+ } ,
425+ data
426+ )
427+
428+ const patientSession = PatientSession . findOne (
429+ createdPatientSession . uuid ,
430+ data
431+ )
432+
433+ response . redirect ( patientSession . uri )
434+ } ,
435+
391436 vaccination ( type ) {
392437 return ( request , response ) => {
393438 const { account } = request . app . locals
0 commit comments