Skip to content

Commit

Permalink
SOAP Client to query Estonia National Patient Registry for Patient D…
Browse files Browse the repository at this point in the history
…emographics fix #1320
  • Loading branch information
gunterze committed Jun 28, 2023
1 parent 7e17265 commit 1bd97cf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 30 deletions.
31 changes: 19 additions & 12 deletions dcm4che-tool/dcm4che-tool-xroad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@ names reflecting the Estonian property names in the SOAP messages.
Technically a response message may contain multiple patient records, which
is reflected by the first field "#", specifying the index of the patient
record in the response message contained by that CSV row: "1" marks the
first patient record in the response message, "2" the second, and so on.
"0" indicates, there was no patient record in the response message at all,
typically because there is no patient record with the given <patientID> in
the National Patient Registry. The second ("cIsikukoodid") and the third
("cValjad") field contain properties of the request message, the remaining
fields ("cIsikukood", "cPerenimi", "cEesnimi", "cMPerenimed",
"cMEesnimed", "cRiikKood", "cRiik", "cIsanimi", "cSugu", "cSynniaeg",
"cSurmKpv", "cTeoVoime", "cIsStaatus", "cKirjeStaatus", "cEKRiik",
"cEKMaak", "cEKVald", "cEKAsula", "cEKTanav", "cEKIndeks", "cEKAlgKpv",
"cEKVallaKpv", "cEKAadress", "cSynniRiik", "cSaabusEestiKpv", "faultCode",
"faultString") contain properties of the response message.
record in the response message contained by that CSV row:
- "1" marks the first patient record in the response message, "2" the
second, and so on.
- "0" indicates, there was no patient record in the response message at
all, typically because there is no patient record with the given
<patientID> in the National Patient Registry.
- "-1" signals an error receiving the response message, with last field
("faultString") containing an error message.
The second ("cIsikukoodid") and the third ("cValjad") field contain
properties of the request message, the remaining fields ("cIsikukood",
"cPerenimi", "cEesnimi", "cMPerenimed", "cMEesnimed", "cRiikKood",
"cRiik", "cIsanimi", "cSugu", "cSynniaeg", "cSurmKpv", "cTeoVoime",
"cIsStaatus", "cKirjeStaatus", "cEKRiik", "cEKMaak", "cEKVald",
"cEKAsula", "cEKTanav", "cEKIndeks", "cEKAlgKpv", "cEKVallaKpv",
"cEKAadress", "cSynniRiik", "cSaabusEestiKpv", "faultCode", "faultString")
contain properties of the response message.
-
Options:
-c continue on errors receiving
response messages.
--client.memberClass <value> set XRoad Client Identifier
property "memberClass", "NGO" by
default.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class XRoad implements AutoCloseable {
private final boolean csvHeader;
private final char csvDelim;
private final Character csvQuote;
private final boolean continueOnError;

private XRoad(String userID, String url, CommandLine cl) throws IOException {
port = new XRoadService().getXRoadServicePort();
Expand All @@ -133,7 +134,7 @@ private XRoad(String userID, String url, CommandLine cl) throws IOException {
csvHeader = !cl.hasOption("csv-no-header");
csvDelim = csvDelim(cl.getOptionValue("csv-delim"));
csvQuote = csvQuote(cl.getOptionValue("csv-quote"));

continueOnError = cl.hasOption("c");
}

private BufferedWriter newBufferedWriter(String pathName) throws IOException {
Expand Down Expand Up @@ -202,16 +203,23 @@ private static List<String> readLines(String pathName) throws IOException {
}
}

private void rr441(String pid) throws IOException {
private void rr441(String pid) throws Exception {
RR441RequestType rq = XRoadUtils.createRR441RequestType(cValjad, pid);
LOG.info("<< RR441Request{cIsikukoodid={}, cValjad={}}", pid, cValjad);
RR441ResponseType rsp = rr441(rq);
LOG.info(">> RR441Response{{}}", new Object() {
public String toString() {
return XRoad.this.toString(rsp);
}
});
if (csvWriter != null) writeCsvRows(rq, rsp);
try {
RR441ResponseType rsp = rr441(rq);
LOG.info(">> RR441Response{{}}", new Object() {
public String toString() {
return XRoad.this.toString(rsp);
}
});
if (csvWriter != null) writeCsvRows(rq, rsp);
} catch (Exception e) {
LOG.warn("Failed to receive RR441Response for RR441Request{cIsikukoodid={}, cValjad={}}:\n",
pid, cValjad, e);
if (!continueOnError) throw e;
if (csvWriter != null) writeCsvRow(rq, e);
}
}

private String toString(RR441ResponseType rsp) {
Expand Down Expand Up @@ -272,6 +280,17 @@ private void writeCsvRows(RR441RequestType rq, RR441ResponseType rsp) throws IOE
}
}

private void writeCsvRow(RR441RequestType rq, Exception e) throws IOException {
writeCsvValue("-1");
writeCsvDelimiterAndValue(rq.getCIsikukoodid());
writeCsvDelimiterAndValue(rq.getCValjad());
for (int i = 0; i < HEADERS.length - 3; i++) {
csvWriter.write(csvDelim);
}
writeCsvDelimiterAndValue(e.getMessage());
csvWriter.write("\r\n");
}

private void writeCsvRow(RR441RequestType rq, RR441ResponseType rsp, int index) throws IOException {
writeCsvValue(Integer.toString(index + 1));
writeCsvDelimiterAndValue(rq.getCIsikukoodid());
Expand Down Expand Up @@ -495,6 +514,9 @@ private static CommandLine parseComandLine(String[] args) throws ParseException
.argName("char")
.desc(rb.getString("csv-quote"))
.build());
opts.addOption(Option.builder("c")
.desc(rb.getString("continue-on-error"))
.build());
return CLIUtils.parseComandLine(args, opts, rb, XRoad.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ try=Try 'xroad --help' for more information.
description=\n\
XRoad SOAP Client to query Estonia National Patient Registry for Patient Demographics and optionally write \
query results in a CSV file with header names reflecting the Estonian property names in the SOAP messages.\n\n\
Technically a response message may contain multiple patient records, which is reflected by the first field \
"#", specifying the index of the patient record in the response message contained by that CSV row: "1" marks \
the first patient record in the response message, "2" the second, and so on. "0" indicates, there was no patient \
record in the response message at all, typically because there is no patient record with the given <patientID> in \
the National Patient Registry. The second ("cIsikukoodid") and the third ("cValjad") field contain properties of \
the request message, the remaining fields ("cIsikukood", "cPerenimi", "cEesnimi", "cMPerenimed", "cMEesnimed", \
"cRiikKood", "cRiik", "cIsanimi", "cSugu", "cSynniaeg", "cSurmKpv", "cTeoVoime", "cIsStaatus", "cKirjeStaatus", \
"cEKRiik", "cEKMaak", "cEKVald", "cEKAsula", "cEKTanav", "cEKIndeks", "cEKAlgKpv", "cEKVallaKpv", "cEKAadress", \
"cSynniRiik", "cSaabusEestiKpv", "faultCode", "faultString") contain properties of the response message.\n\-\n\
Technically a response message may contain multiple patient records, which is reflected by the first field "#", \
specifying the index of the patient record in the response message contained by that CSV row:\n\
- "1" marks the first patient record in the response message, "2" the second, and so on.\n\
- "0" indicates, there was no patient record in the response message at all, typically because there is no \
patient record with the given <patientID> in the National Patient Registry.\n\
- "-1" signals an error receiving the response message, with last field ("faultString") containing an error message.\n\n\
The second ("cIsikukoodid") and the third ("cValjad") field contain properties of the request message, the remaining \
fields ("cIsikukood", "cPerenimi", "cEesnimi", "cMPerenimed", "cMEesnimed", "cRiikKood", "cRiik", "cIsanimi", \
"cSugu", "cSynniaeg", "cSurmKpv", "cTeoVoime", "cIsStaatus", "cKirjeStaatus", "cEKRiik", "cEKMaak", "cEKVald", \
"cEKAsula", "cEKTanav", "cEKIndeks", "cEKAlgKpv", "cEKVallaKpv", "cEKAadress", "cSynniRiik", "cSaabusEestiKpv", \
"faultCode", "faultString") contain properties of the response message.\n\-\n\
Options:
example=-\n\
Examples:\n\
Expand Down Expand Up @@ -41,6 +43,7 @@ csv-no-header: write CSV file without header line.
csv-delim: delimiter character for CSV file specified by --csv. Defaults to , (comma).
csv-quote: quote character for CSV file specified by --csv. By default, only fields containing a line-break, \
double-quote or delimiters (commas) are quoted by a double-quote.
continue-on-error=continue on errors receiving response messages.
missing-user-opt=missing required option -u
missing-url-opt=missing required option --url
missing-pid=missing <patientID> operand

0 comments on commit 1bd97cf

Please sign in to comment.