I\'m not that great with SQL Server, but I\'m trying to do some behind the scenes work to create some functionality that our EMR system lacks - copying forms (and all their
Psuedo code, not tested:
DECLARE @patient_id INT, @date datetime, @time ??
SET @patient_id = 112244 --your patient id
INSERT INTO [**Table 1**] (patient_id, date, time, etc, etc, etc, etc)
VALUES (@patient_id, @date, @time, 'a', 'b', 'c', 'd')
DECLARE @encounter_id int
SET @encounter_id = SCOPE_IDENTITY -- or select @encounter_id = encounter_id from [**Table 1**] where patientId = @patient_id
INSERT INTO [**Table 2**] (encounter_id, page, recorded_on, recorded_by, etc, etc2)
SELECT @encounter_id, page, recorded_on, recorded_by, etc, etc2
FROM [**Table 2**]
WHERE encounter_id = 1234
INSERT INTO [**Table 3**] (encounter_id, page, keyname, keyvalue)
SELECT @encounter_id, page, keyname, keyvalue
FROM [**Table 3**]
WHERE encounter_id = 1234