Skip to content

Commit

Permalink
update plugins with custom error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ncrouzier-nist committed Aug 7, 2019
1 parent 7fbdb50 commit 406506f
Show file tree
Hide file tree
Showing 13 changed files with 24,263 additions and 874 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@
</dependency>
</dependencies>
<properties>
<hitcorehl7v2.version>1.0.19</hitcorehl7v2.version>
<hitcorehl7v2.version>1.0.20-SNAPSHOT</hitcorehl7v2.version>
</properties>
</project>
91 changes: 91 additions & 0 deletions src/main/java/gov/nist/hit/pcd/custom/ALERT_OBSERVATION_OBR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package gov.nist.hit.pcd.custom;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import hl7.v2.instance.Element;
import hl7.v2.instance.Query;
import hl7.v2.instance.Simple;
import scala.collection.Iterator;
import scala.collection.immutable.List;

public class ALERT_OBSERVATION_OBR {

public java.util.List<String> assertionWithCustomMessages(hl7.v2.instance.Element e) {
java.util.List<String> messages = new ArrayList<String>();
// System.out.println("get in");
List<Element> OBXList = Query.query(e, "2[*].1[1]").get();
// System.out.println(OBXList);

if (OBXList.size() >= 2) {
String OBX3_1 = getSimpleValue(Query.queryAsSimple(OBXList.apply(0), "3[1].2[1]").get());
String OBX3_2 = getSimpleValue(Query.queryAsSimple(OBXList.apply(1), "3[1].2[1]").get());
// String OBX3_3 = getSimpleValue(Query.queryAsSimple(OBXList.apply(2), "3[1].2[1]").get());

if (!OBX3_1.matches(".*_MDS")) {
messages.add("Missing Medical Device System (MDS) information");
return messages;
}
if (!OBX3_2.matches(".*_VMD")) {
messages.add("Missing Virtual Medical Devices (VMD) information");
return messages;
}
// if (!OBX3_3.matches(".*_CHAN")) {
// return false;
// }

}

//
// Iterator<Element> it = OBXList.iterator();
// while (it.hasNext()) {
// Element next = it.next();
// List<Simple> OBX3_1List = Query.queryAsSimple(next, "1[1]").get();
// List<Simple> OBX3_2List = Query.queryAsSimple(next, "2[1]").get();
// List<Simple> OBX3_3List = Query.queryAsSimple(next, "3[1]").get();
//
// String OBX3_1 = OBX3_1List.size() > 0 ? OBX3_1List.apply(0).value().raw() :
// "";
// String OBX3_2 = OBX3_2List.size() > 0 ? OBX3_2List.apply(0).value().raw() :
// "";
// String OBX3_3 = OBX3_3List.size() > 0 ? OBX3_3List.apply(0).value().raw() :
// "";
//
// // ignore 0 code terms or MDCX terms
// if (OBX3_1.equals("0") || OBX3_2.startsWith("MDCX_")) {
// return true;
// }
//
//
// if (OBX3_3.equals("MDC")) {
// ResourceHandler rh = new ResourceHandler();
// if (rh.dupletIsValid(OBX3_1, OBX3_2)) {
// return true;
// }else {
// return false;
// }
//
// }else {
// return true;
// }
//
// }

return messages;

}

private String getSimpleValue(List<Simple> simpleElementList) {
if (simpleElementList.size() > 1) {
throw new IllegalArgumentException("Invalid List size : " + simpleElementList.size());
}
if (simpleElementList.size() == 0) {
return null;
}
// only get first element
return simpleElementList.apply(0).value().raw();
}

}
21 changes: 11 additions & 10 deletions src/main/java/gov/nist/hit/pcd/custom/OBX_3.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package gov.nist.hit.pcd.custom;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;


import hl7.v2.instance.Element;
import hl7.v2.instance.Query;
Expand All @@ -23,11 +22,12 @@ public class OBX_3 {
* @return true if OBX-3.3 not MDC, true if OBX-3.2 and OBX-3.1 are valid, false otherwise
*/

public boolean assertion(hl7.v2.instance.Element e) {
public java.util.List<String> assertionWithCustomMessages(hl7.v2.instance.Element e) {
java.util.List<String> messages = new ArrayList<String>();
List<Element> OBXList = Query.query(e, "3[1]").get();
if (OBXList == null || OBXList.size() == 0) {
// OBR-3 is not present
return true;
return messages;
}

Iterator<Element> it = OBXList.iterator();
Expand All @@ -43,24 +43,25 @@ public boolean assertion(hl7.v2.instance.Element e) {

// ignore 0 code terms or MDCX terms
if (OBX3_1.equals("0") || OBX3_2.startsWith("MDCX_")) {
return true;
return messages;
}


if (OBX3_3.equals("MDC")) {
ResourceHandler rh = new ResourceHandler();
if (rh.dupletIsValid(OBX3_1, OBX3_2)) {
return true;
return messages;
}else {
return false;
messages.add("The REFID "+OBX3_2+" does not match with the provided code "+OBX3_1);
return messages;
}

}else {
return true;
return messages;
}

}

return true;
return null;
}
}
61 changes: 47 additions & 14 deletions src/main/java/gov/nist/hit/pcd/custom/OBX_UnitCheck.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gov.nist.hit.pcd.custom;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -23,17 +24,24 @@ public class OBX_UnitCheck {
* @return true if OBX-3.3 not MDC, true if OBX-3.2 and OBX-3.1 are valid, false otherwise
*/

public boolean assertion(hl7.v2.instance.Element e) {
public java.util.List<String> assertionWithCustomMessages(hl7.v2.instance.Element e) {
java.util.List<String> messages = new ArrayList<String>();
ResourceHandler rh = new ResourceHandler();

boolean checkOne = false;
boolean checkTwo = false;


List<Element> OBX3List = Query.query(e, "3[1]").get();
if (OBX3List == null || OBX3List.size() == 0) {
// OBX-3 is not present
return true;
return messages;
}

List<Element> OBX6List = Query.query(e, "6[1]").get();
if (OBX6List == null || OBX6List.size() == 0) {
// OBX-6 is not present
return true;
return messages;
}

Iterator<Element> it = OBX3List.iterator();
Expand All @@ -49,47 +57,72 @@ public boolean assertion(hl7.v2.instance.Element e) {

// ignore 0 code terms or MDCX terms
if (OBX3_1.equals("0") || OBX3_2.startsWith("MDCX_")) {
return true;
return messages;
}


if (OBX3_3.equals("MDC")) {



Iterator<Element> it6 = OBX6List.iterator();
while (it6.hasNext()) {
Element next6 = it6.next();


//primary
List<Simple> OBX6_1List = Query.queryAsSimple(next6, "1[1]").get();
List<Simple> OBX6_2List = Query.queryAsSimple(next6, "2[1]").get();
List<Simple> OBX6_3List = Query.queryAsSimple(next6, "3[1]").get();
String OBX6_1 = OBX6_2List.size() > 0 ? OBX6_1List.apply(0).value().raw() : "";
String OBX6_2 = OBX6_2List.size() > 0 ? OBX6_2List.apply(0).value().raw() : "";

String OBX6_3 = OBX6_3List.size() > 0 ? OBX6_3List.apply(0).value().raw() : "";
if (OBX6_3.equals("MDC")) {
if (!rh.dupletIsValid(OBX6_1, OBX6_2)) {
messages.add("The Unit REFID "+OBX6_2+" does not match with the provided code "+OBX6_1);
}
}


//alternate
List<Simple> OBX6_4List = Query.queryAsSimple(next6, "4[1]").get();
List<Simple> OBX6_5List = Query.queryAsSimple(next6, "5[1]").get();
List<Simple> OBX6_6List = Query.queryAsSimple(next6, "6[1]").get();
String OBX6_4 = OBX6_4List.size() > 0 ? OBX6_4List.apply(0).value().raw() : "";
String OBX6_5 = OBX6_5List.size() > 0 ? OBX6_5List.apply(0).value().raw() : "";
String OBX6_6 = OBX6_6List.size() > 0 ? OBX6_6List.apply(0).value().raw() : "";

if (OBX6_6.equals("MDC")) {
if (!rh.dupletIsValid(OBX6_4, OBX6_5)) {
messages.add("The Unit REFID "+OBX6_5+" does not match with the provided code "+OBX6_4);
}
}

ResourceHandler rh = new ResourceHandler();


if (rh.unitIsValid(OBX3_2, OBX6_2) && rh.unitIsValid(OBX3_2, OBX6_5)) {
return true;
checkOne = rh.unitIsValid(OBX3_1, OBX3_2, OBX6_2);
checkTwo = rh.unitIsValid(OBX3_1, OBX3_2, OBX6_5);
if (checkOne && checkTwo) {
return messages;
}else {

return false;
if (!checkOne) {
messages.add("The provided primary unit ("+OBX6_2+") associated with "+ OBX3_2 + " is not valid");
}
if (!checkTwo) {
messages.add("The provided alternate unit ("+OBX6_5+") associated with "+ OBX3_2 + " is not valid");
}
return messages;
}
}




}else {
return true;
return messages;
}

}

return true;
return messages;
}
}
38 changes: 30 additions & 8 deletions src/main/java/gov/nist/hit/pcd/custom/ResourceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

public class ResourceHandler {

private static final String VERSION = "october2018";

private static List<MDCterm> mdcValues;
private static List<MDCUnitsterm> mdcUnitsTerms;

Expand All @@ -31,7 +33,7 @@ public ResourceHandler() {
public List<MDCterm> loadMDC(){

List<MDCterm> values = new ArrayList<>();
try(BufferedReader br= new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/" + "mdccodes.csv")))) {
try(BufferedReader br= new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/"+VERSION+"/" + "mdccodes.csv")))) {
values = br.lines().map(line -> {return new MDCterm(line.split(",")[0],line.split(",")[1]);}).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -42,7 +44,7 @@ public List<MDCterm> loadMDC(){
public List<MDCUnitsterm> loadMdcUnitsTerms(){

List<MDCUnitsterm> values = new ArrayList<>();
try(BufferedReader br= new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/" + "units.csv")))) {
try(BufferedReader br= new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/"+VERSION+"/" + "units.csv")))) {
values = br.lines().map(line -> {return new MDCUnitsterm(line.split(",")); }).collect(Collectors.toList());
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -80,14 +82,34 @@ public boolean dupletIsValid (String code, String refid) {
}


public boolean unitIsValid (String refid, String unit) {
public boolean unitIsValid (String code, String refid, String unit) {
// if no unit present, no need to check..

if (unit == null || unit.isEmpty()) {
return true;
}
for (MDCUnitsterm mdc : mdcUnitsTerms) {
if (mdc.getRefid().equals(refid)) {
if (mdc.getUnits().contains(unit)) {
return true;
}else {
return false;

if (mdc.getCode().equals(code) || mdc.getRefid().equals(refid)) {
for (String u : mdc.getUnits()) {
if (u.contains("_X_")){
if (u.equals(unit) || unit.matches(u.replace("_X_", "_.*"))) {

return true;
}
}else if (u.contains("_X")){ //suffix
if (u.equals(unit) || unit.matches(u.replace("_X", "_.+"))) {

return true;
}
}else {

if (u.equals(unit)){
return true;
}
}
}
return false;
}
}
//couldn't find refid, no errors
Expand Down
29 changes: 23 additions & 6 deletions src/main/java/gov/nist/hit/pcd/custom/model/MDCUnitsterm.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@

public class MDCUnitsterm {

private List<String> units;
private String code;
private String refid;

private List<String> units;




public MDCUnitsterm(String[] refAndunits) {
refid = refAndunits[0];
units = new ArrayList<>(Arrays.asList(refAndunits));
units.remove(0);
public MDCUnitsterm(String[] codeRefAndunits) {
code = codeRefAndunits[0];
refid = codeRefAndunits[1];
units = new ArrayList<>(Arrays.asList(codeRefAndunits));
units.remove(0); // remove code
units.remove(0); // remoce refid
}


public MDCUnitsterm(String refid,List<String> units) {
public MDCUnitsterm(String code,String refid,List<String> units) {
super();
this.code = code;
this.units = units;
this.refid = refid;
}
Expand All @@ -45,6 +51,17 @@ public void setRefid(String refid) {
}


public String getCode() {
return code;
}


public void setCode(String code) {
this.code = code;
}






Expand Down
Loading

0 comments on commit 406506f

Please sign in to comment.