Keeping Track of Entered Cases


Unfortunately, CSPro does not have a way, within a data entry application, to get a listing of the IDs of the other cases that have been entered to the primary data file. If your application is somewhat simple, you can write a two-dictionary application to facilitate a basic version of case management.

In this example, the main dictionary of the application is a junk dictionary. Any data entered to this dictionary will be ignored. We only use this dictionary to provide the framework for the main data entry application and as a way to enter a menu selection.

The external dictionary and form is actually where data is entered for this application. By using loadcase and writecase statements, it is possible to add and modify cases.

Whenever the data entry application is started, an array is populated with information about all of the cases in the data file. In this example, the program is hardcoded to expect that information about households 1-8 will eventually be added to the file. The program reports on what has been entered and what cases are remaining.

20120222menu

This list is created by using the find statement to check on all of the expected IDs in the external file (which really is the main data file for this application). Then the setvalueset and setcapturetype functions display the results on the screen.

Download the example here, or view the code below.

PROC GLOBAL

array numeric casesIDs(100);
array alpha (30) casesLabels(100);

numeric numberCasesExpected = 8// eight cases expected for the cluster

PROC MENU_FF

PROC MENU_ID

onfocus

    MENU_ID = 
notappl// reset any value that might be here

   
numeric cnt,numLabels,someCasesNotEntered;

   
do cnt = 1 while cnt <= numberCasesExpected

        HHID = cnt;
        casesIDs(numLabels) = HHID;

       
if find(QUESTIONNAIRE_DICT,=,itemlist(HHID)) then
            casesLabels(numLabels) = 
maketext("Modify Household %d",cnt);

       
else
            casesLabels(numLabels) = 
maketext("Add Household %d",cnt);
            someCasesNotEntered = 
1;

       
endif;

       
inc(numLabels);

   
enddo;

    casesIDs(numLabels) = 
99;
    casesLabels(numLabels) = 
"Quit";

   
inc(numLabels);
    casesIDs(numLabels) = 
notappl// end the dynamic value set

   
setvalueset(MENU_ID,casesIDs,casesLabels);
   
setcapturetype(MENU_ID,1);

postproc

   
if MENU_ID = 99 then

       
if someCasesNotEntered then

           
if ( errmsg("You are not finished entering cases. Are you sure you want to quit?"select("Yes",continue,"No",continue) ) = 2 then
               
reenter;
           
endif;

       
endif;

       
stop(1);

   
endif;

    HHID = MENU_ID;

   
if not loadcase(QUESTIONNAIRE_DICT,HHID) then
       
clear(QUESTIONNAIRE_DICT); // we are adding a new case so we must make sure the fields are blank
        HHID = MENU_ID;
   
endif;

   
enter QUESTIONNAIRE_FF;

   
writecase(QUESTIONNAIRE_DICT); // write the case to the data file

   
reenter;