Commit ef21b8d6 authored by Marco Descher's avatar Marco Descher
Browse files

changes

parent 9d25a1fc
monitor = Polyglot.import("monitor");
logger = Polyglot.import("logger");
monitor.beginTask("Importiere MediData Versichererliste", 100);
// downloading a file without a browser setting proved complicated,
// due to this the framework provides the function download
download = Polyglot.import("download");
const url = "http://download.elexis.info/elexis/versichererliste.csv";
csvString = download(url);
// load the papa parse library
// see https://github.com/graalvm/graaljs/blob/master/docs/user/JavaScriptCompatibility.md
load("https://raw.githubusercontent.com/mholt/PapaParse/master/papaparse.js");
var results = Papa.parse(csvString, {
header: true
});
logger.error(JSON.stringify(results.errors));
coreModelService = Polyglot.import("coreModelService");
const IOrganizationType = Java.type("ch.elexis.core.model.IOrganization");
var findExistingOrganization = function(org, departement, street, city) {
var contactQuery = coreModelService.getQuery(IOrganizationType);
var iQuery = Java.type("ch.elexis.core.services.IQuery");
contactQuery.and("description1", iQuery.COMPARATOR.EQUALS, org);
contactQuery.and("description2", iQuery.COMPARATOR.EQUALS, departement);
contactQuery.and("city", iQuery.COMPARATOR.EQUALS, city);
contactQuery.and("street", iQuery.COMPARATOR.EQUALS, street);
result = contactQuery.execute();
if (result.length > 0) {
logger.warn(
"Kontakt [{}] existiert bereits. Wird nicht imporiert.",
org + " " + departement + ", " + street + ", " + city
);
return true;
}
return false;
};
for (entry of results.data) {
var ad1 = entry["address1"];
var ad2 = entry["address2"];
var street = ad2 ? ad1 + ", " + ad2 : ad1;
if (
findExistingOrganization(
entry["organisation"],
entry["departement"],
street,
entry["city"]
)
) {
monitor.worked(1);
continue;
}
var org = coreModelService.create(IOrganizationType);
org.setDescription1(entry["organisation"]);
org.setDescription2(entry["departement"]);
org.setStreet(street);
org.setCity(entry["city"]);
org.setZip(entry["zipcode"]);
org.setPhone1(entry["phone"]);
org.setEmail(entry["email"]);
org.setWebsite(entry["insuranceLink"]);
org.setInsuranceLawCode(entry["lawCode"]);
org.setInsuranceXmlName(entry["XMLInsuranceName"]);
var insuranceEan = entry["insuranceGLN"];
if (insuranceEan && 13 === insuranceEan.length) {
org.addXid("www.xid.ch/id/ean", insuranceEan, true);
}
var recipientEan = entry["recepientGLN"];
if (recipientEan && 13 === recipientEan.length) {
org.addXid("www.xid.ch/id/recipient_ean", recipientEan, true);
}
coreModelService.save(org);
monitor.worked(1);
}
monitor.done();
name = "Importer Mediport Versichererliste"
description = "Importiere die Mediport Versichererliste"
category = "Importer"
[executor]
type = "js"
entrypoint = "main.js"
......@@ -7,22 +7,33 @@ import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.IProgressMonitor;
import org.slf4j.Logger;
import ch.elexis.core.constants.XidConstants;
import ch.elexis.core.model.IAddress;
import ch.elexis.core.model.IOrganization;
import ch.elexis.core.model.ModelPackage;
import ch.elexis.core.model.builder.IContactBuilder;
import ch.elexis.core.services.IModelService;
import ch.elexis.core.services.IQuery;
import ch.elexis.core.services.IQuery.COMPARATOR;
import ch.elexis.core.types.Country;
import info.elexis.server.misthios.MisthiosException;
import info.elexis.server.misthios.MisthiosTask;
import info.elexis.server.misthios.MisthiosTaskResult;
/**
*
* @see ch.elexis.core.ui.importer.div.importers.MediportInsurerImporter
*/
public class MediportInsurerImporter implements MisthiosTask {
@Override
public MisthiosTaskResult run(Map<String, Object> context) {
public Map<String, Object> run(Map<String, Object> context) throws MisthiosException {
IModelService coreModelService = (IModelService) context.get("coreModelService");
Logger logger = (Logger) context.get("logger");
IProgressMonitor monitor = (IProgressMonitor) context.get("monitor");
......@@ -33,14 +44,14 @@ public class MediportInsurerImporter implements MisthiosTask {
try {
sourceFile = new URL("http://download.elexis.info/elexis/versichererliste.csv");
} catch (MalformedURLException e1) {
return MisthiosTaskResult.ERROR(e1);
throw new MisthiosException(e1);
}
try (InputStream is = sourceFile.openStream()) {
importCSVFromStream(coreModelService, logger, monitor, is);
monitor.done();
return MisthiosTaskResult.OK();
return Collections.emptyMap();
} catch (IOException e) {
return MisthiosTaskResult.ERROR(e);
throw new MisthiosException(e);
}
}
......@@ -66,9 +77,8 @@ public class MediportInsurerImporter implements MisthiosTask {
public static List<IOrganization> importCSVFromStream(IModelService coreModelService, Logger logger,
IProgressMonitor monitor, InputStream csvInStream) {
List<IOrganization> insurerList = new ArrayList<IOrganization>();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(csvInStream));
List<IOrganization> insurerList = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(csvInStream))) {
String line = "";
int lineNo = 0;
......@@ -97,42 +107,44 @@ public class MediportInsurerImporter implements MisthiosTask {
String lawCode = parts[IDX_LAW_CODE];
String mediport = parts[IDX_MEDIPORT_SUPPORT];
// IQuery<IOrganization> contactQuery = coreModelService.getQuery(IOrganization.class);
// contactQuery.add(Kontakt.FLD_NAME1, Query.EQUALS, org);
// contactQuery.add(Kontakt.FLD_NAME2, Query.EQUALS, dept);
// contactQuery.add(Kontakt.FLD_STREET, Query.EQUALS, street);
// contactQuery.add(Kontakt.FLD_PLACE, Query.EQUALS, city);
// List<IOrganization> contactList = contactQuery.execute();
// if (contactList != null && !contactList.isEmpty()) {
// logger.warn("Kontakt [" + org + " " + dept + ", " + street + ", " + city
// + "] existiert bereits. Wird nicht imporiert.");
// continue;
// }
IOrganization insurer = new IContactBuilder.OrganizationBuilder(coreModelService, org).build();
IQuery<IOrganization> contactQuery = coreModelService.getQuery(IOrganization.class);
contactQuery.and(ModelPackage.Literals.ICONTACT__DESCRIPTION1, COMPARATOR.EQUALS, org);
contactQuery.and(ModelPackage.Literals.ICONTACT__DESCRIPTION2, COMPARATOR.EQUALS, dept);
contactQuery.and(ModelPackage.Literals.ICONTACT__STREET, COMPARATOR.EQUALS, street);
contactQuery.and(ModelPackage.Literals.ICONTACT__CITY, COMPARATOR.EQUALS, city);
List<IOrganization> contactList = contactQuery.execute();
if (contactList != null && !contactList.isEmpty()) {
logger.warn("Kontakt [{}] existiert bereits. Wird nicht imporiert.",
org + " " + dept + ", " + street + ", " + city);
continue;
}
IOrganization insurer = new IContactBuilder.OrganizationBuilder(coreModelService, org)
.defaultAddress(street, zip, city, Country.CH).build();
insurer.setDescription2(dept);
insurer.setStreet(street);
insurer.setZip(zip);
insurer.setCity(city);
insurer.setPhone1(phone);
insurer.setEmail(email);
insurer.setWebsite(website);
// titelSuffix -> lawCode
// allergien -> xmlInsuranceName
insurer.setInsuranceLawCode(lawCode);
insurer.setInsuranceXmlName(xmlInsuranceName);
IAddress address = coreModelService.create(IAddress.class);
insurer.addAddress(address);
// insurer.setAnschrift(new Anschrift(insurer));
// insurer.getXid();
//
// // set EANs
// if (insuranceEAN != null && insuranceEAN.length() == 13) {
// insurer.setInsurerEAN(insuranceEAN);
// }
// if (recepientEAN != null && recepientEAN.length() == 13) {
// insurer.setRecepientEAN(recepientEAN);
// }
//
// // set further information
// set EANs
if (insuranceEAN != null && insuranceEAN.length() == 13) {
insurer.addXid(XidConstants.DOMAIN_EAN, insuranceEAN, true);
}
if (recepientEAN != null && recepientEAN.length() == 13) {
insurer.addXid(XidConstants.DOMAIN_RECIPIENT_EAN, recepientEAN, true);
}
// set further information
// insurer.setSupportsMediport(MEDIPORT_CONNECTED.equalsIgnoreCase(mediport));
insurer.setGroup((MEDIPORT_CONNECTED.equalsIgnoreCase(mediport)) ? "1" : "0");
boolean save = coreModelService.save(insurer);
if (!save) {
......@@ -141,7 +153,6 @@ public class MediportInsurerImporter implements MisthiosTask {
insurerList.add(insurer);
monitor.worked(1);
}
reader.close();
} catch (Exception e) {
logger.error("Exception on execution", e);
return insurerList;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment