Sync and response change notification help !!

Discussions about creating CAPI applications to run on Android devices
Forum rules
New release: CSPro 8.0
Post Reply
hcomplex
Posts: 6
Joined: February 27th, 2017, 1:59 pm

Sync and response change notification help !!

Post by hcomplex »

I need some help with bluetooth sync , here is the scenario
the questionnaire has two parts male and female. The female enumerator fills out the roster and shares the roster with the male enumerator via bluetooth. The sync works fine for the first time but when we do this a second time it overwrites the first file.
if I change the destination folder then there is no .pff file there to be able to run the data file. Then I added another put command to send the .pff and .pen files with the data file to the new folder , that worked but now when i want to sync the completed cases with drop box i cant cause i have created new folders.
I am sure that there is a better way to do this and someone here knows how.

here is what my send sync file looks like
[SyncFile]
Version=CSPro 6.3
AppName=(Female to Male)
Description=Send data to male enumerator

[Connection]
Type=Bluetooth


[Sync]
ClientPath=/cspapp
CreateServerPath=/cspapp %DateTime%
ServerPath=/cspapp %DateTime%
Put=datafile1.dat
Put=cspapp.pen
put=cspapp.pff

The second issue is when the male enumerator receives the roster he goes over it with the male respondent and confirms the
responses given by the female respondent. Is there a way to notify or highlight when a previously given response is changed ? e.g if a relation ship previously selected as father is now changed to son ?

One last thing , in a capi application when filling out a survey if I go back and make a change I can uncheck the check boxes and delete any written responses but I cannot uncheck a radio button. Now if I go back and choose a different response that takes me to a different set of questions how can i delete the responses that were left behind in the form of those unchecked radio buttons ?

Any and all help is much appreciated.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Sync and response change notification help !!

Post by josh »

The sync scenario you are describing is a bit tricky. Unfortunately, I don't think there is a simple way to make it work. It is going to require some very advanced CSPro programming to make it work well. If you are not an experienced programmer you want to consider hiring a consultant to implement it for you.

Sync doesn't merge files or cases so you would need to transfer the file to the male enumerator via bluetooth as a separate data file and then use CSPro logic to combine it into the main data file. To do this you could make a second application for the female household roster that would just be used by the female enumerator. It would have its own dictionary and its own data file different from the one used by the male enumerator. The female enumerator would run this application, fill in the roster and use bluetooth sync to send the data file to the male enumerator. This data file would have a different name from the main data file so it would not overwrite it. Then in the main application you would add the dictionary from the female enumerator application as an external dictionary and associate it with the data file from the female enumerator application. In the main application you would now have two versions of the roster: one in the main program (from the male enumerator) and another in the external data file (from the female enuemrator). You would use the loadcase() function to load the household from the female enumerator file that corresponds to the household currently open in the main application. You could then copy, variable by variable, from the external file (female enumerator file) into the household roster in the main application.

I believe that the DHS survey does something similar - maybe someone with experience with DHS CAPI can explain how they do it.

For your second question, there isn't a simple way to see when a field was changed in CSPro. You could detect the change in logic for each question and add a flag variable to mark that the field was changed or you could use setnote() to add a note with the original value.

For you last question, once a question has been answered with radio buttons there is no way to manually set it to blank. In logic you can use the skip command which will blank out the value or set the value equal to "notappl" to set the field to blank, however if you are you using system controlled mode (which is the default for CAPI applications) you will get errors if you try to move forward in the questionnaire with a blank response (technically you change this behavior using the set behavior statement but it is not recommended). What we recommend is to add an additional radio button for "no answer" and set it to that value rather than to try to make it blank.
hcomplex
Posts: 6
Joined: February 27th, 2017, 1:59 pm

Re: Sync and response change notification help !!

Post by hcomplex »

Thank you so much Josh for your help.
The first problem I am still working on.
The second one I am trying making a string arrray and then saving it in temp or separate file and then looking up data from that file.
For the third issue I read somewhere on this forum that if you are in system control mode any jumps you make the data in the missed fields in turned grey and dropped at the end when the case is accepted. So far this has held true but if there is any other issues about this i should be concerned about please let me know.

Now I want to do two things:
When the case is accepted I want to change the name of the data file and save it to a location of my choosing.
Concatenate files right when they are saved.
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Sync and response change notification help !!

Post by josh »

Rather than saving a string array to a file, I would create an external dictionary and use writecase/loadcase. It is a little tricky initially to understand how those functions work but once you do it is much easier than using arrays and filewrite/fileread since CSPro handles all the file parsing code for you. Basically you create a second dictionary by going to File menu and picking Add Files... In the dialog that comes enter a name for your new dictionary. Edit the records/items as you normally would. You can run into issues if your external dictionary and main dictionary have items with the same names so try to avoid that. I usually add a prefix to the names in my external dictionary so if in my main dictionary I have PROVINCE and DISTRICT, in my external dictionary I will have EX_DISTRICT and EX_HOUSEHOLD_NUM. Then to fill in a case in the external dictionary you fill in the variables in your logic and call writecase. For example if in my external dictionary I have EX_DISTRICT and EX_HOUSEHOLD_NUM as id-items and then a repeating record with EX_NAME and EX_SEX as items in it my logic might look like:

Code: Select all

EX_DISTRICT = 1;
EX_HOUSEHOLD_NUM= 2;
EX_NAME(1) = "John";
EX_SEX(1) = 1;
EX_NAME(2) = "Barry";
EX_SEX(2) = 1;
...
writecase(MYEXT_DICT);
This saves all of those variables to your external data file. Then to load them back you use loadcase with the id-items to tell CSPro which case to lookup. It then loads your variables (EX_NAME, EX_SEX) with the values from the case that was saved in your file that matches the id-items you pass it. For example:

Code: Select all

EX_DISTRICT = 1;
EX_HOUSEHOLD_NUM= 2;
if loadcase(MYEXT_DICT,  EX_DISTRICT , EX_HOUSEHOLD_NUM) = 0 then
   errmsg("Failed to find case");
else
   // use the variables EX_SEX and EX_NAME
endif;
Search on the forum for lookup files and loadcase to see more.

Renaming the data file is not possible from within the data entry program. While the data entry program is running the file is locked and there is no way to rename it. What most people do is to use a menu program, which is a separate program that launches your data entry program. Instead of using the pff file that CSPro creates for you, your menu program generates a pff file using filewrite() and fills in the name of the data file that you want. It then calls execpff() to launch the main data entry program. There are lots of postings on the forum about menu programs. You can also look at http://teleyah.com/cspro/DCJune2015/10-Menu/10-Menu.pdf and http://teleyah.com/cspro/DCJune2015/10- ... rvey10.zip for an example.

You can use the fileconcat() function to concatenate files from within CSPro logic.
hcomplex
Posts: 6
Joined: February 27th, 2017, 1:59 pm

Re: Sync and response change notification help !!

Post by hcomplex »

Thank you once again for that detailed answer, Josh.
I was able to do something different but it still made it possible to notify the surveyor what the previous selection was. I used VisualValue and right when you get to that particular field it triggers a warning displaying the previously selected answer. It even works if you exit and load the app again.

Now I am stuck with the hardest part syncing this data without having to go through a million files.
What I am doing is this: The application is set up with three parts, the roster , the female and lastly the male part.
Female fills out the roster send it to the male and fills in the rest of the female part. When she is done with the female part she is asked to accept the case and the male part is left unfilled. The male receives the roster confirms the entries (visualvalue function) at the end of the roster he is asked to skip to the male part , he fills it in and accepts the case.
Now the both have a .dat file with the same name. Lets assume there is no internet connection and they move on to the next interview. The female fills the roster and send it to the male, this time the file that she is sending has the previous case (roster , female part filled , and male part unfilled) and this new case (roster filled , both female and male unfilled). When the male receives the file, the previous file he has is overwritten.
Another scenario is this, The female respondent is home but the male isnt. So the female surveyor still fills out the roster and the female part and send it to the male surveyor but he will have to come back at a later time. And then they move on to the next case .
Each time we sync everything on the male tablet is overwritten. What can I do to:
Save the files on the male tablet.
Is it possible to merge them with the file on the female tablet so i have one file with Roster , female part filled and the male part filled.
And then sync the files to the drop box folder.
The problem i am having is with the files on the male tablet. Since the files originate on the female tablet there are no issues there.

I hope I explained it well. This is a pretty tricky situation.
hcomplex
Posts: 6
Joined: February 27th, 2017, 1:59 pm

Re: Sync and response change notification help !!

Post by hcomplex »

Can I use a .PNC file to send data from one folder to another folder on the same device ?
if yes what do i choose as the connection type ?
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Sync and response change notification help !!

Post by josh »

Glad you were able to solve your problem with visualvalue(). Sounds like a good solution.

I understand the issues you are facing with the files being overwritten during sync. In my original answer I outlined an approach using a second dictionary to merge the files together. That is how I would handle this situation rather than trying to have the male and female interviewers sharing the same dictionary. Have a dictionary for the female interviewer with the just the roster and female section. You can copy and paste from your existing dictionary to that one. Then use your current dictionary for the male interviewer. The female interviewer has a data entry app that enters data into the female enumerator dictionary with a data file named say female.dat. She syncs that to the male interviewer. The male enumerator has an application that uses the combined dictionary with a data file named combined.dat. When the male interviewer syncs with the female interviewer, the male enumerator program loads the female.dat file using the female dictionary as an external dictionary and updates the cases in the combined.dat file. The problem with this approach is that you will have the roster duplicated in both dictionaries/applications and ideally we try to avoid duplicate dictionaries/forms/logic as it is hard to maintain.

The other option is to use 3 separate applications: roster, male, female. You would link them together using a menu program. Each one would have their own data file and you could combine them after syncing to the dropbox using concatenate data plus a record sort. I think this approach is harder to code and also makes it more difficult to do cross checks between the roster and the other sections.

Sync won't work on the same device but you don't need sync to move files around on the same device. Just use the filecopy() function. You may need to run it from a menu program though if you are trying to copy a data file that is opened in your data entry program.
Post Reply