-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eae585b
commit 7fbdb50
Showing
8 changed files
with
12,021 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package gov.nist.hit.pcd.custom; | ||
|
||
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 OBX_3 { | ||
|
||
|
||
/* | ||
* OBX-3: If OBX-3.3 is MDC, check if code/refid is valid . | ||
*/ | ||
|
||
/** | ||
* @param e | ||
* OBX context | ||
* @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) { | ||
List<Element> OBXList = Query.query(e, "3[1]").get(); | ||
if (OBXList == null || OBXList.size() == 0) { | ||
// OBR-3 is not present | ||
return true; | ||
} | ||
|
||
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 true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package gov.nist.hit.pcd.custom; | ||
|
||
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 OBX_UnitCheck { | ||
|
||
|
||
/* | ||
* OBX-3: If OBX-3.3 is MDC, check if code/refid is valid . | ||
*/ | ||
|
||
/** | ||
* @param e | ||
* OBX context | ||
* @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) { | ||
List<Element> OBX3List = Query.query(e, "3[1]").get(); | ||
if (OBX3List == null || OBX3List.size() == 0) { | ||
// OBX-3 is not present | ||
return true; | ||
} | ||
|
||
List<Element> OBX6List = Query.query(e, "6[1]").get(); | ||
if (OBX6List == null || OBX6List.size() == 0) { | ||
// OBX-6 is not present | ||
return true; | ||
} | ||
|
||
Iterator<Element> it = OBX3List.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")) { | ||
|
||
|
||
Iterator<Element> it6 = OBX6List.iterator(); | ||
while (it6.hasNext()) { | ||
Element next6 = it6.next(); | ||
|
||
|
||
//primary | ||
List<Simple> OBX6_2List = Query.queryAsSimple(next6, "2[1]").get(); | ||
String OBX6_2 = OBX6_2List.size() > 0 ? OBX6_2List.apply(0).value().raw() : ""; | ||
|
||
//alternate | ||
List<Simple> OBX6_5List = Query.queryAsSimple(next6, "5[1]").get(); | ||
String OBX6_5 = OBX6_5List.size() > 0 ? OBX6_5List.apply(0).value().raw() : ""; | ||
|
||
|
||
ResourceHandler rh = new ResourceHandler(); | ||
|
||
|
||
if (rh.unitIsValid(OBX3_2, OBX6_2) && rh.unitIsValid(OBX3_2, OBX6_5)) { | ||
return true; | ||
}else { | ||
|
||
return false; | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
}else { | ||
return true; | ||
} | ||
|
||
} | ||
|
||
return true; | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/gov/nist/hit/pcd/custom/ResourceHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package gov.nist.hit.pcd.custom; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import gov.nist.hit.pcd.custom.model.MDCUnitsterm; | ||
import gov.nist.hit.pcd.custom.model.MDCterm; | ||
|
||
public class ResourceHandler { | ||
|
||
private static List<MDCterm> mdcValues; | ||
private static List<MDCUnitsterm> mdcUnitsTerms; | ||
|
||
|
||
public ResourceHandler() { | ||
if (mdcValues == null) { | ||
mdcValues = loadMDC(); | ||
} | ||
|
||
if (mdcUnitsTerms == null) { | ||
mdcUnitsTerms = loadMdcUnitsTerms(); | ||
} | ||
|
||
|
||
} | ||
|
||
public List<MDCterm> loadMDC(){ | ||
|
||
List<MDCterm> values = new ArrayList<>(); | ||
try(BufferedReader br= new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/" + "mdccodes.csv")))) { | ||
values = br.lines().map(line -> {return new MDCterm(line.split(",")[0],line.split(",")[1]);}).collect(Collectors.toList()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return values; | ||
} | ||
|
||
public List<MDCUnitsterm> loadMdcUnitsTerms(){ | ||
|
||
List<MDCUnitsterm> values = new ArrayList<>(); | ||
try(BufferedReader br= new BufferedReader(new InputStreamReader(this.getClass().getResourceAsStream("/" + "units.csv")))) { | ||
values = br.lines().map(line -> {return new MDCUnitsterm(line.split(",")); }).collect(Collectors.toList()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return values; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
public boolean codeExists(String code) { | ||
for (MDCterm mdc : mdcValues) { | ||
if (mdc.getTermcode().equals(code)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
|
||
public boolean dupletIsValid (String code, String refid) { | ||
for (MDCterm mdc : mdcValues) { | ||
if (mdc.getRefid().equals(refid)) { | ||
if (mdc.getTermcode().equals(code)) { | ||
return true; | ||
}else { | ||
return false; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
|
||
public boolean unitIsValid (String refid, String unit) { | ||
for (MDCUnitsterm mdc : mdcUnitsTerms) { | ||
if (mdc.getRefid().equals(refid)) { | ||
if (mdc.getUnits().contains(unit)) { | ||
return true; | ||
}else { | ||
return false; | ||
} | ||
} | ||
} | ||
//couldn't find refid, no errors | ||
return true; | ||
} | ||
|
||
|
||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/gov/nist/hit/pcd/custom/model/MDCUnitsterm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package gov.nist.hit.pcd.custom.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class MDCUnitsterm { | ||
|
||
private List<String> units; | ||
private String refid; | ||
|
||
|
||
|
||
public MDCUnitsterm(String[] refAndunits) { | ||
refid = refAndunits[0]; | ||
units = new ArrayList<>(Arrays.asList(refAndunits)); | ||
units.remove(0); | ||
} | ||
|
||
|
||
public MDCUnitsterm(String refid,List<String> units) { | ||
super(); | ||
this.units = units; | ||
this.refid = refid; | ||
} | ||
|
||
|
||
public List<String> getUnits() { | ||
return units; | ||
} | ||
|
||
|
||
public void setUnits(List<String> units) { | ||
this.units = units; | ||
} | ||
|
||
|
||
public String getRefid() { | ||
return refid; | ||
} | ||
|
||
|
||
public void setRefid(String refid) { | ||
this.refid = refid; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
Oops, something went wrong.