|-- preset (for storing preset files)
| |-- additional.csv
| |-- advice.csv
- | |-- certify.csv
+ | |-- certificate.csv
| |-- investigation.csv
| |-- medication.csv
| |-- note.csv
Plugins may also contain a web app written in HTML/JavaScript. To use it the
plugin must contain a function called `web` which takes the prescription object
-and returns the URL of the web app. The run function of such a plugin must
+and returns a tuple containing the URL of the web app and a json string
+containing any data to be passed on to the web app. The `run` function of such a plugin must
take two arguments, the prescription and the data returned from the web app.
-The web app itself must include the qtwebchannel.js from PyQt6. The webchannel
-exposes an object named `js` to the web app. The web app may return data by
-calling the `run` function of the exposed `js` object.
+The web app itself must include the `qtwebchannel.js` from PyQt6
+(qrc:///qtwebchannel/qwebchannel.js). The webchannel exposes an object named
+`js` to the web app. The web app may access the prescription by using the
+`js.getPrescription()` and the data from the plugin by using the `js.getData()`
+function. The webapp may return data to the plugin by calling the `run`
+function of the exposed `js` object with two arguments, first being a json
+string containing the prescription object and the second being any data as
+string to be passed onto the plugin.
Template Development
--------------------
# MedScript is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along with MedScript. If not, see <https://www.gnu.org/licenses/>.
-import logging, os, importlib, copy
+import logging, os, importlib, copy, json
from PyQt6.QtWidgets import QMessageBox, QMainWindow, QInputDialog, QFileDialog, QVBoxLayout
from PyQt6.QtCore import QObject, QThread, QUrl, pyqtSignal, pyqtSlot
from PyQt6.QtWebChannel import QWebChannel
if(hasattr(module, "web") and callable(module.web)):
self.webapp=WebApp()
self.webapp.done.connect(lambda: self.update.emit())
- url=module.web(prescription)
- self.webapp.load(module, QUrl(url), prescription)
+ url, data=module.web(prescription)
+ self.webapp.load(module, QUrl(url), prescription, data)
self.webapp.show()
elif(hasattr(module, "run") and callable(module.run)):
if(hasattr(module, "confirm") and module.confirm):
self.webview=QWebEngineView()
self.setCentralWidget(self.webview)
- def load(self, module, url, prescription):
+ def load(self, module, url, prescription, data):
self.module=module
self.webview.load(url)
self.channel=QWebChannel()
- self.js=JS(module, prescription)
+ self.js=JS(module, prescription, data)
self.channel.registerObject("js", self.js)
self.webview.page().setWebChannel(self.channel)
self.js.done.connect(lambda: self.done.emit())
done=pyqtSignal()
- def __init__(self, module, prescription):
+ def __init__(self, module, prescription, data):
super().__init__()
self.module=module
self.prescription=prescription
+ self.data=data
- @pyqtSlot(str)
- def run(self, data):
+ @pyqtSlot(str, str)
+ def run(self, prescription, result):
+ self.prescription.set_data_from_json(json.loads(prescription))
try:
- message=self.module.run(self.prescription, data)
+ message=self.module.run(self.prescription, result)
if(message):
QMessageBox.information(None, "Information", message)
self.done.emit()
logging.error(self.module)
logging.exception(e)
+ @pyqtSlot(result=str)
+ def getPrescription(self):
+ return self.prescription.get_json()
+
+ @pyqtSlot(result=str)
+ def getData(self):
+ return self.data
+
class Worker(QThread):
pluginComplete=pyqtSignal(str, int)