Merge and aggregate datasets: Difference between revisions

Content added Content deleted
(Harbour: allow for left join)
(Harbour: allow for left join)
Line 846: Line 846:
LOCATE FOR patient_id==xCurId
LOCATE FOR patient_id==xCurId
IF found()
IF found()
&& aggregate within visits for a given patient
&& aggregate within visits for a given patient
aAgg := {0, 0.0, ctod("19000101")} && initial values
aAgg := {0, 0.0, ctod("19000101")} && initial values
DO WHILE ! Eof() .AND. xCurId == patient_id
DO WHILE ! Eof() .AND. xCurId == patient_id
aAgg := {1+aAgg[1], score+aAgg[2], max(visit_date, aAgg[3])} && update
aAgg := {1+aAgg[1], score+aAgg[2], max(visit_date, aAgg[3])} && update
SKIP
SKIP
ENDDO
ENDDO
INSERT INTO report (patient_id, lastname, n, sum_score, avg_score, max_date) ;
INSERT INTO report (patient_id, lastname, n, sum_score, avg_score, max_date) ;
VALUES (xCurId, patient->lastname, aAgg[1], aAgg[2], aAgg[2]/aAgg[1], aAgg[3])
VALUES (xCurId, patient->lastname, aAgg[1], aAgg[2], aAgg[2]/aAgg[1], aAgg[3])
ELSE
ELSE
INSERT INTO report (patient_id, lastname) VALUES (xCurId, patient->lastname)
INSERT INTO report (patient_id, lastname) VALUES (xCurId, patient->lastname)
END IF
END IF
SELECT patient
SELECT patient