diff --git a/sql/create_ALLERGYINTOLERANCE_table.sql b/sql/create_ALLERGYINTOLERANCE_table.sql new file mode 100644 index 0000000..36e8910 --- /dev/null +++ b/sql/create_ALLERGYINTOLERANCE_table.sql @@ -0,0 +1,11 @@ +CREATE TABLE `HealthPort`.`ALLERGYINTOLERANCE` ( + `ID` VARCHAR(255) NOT NULL, + `DISPLAY` TEXT NULL, + `SUBSTANCE` VARCHAR(255) NULL, + `SUBJECT` TEXT NULL, + `SENSITIVITY_TYPE` TEXT NULL, + `RECORDED_DATE` DATE NULL, + `REACTION` TEXT NULL, + `CRITICALITY` TEXT NULL, + `STATUS` TEXT NULL, + PRIMARY KEY (`ID`)); \ No newline at end of file diff --git a/sql/create_SUBSTANCE_table.sql b/sql/create_SUBSTANCE_table.sql new file mode 100644 index 0000000..d7943f5 --- /dev/null +++ b/sql/create_SUBSTANCE_table.sql @@ -0,0 +1,10 @@ +CREATE TABLE `HealthPort`.`SUBSTANCE` ( + `ID` VARCHAR(255) NOT NULL, + `NAME` TEXT NULL, + `TYPE_SYSTEM` TEXT NULL, + `TYPE_CODE` TEXT NULL, + `TYPE_DISPLAY` TEXT NULL, + `EXTENSION_SYSTEM` TEXT NULL, + `EXTENSION_CODE` TEXT NULL, + `EXTENSION_DISPLAY` TEXT NULL, + PRIMARY KEY (`ID`)); \ No newline at end of file diff --git a/src/edu/gatech/i3l/HealthPort/AllergyIntoleranceSerializable.java b/src/edu/gatech/i3l/HealthPort/AllergyIntoleranceSerializable.java new file mode 100644 index 0000000..b354f67 --- /dev/null +++ b/src/edu/gatech/i3l/HealthPort/AllergyIntoleranceSerializable.java @@ -0,0 +1,36 @@ +package edu.gatech.i3l.HealthPort; + +import java.io.Serializable; + +/** + * Bean for AllergyIntolerance data. + * @author Eric Wallace + */ +public class AllergyIntoleranceSerializable implements Serializable { + private static final long serialVersionUID = 1L; + + public String ID; + public String DISPLAY; + public String SUBSTANCE; + public String SUBJECT; + public String SENSITIVITY_TYPE; + public java.util.Date RECORDED_DATE; + public String REACTION; + public String CRITICALITY; + public String STATUS; + + public AllergyIntoleranceSerializable() {}; + + public AllergyIntoleranceSerializable(String id, String display, String substId, String subj, + String sensitivity, java.util.Date recDate, String reaction, String criticality, String status) { + this.ID = id; + this.DISPLAY = display; + this.SUBSTANCE = substId; + this.SUBJECT = subj; + this.SENSITIVITY_TYPE = sensitivity; + this.RECORDED_DATE = recDate; + this.REACTION = reaction; + this.CRITICALITY = criticality; + this.STATUS = status; + } +} \ No newline at end of file diff --git a/src/edu/gatech/i3l/HealthPort/HealthPortInfo.java b/src/edu/gatech/i3l/HealthPort/HealthPortInfo.java index ba7edef..744d8d1 100644 --- a/src/edu/gatech/i3l/HealthPort/HealthPortInfo.java +++ b/src/edu/gatech/i3l/HealthPort/HealthPortInfo.java @@ -24,26 +24,36 @@ import org.apache.commons.lang3.StringEscapeUtils; +import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu.composite.CodingDt; import ca.uhn.fhir.model.dstu.composite.ContainedDt; +import ca.uhn.fhir.model.dstu.composite.NarrativeDt; import ca.uhn.fhir.model.dstu.composite.QuantityDt; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; +import ca.uhn.fhir.model.dstu.resource.AdverseReaction; +import ca.uhn.fhir.model.dstu.resource.AdverseReaction.Symptom; +import ca.uhn.fhir.model.dstu.resource.AllergyIntolerance; import ca.uhn.fhir.model.dstu.resource.Condition; import ca.uhn.fhir.model.dstu.resource.Medication; import ca.uhn.fhir.model.dstu.resource.MedicationPrescription; import ca.uhn.fhir.model.dstu.resource.Observation; import ca.uhn.fhir.model.dstu.resource.MedicationPrescription.Dispense; import ca.uhn.fhir.model.dstu.resource.MedicationPrescription.DosageInstruction; +import ca.uhn.fhir.model.dstu.resource.Substance; import ca.uhn.fhir.model.dstu.valueset.ConditionStatusEnum; +import ca.uhn.fhir.model.dstu.valueset.CriticalityEnum; import ca.uhn.fhir.model.dstu.valueset.MedicationPrescriptionStatusEnum; import ca.uhn.fhir.model.dstu.valueset.NarrativeStatusEnum; import ca.uhn.fhir.model.dstu.valueset.ObservationReliabilityEnum; import ca.uhn.fhir.model.dstu.valueset.ObservationStatusEnum; +import ca.uhn.fhir.model.dstu.valueset.SensitivityStatusEnum; +import ca.uhn.fhir.model.dstu.valueset.SensitivityTypeEnum; import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.StringDt; /** * @author Myung Choi Constructor requires UserID. - Connects to SQL database to @@ -64,6 +74,8 @@ public class HealthPortInfo { public static String OBSERVATION = "OBSERVATION"; public static String CONDITION = "CONDITIONS"; public static String MEDICATIONPRESCRIPTION = "MEDICATIONPRESCRIPTION"; + public static String ALLERGYINTOLERANCE = "ALLERGYINTOLERANCE"; + public static String SUBSTANCE = "SUBSTANCE"; private DataSource dataSource; @@ -202,6 +214,39 @@ public List getResourceIdsByCodeSystem(String tableName, return retVal; } + public List getResourceIdsBySubstance (String tableName, String substanceId) { + List retVal = new ArrayList(); + + Connection connection = null; + Statement statement = null; + + String SQL_STATEMENT = "SELECT ID FROM " + tableName + + " WHERE SUBSTANCE = 'Substance/" + substanceId + "'"; + + System.out.println ("HealthPortInfo: getResourceIdsBySubstance: "+tableName+" for Substance "+substanceId); + connection = getConnection(); + try { + statement = connection.createStatement(); + ResultSet rs = statement.executeQuery(SQL_STATEMENT); + + while (rs.next()) { + retVal.add(rs.getString("ID")); + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + } + + System.out.println ("HealthPortInfo: getResourceIdsBySubstance: Done"); + + return retVal; + } + public List getAllResourceIds(String tableName) { List retVal = new ArrayList(); @@ -349,7 +394,54 @@ public static void storeResource(String tableName, Object obj0) pstmt.executeUpdate(); pstmt.clearParameters(); pstmt.close(); + } else if (tableName.equals(ALLERGYINTOLERANCE)) { + AllergyIntoleranceSerializable obj = (AllergyIntoleranceSerializable) obj0; + SQL_STATEMENT = "REPLACE INTO " + tableName + + " (ID, DISPLAY, SUBSTANCE, SUBJECT, SENSITIVITY_TYPE," + + " RECORDED_DATE, REACTION, CRITICALITY, STATUS) VALUES" + + " (?, ?, ?, ?, ?, ?, ?, ?, ?)"; + PreparedStatement pstmt = connection.prepareStatement(SQL_STATEMENT); + + // set input parameters + pstmt.setString(1, obj.ID); + pstmt.setString(2, obj.DISPLAY); + pstmt.setString(3, obj.SUBSTANCE); + pstmt.setString(4, "Patient/" + obj.SUBJECT); + pstmt.setString(5, obj.SENSITIVITY_TYPE); + if (obj.RECORDED_DATE != null) { + Timestamp ts = new Timestamp(obj.RECORDED_DATE.getTime()); + pstmt.setTimestamp(6, ts); + } else { + pstmt.setTimestamp(6, null); + } + pstmt.setString(7, obj.REACTION); + pstmt.setString(8, obj.CRITICALITY); + pstmt.setString(9, obj.STATUS); + + pstmt.executeUpdate(); + pstmt.clearParameters(); + pstmt.close(); + } else if (tableName.equals(SUBSTANCE)) { + SubstanceSerializable obj = (SubstanceSerializable) obj0; + SQL_STATEMENT = "REPLACE INTO " + tableName + + " (ID, NAME, TYPE_SYSTEM, TYPE_CODE, TYPE_DISPLAY," + + " EXTENSION_SYSTEM, EXTENSION_CODE, EXTENSION_DISPLAY) VALUES" + + " (?, ?, ?, ?, ?, ?, ?, ?)"; + PreparedStatement pstmt = connection.prepareStatement(SQL_STATEMENT); + // set input parameters + pstmt.setString(1, obj.ID); + pstmt.setString(2, obj.NAME); + pstmt.setString(3, obj.TYPE_SYSTEM); + pstmt.setString(4, obj.TYPE_CODE); + pstmt.setString(5, obj.TYPE_DISPLAY); + pstmt.setString(6, obj.EXTENSION_SYSTEM); + pstmt.setString(7, obj.EXTENSION_CODE); + pstmt.setString(8, obj.EXTENSION_DISPLAY); + + pstmt.executeUpdate(); + pstmt.clearParameters(); + pstmt.close(); } } catch (NamingException | SQLException e) { e.printStackTrace(); @@ -703,6 +795,118 @@ else if (textStatus.equalsIgnoreCase("EXTENSIONS")) NarrativeStatusEnum.EXTENSIONS); } retVal.add(medicationPrescript); + } else if (tableName.equals(ALLERGYINTOLERANCE)) { + String id = rs.getString("ID"); + String display = rs.getString("DISPLAY"); + String substId = rs.getString("SUBSTANCE"); + String subject = rs.getString("SUBJECT"); + String sensitivity = rs.getString("SENSITIVITY_TYPE"); + Timestamp rdateTS = rs.getTimestamp("RECORDED_DATE"); + String reactionText = rs.getString("REACTION"); + String criticality = rs.getString("CRITICALITY"); + String status = rs.getString("STATUS"); + + AllergyIntolerance allergy = new AllergyIntolerance(); + + // set ID + allergy.setId(id); + + // set Text + NarrativeDt text = new NarrativeDt(); + text.setDiv(display); + allergy.setText(text); + + // set Subject as reference to Patient + ResourceReferenceDt subj = new ResourceReferenceDt(subject); + allergy.setSubject(subj); + + // set Substance - reference + allergy.setSubstance(new ResourceReferenceDt(substId)); + + // set Type - valueset http://www.hl7.org/implement/standards/fhir/sensitivitytype.html + if (sensitivity.matches("(?i:allergy|drug|immunization)")) + allergy.setSensitivityType(SensitivityTypeEnum.ALLERGY); + else if (sensitivity.matches("(?i:intolerance|sensitivity")) + allergy.setSensitivityType(SensitivityTypeEnum.INTOLERANCE); + else + allergy.setSensitivityType(SensitivityTypeEnum.UNKNOWN); + + // set Recoded Date + java.util.Date rDate = null; + if (rdateTS != null) + rDate = new Date(rdateTS.getTime()); + if (rDate != null) + allergy.setRecordedDate(new DateTimeDt(rDate)); + + // set Reaction - resource AdverseReaction.symptom + AdverseReaction reactionObj = new AdverseReaction(); + reactionObj.setSubject(subj); + Symptom symptom = new Symptom(); + CodeableConceptDt sympCode = new CodeableConceptDt(); + sympCode.setText(reactionText); // not enough info to fill out code + symptom.setCode(sympCode); + ArrayList sympList = new ArrayList(); + sympList.add(symptom); + reactionObj.setSymptom(sympList); + + // set Criticality - valueset http://www.hl7.org/implement/standards/fhir/criticality.html + if (criticality.matches("(?i:mild|low)")) + allergy.setCriticality(CriticalityEnum.LOW); + else if (criticality.matches("(?i:moderate|medium)")) + allergy.setCriticality(CriticalityEnum.MEDIUM); + else if (criticality.matches("(?i:severe|high)")) + allergy.setCriticality(CriticalityEnum.HIGH); + else if (criticality.matches("(?i:critical|fatal)")) + allergy.setCriticality(CriticalityEnum.FATAL); + + // set Status - valueset http://www.hl7.org/implement/standards/fhir/sensitivitystatus.html + if (status.matches("(?i:suspected)")) + allergy.setStatus(SensitivityStatusEnum.SUSPECTED); + else if (status.matches("(?i:confirmed)")) + allergy.setStatus(SensitivityStatusEnum.CONFIRMED); + else if (status.matches("(?i:refuted)")) + allergy.setStatus(SensitivityStatusEnum.REFUTED); + else if (status.matches("(?i:resolved)")) + allergy.setStatus(SensitivityStatusEnum.RESOLVED); + + retVal.add(allergy); + } else if (tableName.equals(SUBSTANCE)) { + String id = rs.getString("ID"); + String name = rs.getString("NAME"); + String typeSystem = rs.getString("TYPE_SYSTEM"); + String typeCode = rs.getString("TYPE_CODE"); + String typeDisp = rs.getString("TYPE_DISPLAY"); + String extSystem = rs.getString("EXTENSION_SYSTEM"); + String extCode = rs.getString("EXTENSION_CODE"); + String extDisp = rs.getString("EXTENSION_DISPLAY"); + + Substance subst = new Substance(); + + // set ID + subst.setId(id); + + // set Name + name = StringEscapeUtils.escapeHtml4(name); + subst.setDescription(name); + + // set Type + //subst.setType(SubstanceTypeEnum.VALUESET_BINDER.fromCodeString(typeCode, typeSystem)); + CodingDt typeCoding = new CodingDt(); + typeCoding.setValueSet(new ResourceReferenceDt("http://hl7.org/fhir/vs/substance-type")); + typeCoding.setSystem(typeSystem); + typeCoding.setCode(typeCode); + typeCoding.setDisplay(typeDisp); + ArrayList codingList = new ArrayList(); + codingList.add(typeCoding); + subst.getType().setCoding(codingList); + + // add Extension + if (!extSystem.equals("") && !extCode.equals("")) { + ExtensionDt ext = new ExtensionDt(false, extSystem, new StringDt(extCode)); + subst.addUndeclaredExtension(ext); + } + + retVal.add(subst); } } } diff --git a/src/edu/gatech/i3l/HealthPort/RestfulServlet.java b/src/edu/gatech/i3l/HealthPort/RestfulServlet.java index b69d1cf..4be3b23 100644 --- a/src/edu/gatech/i3l/HealthPort/RestfulServlet.java +++ b/src/edu/gatech/i3l/HealthPort/RestfulServlet.java @@ -9,10 +9,12 @@ import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import edu.gatech.i3l.HealthPort.providers.AllergyIntoleranceResourceProvider; import edu.gatech.i3l.HealthPort.providers.ConditionResourceProvider; import edu.gatech.i3l.HealthPort.providers.MedicationPrescrResource; import edu.gatech.i3l.HealthPort.providers.ObservationResourceProvider; import edu.gatech.i3l.HealthPort.providers.PatientResourceProvider; +import edu.gatech.i3l.HealthPort.providers.SubstanceResourceProvider; import org.slf4j.LoggerFactory; @@ -63,6 +65,8 @@ protected void initialize() throws ServletException { resourceProviders.add(new ObservationResourceProvider()); resourceProviders.add(new ConditionResourceProvider()); resourceProviders.add(new MedicationPrescrResource()); + resourceProviders.add(new AllergyIntoleranceResourceProvider()); + resourceProviders.add(new SubstanceResourceProvider()); setResourceProviders(resourceProviders); // /* diff --git a/src/edu/gatech/i3l/HealthPort/SubstanceSerializable.java b/src/edu/gatech/i3l/HealthPort/SubstanceSerializable.java new file mode 100644 index 0000000..2865eb2 --- /dev/null +++ b/src/edu/gatech/i3l/HealthPort/SubstanceSerializable.java @@ -0,0 +1,35 @@ +package edu.gatech.i3l.HealthPort; + +import java.io.Serializable; + +/** + * Bean for Substance data. + * @author Eric Wallace + */ +public class SubstanceSerializable implements Serializable { + private static final long serialVersionUID = 1L; + + public String ID; + public String NAME; + public String TYPE_SYSTEM; + public String TYPE_CODE; + public String TYPE_DISPLAY; + public String EXTENSION_SYSTEM; + public String EXTENSION_CODE; + public String EXTENSION_DISPLAY; + + public SubstanceSerializable() {}; + + public SubstanceSerializable(String id, String name, + String typeSystem, String typeCode, String typeDisp, + String extSystem, String extCode, String extDisp) { + this.ID = id; + this.NAME = name; + this.TYPE_SYSTEM = typeSystem; + this.TYPE_CODE = typeCode; + this.TYPE_DISPLAY = typeDisp; + this.EXTENSION_SYSTEM = extSystem; + this.EXTENSION_CODE = extCode; + this.EXTENSION_DISPLAY = extDisp; + } +} \ No newline at end of file diff --git a/src/edu/gatech/i3l/HealthPort/UpdateFHIRdB.java b/src/edu/gatech/i3l/HealthPort/UpdateFHIRdB.java index 1cc1a73..8ddbfb2 100644 --- a/src/edu/gatech/i3l/HealthPort/UpdateFHIRdB.java +++ b/src/edu/gatech/i3l/HealthPort/UpdateFHIRdB.java @@ -167,6 +167,10 @@ protected void doGet(HttpServletRequest request, e.printStackTrace(); } } + } else if (res.equalsIgnoreCase(HealthPortInfo.ALLERGYINTOLERANCE)) { + // only ExactDataPort implemented at this time + syntheticEHRPort.getAllergyIntolerances(); + syntheticCancerPort.getAllergyIntolerances(); } } diff --git a/src/edu/gatech/i3l/HealthPort/ports/ExactDataPort.java b/src/edu/gatech/i3l/HealthPort/ports/ExactDataPort.java index 3beb239..ac61023 100644 --- a/src/edu/gatech/i3l/HealthPort/ports/ExactDataPort.java +++ b/src/edu/gatech/i3l/HealthPort/ports/ExactDataPort.java @@ -3,6 +3,8 @@ */ package edu.gatech.i3l.HealthPort.ports; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -10,6 +12,7 @@ import java.sql.Timestamp; import java.util.ArrayList; import java.sql.Date; +import java.text.SimpleDateFormat; import java.util.List; import javax.naming.InitialContext; @@ -38,11 +41,13 @@ import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.IdDt; +import edu.gatech.i3l.HealthPort.AllergyIntoleranceSerializable; import edu.gatech.i3l.HealthPort.ConditionSerializable; import edu.gatech.i3l.HealthPort.HealthPortInfo; import edu.gatech.i3l.HealthPort.MedicationPrescriptionSerializable; import edu.gatech.i3l.HealthPort.ObservationSerializable; import edu.gatech.i3l.HealthPort.PortIf; +import edu.gatech.i3l.HealthPort.SubstanceSerializable; /** * @author MC142 @@ -1448,7 +1453,145 @@ public List getMedicationPrescriptions() { } return retVal; } + + // get all available AllergyIntolerance ids, stored in HealthPort DB as a side-effect + public List getAllergyIntolerances() { + List retVal = new ArrayList(); + + Connection conn = null; + Statement stmt = null; + try { + conn = dataSource.getConnection(); + stmt = conn.createStatement(); + String sql = "SELECT * FROM allergy"; + ResultSet rs = stmt.executeQuery(sql); + List allergyList = getAllergyIntoleranceIds(rs); + if (allergyList != null && !allergyList.isEmpty()) { + retVal.addAll(allergyList); + } + conn.close(); + } catch (SQLException se) { + se.printStackTrace(); + } + return retVal; + } + + // get AllergyIntolerances ids from a ResultSet, storing them in HealthPort DB as a side-effect + public List getAllergyIntoleranceIds(ResultSet rs) { + List retVal = new ArrayList(); + AllergyIntoleranceSerializable allergy = null; + try { + while (rs.next()) { + String memberID = rs.getString("Member_ID"); + if (memberID.isEmpty()) + continue; + + // 1) create Substance + + /* SubstanceType is a SNOMED-CT code from concept is-a 105590001 or 373873005 + * see http://www.hl7.org/implement/standards/fhir/valueset-substance-type.html + * + * ExactData allergy tables appear to include only drugs & immunization allergies + */ + + String substId = null; + if (rs.getString("Allergy_Type").equalsIgnoreCase("drug")) { + + String name = rs.getString("Allergen"); + + final String typeSystem = "http://snomed.info/sct"; + final String typeCode = "410942007"; + final String typeDisp = "Drug or medicament"; + + /* ExactData tables contain RxNorm (drug) or CVX (immunization) codes + * Currently, FHIR Substance resources don't include these codeable concepts + * ...but we can add them as a custom extension + */ + String extSystem = ""; + String extCode = ""; + String extDisp = ""; + if (rs.getString("Drug_Vocab").equalsIgnoreCase("RxNorm")) { + // see http://hl7.org/implement/standards/fhir/2015Jan/rxnorm.html + extSystem = "http://www.nlm.nih.gov/research/umls/rxnorm"; + extCode = rs.getString("Drug_Code"); + extDisp = StringEscapeUtils.escapeHtml4(name); + } else if (rs.getString("Drug_Vocab").equalsIgnoreCase("CVX")) { + // see http://hl7.org/implement/standards/fhir/2015Jan/cvx.html + //extSystem = "http://hl7.org/fhir/v2/0292"; + extSystem = "http://www2a.cdc.gov/vaccines/iis/iisstandards/vaccines.asp?rpt=cvx"; + extCode = rs.getString("Drug_Code"); + extDisp = StringEscapeUtils.escapeHtml4(name); + } + + /* prep substId as a composite + * built from type sytem & code, extension system & code + */ + substId = "SCT." + typeCode + "." + rs.getString("Drug_Vocab") + "." + extCode; + try { substId = URLEncoder.encode(substId, "UTF-8"); } + catch (UnsupportedEncodingException uee) { }; + + SubstanceSerializable substSz = new SubstanceSerializable( + substId, + name, + typeSystem, + typeCode, + typeDisp, + extSystem, + extCode, + extDisp + ); + + // store this Substance in HealthPort DB + HealthPortInfo.storeResource(HealthPortInfo.SUBSTANCE, substSz); + } + + // 2) create Allergy + + // prep date + java.util.Date recDate = null; + Timestamp ts = rs.getTimestamp("Onset_Date"); + if (ts != null) { + recDate = new java.util.Date(ts.getTime()); + } + final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + /* prep allergyId - ExactData's allergy tables do not have ids, so we must create our own + * built from Member_ID + Allergen + Onset_Date + */ + String allergyId = rs.getString("Member_ID") + "." + + rs.getString("Allergen") + "." + + sdf.format(recDate); + try { allergyId = URLEncoder.encode(allergyId, "UTF-8"); } + catch (UnsupportedEncodingException uee) { }; + + // prep Status - set to "suspected" if ExactData's allergy.Information_Source is "patient" + String status = rs.getString("Information_Source").equalsIgnoreCase("patient") ? "suspected" : null; + + allergy = new AllergyIntoleranceSerializable( + allergyId, + rs.getString("Allergen"), + "Substance/" + substId, + rs.getString("Member_ID"), + rs.getString("Allergy_Type"), + recDate, + rs.getString("Reaction"), + rs.getString("Severity_Description"), + status + ); + + // store this AllergyIntolerance in HealthPort DB + HealthPortInfo.storeResource(HealthPortInfo.ALLERGYINTOLERANCE, allergy); + + retVal.add(allergyId); + } + } catch (SQLException e) { + e.printStackTrace(); + } + + return retVal; + } + /* * (non-Javadoc) * diff --git a/src/edu/gatech/i3l/HealthPort/providers/AllergyIntoleranceResourceProvider.java b/src/edu/gatech/i3l/HealthPort/providers/AllergyIntoleranceResourceProvider.java new file mode 100644 index 0000000..7882853 --- /dev/null +++ b/src/edu/gatech/i3l/HealthPort/providers/AllergyIntoleranceResourceProvider.java @@ -0,0 +1,187 @@ +package edu.gatech.i3l.HealthPort.providers; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu.resource.AllergyIntolerance; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.param.ReferenceParam; +import ca.uhn.fhir.rest.server.IBundleProvider; +import ca.uhn.fhir.rest.server.IResourceProvider; +import edu.gatech.i3l.HealthPort.HealthPortInfo; + +/** + * Retrieve AllergyIntolerance data as HAPI-FHIR resource objects. + * @author Eric Wallace + */ +public class AllergyIntoleranceResourceProvider implements IResourceProvider { + private HealthPortInfo healthPortUser; + + public AllergyIntoleranceResourceProvider() { + healthPortUser = new HealthPortInfo("jdbc/HealthPort"); + } + + /* (non-Javadoc) + * @see ca.uhn.fhir.rest.server.IResourceProvider#getResourceType() + */ + @Override + public Class getResourceType() { + return AllergyIntolerance.class; + } + + /** + * Given a single resource ID, retrieve that AllergyIntolerance resource. + * @param theId + * @return an AllergyIntolerance object + */ + @Read() + public AllergyIntolerance getResourceById(@IdParam IdDt theId) { + ListIds = new ArrayList(); + Ids.add(theId.getIdPart()); + + List resourceList = null; + try { + resourceList = healthPortUser.getResourceList(HealthPortInfo.ALLERGYINTOLERANCE, Ids); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + + if (resourceList == null || resourceList.isEmpty()) return null; + return (AllergyIntolerance) resourceList.get(0); + } + + /** + * Retrieve all available AllergyIntolerance resources. + * @return a Bundle of AllergyIntolerance objects + */ + @Search + public IBundleProvider getAllAllergyIntolerances() { + final InstantDt searchTime = InstantDt.withCurrentTime(); + final List matchingResourceIds = healthPortUser + .getAllResourceIds(HealthPortInfo.ALLERGYINTOLERANCE); + + return new IBundleProvider() { + + @Override + public int size() { + return matchingResourceIds.size(); + } + + @Override + public List getResources(int theFromIndex, int theToIndex) { + int end = Math.min(theToIndex, matchingResourceIds.size()); + // System.out.println("From:"+theFromIndex+" To:"+theToIndex+" Total:"+matchingResourceIds.size()); + List idsToReturn = matchingResourceIds.subList(theFromIndex, end); + List retVal = null; + try { + retVal = healthPortUser.getResourceList(HealthPortInfo.ALLERGYINTOLERANCE, idsToReturn); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + + return retVal; + } + + @Override + public InstantDt getPublished() { + return searchTime; + } + }; + } + + /** + * Retrieve all available AllergyIntolerances associated with a patient. + * @param theSubject a Patient object + * @return a Bundle of AllergyIntolerance objects + */ + @Search() + public IBundleProvider getAllergyIntolerancesByPatient( + @RequiredParam(name = AllergyIntolerance.SP_SUBJECT) ReferenceParam theSubject) { + + final InstantDt searchTime = InstantDt.withCurrentTime(); + String patientID = theSubject.getIdPart(); + + final List matchingResourceIds = healthPortUser + .getResourceIdsByPatient(HealthPortInfo.ALLERGYINTOLERANCE, patientID); + + return new IBundleProvider() { + + @Override + public int size() { + return matchingResourceIds.size(); + } + + @Override + public List getResources(int theFromIndex, int theToIndex) { + int end = Math.min(theToIndex, matchingResourceIds.size()); + // System.out.println("From:"+theFromIndex+" To:"+theToIndex+" Total:"+matchingResourceIds.size()); + List idsToReturn = matchingResourceIds.subList(theFromIndex, end); + + List retVal = null; + try { + retVal = healthPortUser.getResourceList(HealthPortInfo.ALLERGYINTOLERANCE,idsToReturn); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + return retVal; + } + + @Override + public InstantDt getPublished() { + return searchTime; + } + }; + } + + /** + * Retrieve all available AllergyIntolerances associated with a Substance. + * @param theSubstance a Substance object + * @return a Bundle of AllergyIntolerance objects + */ + @Search() + public IBundleProvider getAllergyIntolerancesBySubstance( + @RequiredParam(name = AllergyIntolerance.SP_SUBSTANCE) ReferenceParam theSubstance) { + + final InstantDt searchTime = InstantDt.withCurrentTime(); + String substanceID = theSubstance.getIdPart(); + + final List matchingResourceIds = healthPortUser + .getResourceIdsBySubstance(HealthPortInfo.ALLERGYINTOLERANCE, substanceID); + + return new IBundleProvider() { + + @Override + public int size() { + return matchingResourceIds.size(); + } + + @Override + public List getResources(int theFromIndex, int theToIndex) { + int end = Math.min(theToIndex, matchingResourceIds.size()); + // System.out.println("From:"+theFromIndex+" To:"+theToIndex+" Total:"+matchingResourceIds.size()); + List idsToReturn = matchingResourceIds.subList(theFromIndex, end); + + List retVal = null; + try { + retVal = healthPortUser.getResourceList(HealthPortInfo.ALLERGYINTOLERANCE,idsToReturn); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + return retVal; + } + + @Override + public InstantDt getPublished() { + return searchTime; + } + }; + } + +} diff --git a/src/edu/gatech/i3l/HealthPort/providers/SubstanceResourceProvider.java b/src/edu/gatech/i3l/HealthPort/providers/SubstanceResourceProvider.java new file mode 100644 index 0000000..be5bdc2 --- /dev/null +++ b/src/edu/gatech/i3l/HealthPort/providers/SubstanceResourceProvider.java @@ -0,0 +1,97 @@ +package edu.gatech.i3l.HealthPort.providers; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu.resource.Substance; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.server.IBundleProvider; +import ca.uhn.fhir.rest.server.IResourceProvider; +import edu.gatech.i3l.HealthPort.HealthPortInfo; + +/** + * Retrieve Substance data as HAPI-FHIR resource objects. + * @author Eric Wallace + */ +public class SubstanceResourceProvider implements IResourceProvider { + private HealthPortInfo healthPortUser; + + public SubstanceResourceProvider() { + healthPortUser = new HealthPortInfo("jdbc/HealthPort"); + } + + /* (non-Javadoc) + * @see ca.uhn.fhir.rest.server.IResourceProvider#getResourceType() + */ + @Override + public Class getResourceType() { + return Substance.class; + } + + /** + * Given a single resource ID, retrieve that Substance resource. + * @param theId + * @return an Substance object + */ + @Read() + public Substance getResourceById(@IdParam IdDt theId) { + ListIds = new ArrayList(); + Ids.add(theId.getIdPart()); + + List resourceList = null; + try { + resourceList = healthPortUser.getResourceList(HealthPortInfo.SUBSTANCE, Ids); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + + if (resourceList == null || resourceList.isEmpty()) return null; + return (Substance) resourceList.get(0); + } + + /** + * Retrieve all available Substance resources. + * @return a Bundle of Substance objects + */ + @Search + public IBundleProvider getAllSubstances() { + final InstantDt searchTime = InstantDt.withCurrentTime(); + final List matchingResourceIds = healthPortUser + .getAllResourceIds(HealthPortInfo.SUBSTANCE); + + return new IBundleProvider() { + + @Override + public int size() { + return matchingResourceIds.size(); + } + + @Override + public List getResources(int theFromIndex, int theToIndex) { + int end = Math.min(theToIndex, matchingResourceIds.size()); + // System.out.println("From:"+theFromIndex+" To:"+theToIndex+" Total:"+matchingResourceIds.size()); + List idsToReturn = matchingResourceIds.subList(theFromIndex, end); + List retVal = null; + try { + retVal = healthPortUser.getResourceList(HealthPortInfo.SUBSTANCE, idsToReturn); + } catch (SQLException e) { + e.printStackTrace(); // TODO Auto-generated catch block + } + + return retVal; + } + + @Override + public InstantDt getPublished() { + return searchTime; + } + }; + } + +}