We are currently working on the forum. For the short-term, all forum content will be in read-only format. We apologize for the interruption and look forward to collaborating with you shortly. All the best in your research!

Web Service CRF



  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    Hi @kevinteh

    Not sure if you still need it but I have been working on SOAP webservices in PHP and started out with what seemed the easiest one - StudyEventDefinition.

    The file is at [1], its pretty rough but it works (for me) and should give an idea of how to call the listAll function and getMetadata function. It uses the SOAP extension so first you need to enable that in php.ini.

    Stuff to update before use includes:
    1. the items in the $soap_meta array at lines 39-41 to your details (pass as sha1),
    2. the unique id in $sarg_identifier at line 53 to what you want. I only tested it with study level metadata though, not site level.
    3. if you wanted the item oids you'd need to change the xpath at line 85 to something like "//odm:ItemDef/@OID".

    The trickiest parts for me were:
    - setting the security header (which some magician had posted on stackoverflow)
    - getting the getMetadata request right - after nesting the elements (aka array'ed SoapVars) you have to add an extra array for good luck ($sarg_final, line 58).
    - to read the xml, you have to declare the namespace for xpath to work, and the result will be an array even if there is only one result (e.g. StudyName).

    If you / anyone else has any questions about this feel free to ask. I will need to be using pretty much all the SOAP services in the near future so I was going to post examples of how to do that once I know for myself.

    [1] https://github.com/lindsay-stevens-kirby/openclinica_scripts/blob/master/webservices/ws_studydef.php

    Best regards,
  • kevintehkevinteh Posts: 32
    Thank you so much Lindsay for all your help...That is very useful indeed. Great work. Cheers.

  • lindsay.stevenslindsay.stevens Posts: 404 ✭✭✭
    Just an update per my last comment:

    I've tidied up the example from earlier in the month into a class with functions for each of the SOAP webservices available. (see OpenClinicaSoapWebService.php). The functions are designed for a one thing at a time, e.g. one subject per subjectCreateSubject call, one event per eventSchedule call, etc.

    The exception is dataImport, where you can send whatever is in the ODM tree. I have included a set of classes for building the ODM tree and a function for converting that into xml for use with dataImport (see OpenClinicaODMFunctions.php)

    Lastly there is the test data I was using, which doubles as an example on how to use it all (see OpenClinicaWSExamples.php).

    There's some more tidying up to do, some error handling to add; at the very least I plan to add in phpDoc blocks.

    If there are any php wizards on the list I'd appreciate any feedback.
This discussion has been closed.