diff --git a/pom.xml b/pom.xml index 1c37258..e0f1025 100755 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ com.rabbitmq amqp-client - 5.2.0 + 5.4.0 diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/Mimic2Fhir.java b/src/main/java/de.uzl.itcr/mimic2fhir/Mimic2Fhir.java deleted file mode 100755 index a4497b2..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/Mimic2Fhir.java +++ /dev/null @@ -1,408 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir; - -import java.util.HashMap; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonObject; - -import org.hl7.fhir.dstu3.model.Condition; -import org.hl7.fhir.dstu3.model.Encounter; -import org.hl7.fhir.dstu3.model.Location; -import org.hl7.fhir.dstu3.model.Medication; -import org.hl7.fhir.dstu3.model.MedicationAdministration; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.dstu3.model.Organization; -import org.hl7.fhir.dstu3.model.Patient; -import org.hl7.fhir.dstu3.model.Period; -import org.hl7.fhir.dstu3.model.Practitioner; -import org.hl7.fhir.dstu3.model.PractitionerRole; -import org.hl7.fhir.dstu3.model.Procedure; -import org.hl7.fhir.dstu3.model.Reference; - -import ca.uhn.fhir.model.primitive.IdDt; -import de.uzl.itcr.mimic2fhir.model.MAdmission; -import de.uzl.itcr.mimic2fhir.model.MCaregiver; -import de.uzl.itcr.mimic2fhir.model.MPatient; -import de.uzl.itcr.mimic2fhir.model.MTransfer; -import de.uzl.itcr.mimic2fhir.model.MWard; -import de.uzl.itcr.mimic2fhir.queue.Receiver; -import de.uzl.itcr.mimic2fhir.queue.Sender; -import de.uzl.itcr.mimic2fhir.work.BundleControl; -import de.uzl.itcr.mimic2fhir.work.Config; -import de.uzl.itcr.mimic2fhir.work.ConnectDB; -import de.uzl.itcr.mimic2fhir.work.FHIRComm; - -/** - * Application for transforming data from mimiciii to fhir - * @author Stefanie Ververs - * - */ -public class Mimic2Fhir { - //Config-Object - private Config config; - - private OutputMode outputMode; - private int topPatients; - - private ConnectDB dbAccess; - private FHIRComm fhir; - private HashMap caregivers; - private HashMap locations; - - private HashMap locationsInBundle; - private HashMap caregiversInBundle; - private HashMap medicationInBundle; - - private Organization hospital; - private BundleControl bundleC; - - private Sender sendr; - - - public Config getConfig() { - return config; - } - - /** - * Set Configuration Object for App - * @param config Config-Object - */ - public void setConfig(Config config) { - this.config = config; - } - - /** - * Set Application output mode - * @param modus (Write to file, load to server..) - */ - public void setOutputMode(OutputMode modus) { - this.outputMode = modus; - } - - /** - * Set Number of Patients to load (first x patients in db); 0 if all - * Works only with "all patients" import mode - * @param topPatients number of patients to load - */ - public void setTopPatients(int topPatients) { - this.topPatients = topPatients; - } - - /** - * Start transformation - */ - public void start() { - //Connection to mimic postgres DB - dbAccess = new ConnectDB(config); - - //Preload Caregivers - caregivers = dbAccess.getCaregivers(); - - //Preload Wards - locations = dbAccess.getLocations(); - - //initialize memoryLists of locations and caregivers and medication (-> conditional creates, each resource only once in bundle) - locationsInBundle = new HashMap(); - caregiversInBundle = new HashMap(); - medicationInBundle = new HashMap(); - - //Preload Hospital - hospital = createTopHospital(); - - //Fhir-Communication and Resource-Bundle-Stuff - fhir = new FHIRComm(config); - bundleC = new BundleControl(); - - int numberOfAllPatients = 0; - if(topPatients == 0) { //all Patients - numberOfAllPatients = dbAccess.getNumberOfPatients(); - } - else { - numberOfAllPatients = topPatients; - } - - //Sender for sending bundle messages to queue - sendr = new Sender(); - - //Start Message-Receiver (handles bundle operations) - Receiver r = new Receiver(); - r.setFhirConnector(fhir); - r.setOutputMode(outputMode); - r.receive(); - - //loop all patients.. - for(int i = 1; i<= numberOfAllPatients; i++) { - MPatient mimicPat2 = dbAccess.getPatientByRowId(i); - processPatient(mimicPat2, i); - } - - //Push end-Message to queue - JsonObject message = Json.createObjectBuilder() - .add("number", "0") - .add("bundle", "END") - .build(); - - sendr.send(message.toString()); - - //close connection to queue - sendr.close(); - } - - private void resetMemoryLists() { - caregiversInBundle.clear(); - locationsInBundle.clear(); - medicationInBundle.clear(); - } - - private void processPatient(MPatient mimicPat, int numPat) { - //Fill FHIR-Structure - Patient fhirPat = mimicPat.createFhirFromMimic(); - String patNumber; - int admissionIndex = 0; - - //All admissions of one patient - for(MAdmission admission : mimicPat.getAdmissions()) { - - //First: Load/create fhir resources - Encounter enc = admission.createFhirEncounterFromMimic(fhirPat.getId()); - - //create Conditions per Admission - List conditions = admission.createFhirConditionsFromMimic(fhirPat.getId()); - - //create Procedures per Admission - List procedures = admission.createFhirProceduresFromMimic(fhirPat.getId()); - - //create List Of Medication & MedicationAdministrations - List medications = admission.createFhirMedicationsFromMimic(); - List prescriptions = admission.createFhirMedAdminsFromMimic(fhirPat.getId(), enc.getId()); - - //create Observations per Admission - List obs = admission.createFhirObservationsFromMimic(fhirPat.getId(), enc.getId()); - //create Observation from Labevents - List obsLab = admission.createFhirLabObservationsFromMimic(fhirPat.getId(), enc.getId()); - //create Observation from Noteevents - List obsNotes = admission.createFhirNoteObservationsFromMimic(fhirPat.getId(), enc.getId()); - - //create bundle without observations and medication: - createBasicBundle(fhirPat, admission, enc, conditions, procedures); - - //Medication only in first bundle of admission - //Prescriptions - for(Medication med : medications) { - String identifier = med.getCode().getCodingFirstRep().getCode(); - if(!medicationInBundle.containsKey(identifier)) - { - bundleC.addUUIDResourceWithConditionToBundle(med, "code=" + med.getCode().getCodingFirstRep().getCode()); - medicationInBundle.put(identifier, med.getId()); - } - } - - //..and MedicationAdministrations (with correct Medication as Reference) - for(MedicationAdministration madm : prescriptions) { - String identifier = medications.get(prescriptions.indexOf(madm)).getCode().getCodingFirstRep().getCode(); - String medId = medicationInBundle.get(identifier); - madm.setMedication(new Reference(medId)); - - bundleC.addUUIDResourceToBundle(madm); - } - - //Identification - admissionIndex++; - patNumber = numPat + "_" + admissionIndex; - - //add observations to bundle - for(Observation o : obs) { - //check if bundle is full - checkBundleLimit(patNumber, fhirPat, admission, enc, conditions, procedures); - - //get Caregiver for this event - int caregiverId = admission.getEvents().get(obs.indexOf(o)).getCareGiverId(); - if(caregiverId != 0) { - String pFhirId = processCaregiver(caregiverId); - - //Set caregiver-Reference -> Performer - o.addPerformer(new Reference(pFhirId)); - } - //Order important - these reference pat & encounter - bundleC.addResourceToBundle(o); - } - - - for(Observation o : obsLab) { - //check if bundle is full - checkBundleLimit(patNumber, fhirPat, admission, enc, conditions, procedures); - - bundleC.addResourceToBundle(o); - } - - for(Observation o : obsNotes) { - //check if bundle is full - checkBundleLimit(patNumber, fhirPat, admission, enc, conditions, procedures); - - //get Caregiver for this event - int caregiverId = admission.getNoteevents().get(obsNotes.indexOf(o)).getCaregiverId(); - if(caregiverId != 0) { - String pFhirId = processCaregiver(caregiverId); - - //Set caregiver-Reference -> Performer - o.addPerformer(new Reference(pFhirId)); - } - - bundleC.addResourceToBundle(o); - } - - - //Push bundle to queue - JsonObject message = Json.createObjectBuilder() - .add("number", patNumber + "_" + bundleC.getInternalBundleNumber()) - .add("bundle", fhir.getBundleAsString(bundleC.getTransactionBundle())) - .build(); - - sendr.send(message.toString()); - - //reset bundle and memory lists - bundleC.resetBundle(); - resetMemoryLists(); - - - } - bundleC.resetInternalBundleNumber(); - } - - private void checkBundleLimit(String numPat, Patient fhirPat, MAdmission admission, Encounter enc, - List conditions, List procedures) { - - //if bundle exceeds 15000 resources -> start new bundle - if(bundleC.getNumberOfResorces() > 15000) { - //Push bundle to queue - JsonObject message = Json.createObjectBuilder() - .add("number", numPat + "_" + bundleC.getInternalBundleNumber()) - .add("bundle", fhir.getBundleAsString(bundleC.getTransactionBundle())) - .build(); - - sendr.send(message.toString()); - - //reset bundle and memory lists - bundleC.resetBundle(); - resetMemoryLists(); - //reload basic bundle stuff - createBasicBundle(fhirPat, admission, enc, conditions, procedures); - } - } - - private void createBasicBundle(Patient fhirPat, MAdmission admission, Encounter enc, List conditions, - List procedures) { - - //Pat to bundle - bundleC.addUUIDResourceWithConditionToBundle(fhirPat, "identifier=" + fhirPat.getIdentifierFirstRep().getSystem() + "|" + fhirPat.getIdentifierFirstRep().getValue()); - - //Top of all: Hospital - bundleC.addUUIDResourceWithConditionToBundle(hospital, "identifier=" + hospital.getIdentifierFirstRep().getSystem() + "|" + hospital.getIdentifierFirstRep().getValue()); - - enc.getDiagnosis().clear(); //clear all procedures & diagnoses - - //Diagnoses - for(Condition c : conditions) { - int rank = admission.getDiagnoses().get(conditions.indexOf(c)).getSeqNumber(); - - //set Condition in enc.diagnosis - enc.addDiagnosis().setCondition(new Reference(c.getId())).setRank(rank); - - //add Condition to bundle - bundleC.addUUIDResourceWithConditionToBundle(c, "identifier=" + c.getIdentifierFirstRep().getSystem() + "|" + c.getIdentifierFirstRep().getValue()); - } - - //Procedures - for(Procedure p : procedures) { - int rank = admission.getProcedures().get(procedures.indexOf(p)).getSeqNumber(); - - //set Procedure in enc.diagnosis - enc.addDiagnosis().setCondition(new Reference(p.getId())).setRank(rank); - - //add Procedure to bundle - bundleC.addUUIDResourceWithConditionToBundle(p, "identifier=" + p.getIdentifierFirstRep().getSystem() + "|" + p.getIdentifierFirstRep().getValue()); - } - - //create transfer chain - - enc.getLocation().clear(); //clear all locations -> to be newly added - - for(MTransfer t : admission.getTransfers()) { - Location locWard = locations.get(t.getCurrWard()).getFhirLocation(); - String identifier = locWard.getIdentifierFirstRep().getValue(); - String id; - if(!locationsInBundle.containsKey(identifier)) { - //add to memory list: - locationsInBundle.put(identifier, locWard.getId()); - id = locWard.getId(); - //Location: Set Hospital als TOp-Orga - locWard.setManagingOrganization(new Reference(hospital.getId())); - - bundleC.addUUIDResourceWithConditionToBundle(locWard, "identifier=" + locWard.getIdentifierFirstRep().getSystem() + "|" + identifier); - }else { - id = locationsInBundle.get(identifier); - } - - //Ward as Location - enc.addLocation().setLocation(new Reference(id)).setPeriod(new Period().setStart(t.getIntime()).setEnd(t.getOuttime())); - } - - //add Encounter to bundle - bundleC.addUUIDResourceWithConditionToBundle(enc,"identifier=" + enc.getIdentifierFirstRep().getSystem() + "|" + enc.getIdentifierFirstRep().getValue()); - } - - private String processCaregiver(int caregiverId) { - MCaregiver cgHere = caregivers.get(caregiverId); - //Create FHIR-Resources for Practitioner und -Role - Practitioner pFhir = cgHere.getFhirRepresentation(); - String identifier = pFhir.getIdentifierFirstRep().getValue(); - String id; - if(!caregiversInBundle.containsKey(identifier)) { - //add to memory list - caregiversInBundle.put(identifier, pFhir.getId()); - id = pFhir.getId(); - bundleC.addUUIDResourceWithConditionToBundle(pFhir, "identifier=" + pFhir.getIdentifierFirstRep().getSystem() + "|" + identifier); - - PractitionerRole roleFhir = cgHere.getFhirRepresentationRole(); - if(roleFhir != null) { - roleFhir.setPractitioner(new Reference(pFhir.getId())); - roleFhir.setOrganization(new Reference(hospital.getId())); - bundleC.addUUIDResourceWithConditionToBundle(roleFhir, "identifier=" + roleFhir.getIdentifierFirstRep().getSystem() + "|" + roleFhir.getIdentifierFirstRep().getValue()); - } - } - else { - id = caregiversInBundle.get(identifier); - } - return id; - } - - private Organization createTopHospital() { - //Create a "dummy" Organization that is "top player" of PractitionerRoles and Locations - Organization hospital = new Organization(); - - hospital.addIdentifier().setSystem("http://www.imi-mimic.de").setValue("hospital"); - - hospital.addType().addCoding().setCode("prov").setSystem("http://hl7.org/fhir/organization-type").setDisplay("Healthcare Provider"); - hospital.setName("IMI-Mimic Hospital"); - - - hospital.setId(IdDt.newRandomUuid()); - return hospital; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/OutputMode.java b/src/main/java/de.uzl.itcr/mimic2fhir/OutputMode.java deleted file mode 100755 index cac5014..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/OutputMode.java +++ /dev/null @@ -1,32 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir; - -/** - * Output-Mode: Where shall the data go? - * -CONSOLE: Print to console - * -FILE: Print to xml-Files - * -BOTH: Console and file - * -SERVER: Push to a Fhir server - * @author Stefanie Ververs - * - */ -public enum OutputMode { - PRINT_CONSOLE, - PRINT_FILE, - PRINT_BOTH, - PUSH_SERVER -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MAdmission.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MAdmission.java deleted file mode 100755 index 601a120..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MAdmission.java +++ /dev/null @@ -1,416 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Coding; -import org.hl7.fhir.dstu3.model.Condition; -import org.hl7.fhir.dstu3.model.Encounter; -import org.hl7.fhir.dstu3.model.Encounter.EncounterHospitalizationComponent; -import org.hl7.fhir.dstu3.model.Encounter.EncounterStatus; -import org.hl7.fhir.dstu3.model.Medication; -import org.hl7.fhir.dstu3.model.MedicationAdministration; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.dstu3.model.Period; -import org.hl7.fhir.dstu3.model.Procedure; -import org.hl7.fhir.dstu3.model.Reference; - -import ca.uhn.fhir.model.primitive.IdDt; - -/** - * Represents one row (and references) in mimiciii.admissions - * @author Stefanie Ververs - * - */ -public class MAdmission { - - public MAdmission() { - diagnoses = new ArrayList(); - procedures = new ArrayList(); - events = new ArrayList(); - labevents = new ArrayList(); - noteevents = new ArrayList(); - prescriptions = new ArrayList(); - transfers = new ArrayList(); - } - - private String admissionId; - private String maritalStatus; - private String language; - private String religion; - - private Date admissionTime; - private Date dischargeTime; - private String admissionType; - private String dischargeLocation; - private String admissionLocation; - - private List events; - private List labevents; - private List noteevents; - - private List diagnoses; - private List procedures; - - private List prescriptions; - - private List transfers; - - public List getTransfers(){ - return transfers; - } - - public void addTransfer(MTransfer proc) { - transfers.add(proc); - } - - public List getPrescriptions(){ - return prescriptions; - } - - public void addPrescription(MPrescription proc) { - prescriptions.add(proc); - } - - public List getProcedures(){ - return procedures; - } - - public void addProcedure(MProcedure proc) { - procedures.add(proc); - } - - public List getDiagnoses() { - return diagnoses; - } - public void addDiagnose(MDiagnose diag) { - diagnoses.add(diag); - } - - public List getEvents() { - return events; - } - public void addEvent(MChartevent event) { - events.add(event); - } - - public List getLabEvents() { - return labevents; - } - public void addLabEvent(MLabevent event) { - labevents.add(event); - } - - public List getNoteevents() { - return noteevents; - } - public void addNoteEvent(MNoteevent event) { - noteevents.add(event); - } - - public String getAdmissionId() { - return admissionId; - } - public void setAdmissionId(String admissionId) { - this.admissionId = admissionId; - } - - public String getMaritalStatus() { - return maritalStatus; - } - public void setMaritalStatus(String maritalStatus) { - this.maritalStatus = maritalStatus; - } - public String getLanguage() { - return language; - } - public void setLanguage(String language) { - this.language = language; - } - public String getReligion() { - return religion; - } - public void setReligion(String religion) { - this.religion = religion; - } - - public String getAdmissionLocation() { - return admissionLocation; - } - public void setAdmissionLocation(String admissionLocation) { - this.admissionLocation = admissionLocation; - } - public String getDischargeLocation() { - return dischargeLocation; - } - public void setDischargeLocation(String dischargeLocation) { - this.dischargeLocation = dischargeLocation; - } - public String getAdmissionType() { - return admissionType; - } - public void setAdmissionType(String admissionType) { - this.admissionType = admissionType; - } - public Date getAdmissionTime() { - return admissionTime; - } - public void setAdmissionTime(Date admissionTime) { - this.admissionTime = admissionTime; - } - public Date getDischargeTime() { - return dischargeTime; - } - public void setDischargeTime(Date dischargeTime) { - this.dischargeTime = dischargeTime; - } - - /** - * Create all FHIR-"Condition"s for each diagnose - * @param patId Patient-FHIR-Resource-Id - * @return List with all resources - */ - public List createFhirConditionsFromMimic(String patId) { - - List conditions = new ArrayList(); - for(MDiagnose d : diagnoses) { - conditions.add(d.getFhirCondition(patId, getAdmissionId())); - } - return conditions; - } - - /** - * Create the FHIR-"Encounter"-resource for the mimic admission - * @param patId Patient-FHIR-Resource-Id - * @return FHIR-Encounter - */ - public Encounter createFhirEncounterFromMimic(String patId) { - - Encounter enc = new Encounter(); - - //Id - enc.addIdentifier().setSystem("http://www.imi-mimic.de/encs").setValue(getAdmissionId()); - - //Patient - enc.setSubject(new Reference(patId)); - - //Period - enc.setPeriod(new Period().setStart(getAdmissionTime()).setEnd(getDischargeTime())); - - //all admissions are finished - enc.setStatus(EncounterStatus.FINISHED); - - //AdmissionType -> Class - //‘ELECTIVE’, ‘URGENT’, ‘NEWBORN’ or ‘EMERGENCY’ - switch(admissionType) { - case "ELECTIVCE": - enc.setClass_(new Coding().setCode("IMP").setSystem("http://hl7.org/fhir/v3/ActCode").setDisplay("inpatient encounter")); - break; - case "URGENT": - enc.setClass_(new Coding().setCode("ACUTE").setSystem("http://hl7.org/fhir/v3/ActCode").setDisplay("inpatient acute")); - break; - case "EMERGENCY": - enc.setClass_(new Coding().setCode("EMER").setSystem("http://hl7.org/fhir/v3/ActCode").setDisplay("emergency")); - break; - case "NEWBORN": - enc.setClass_(new Coding().setCode("NEWB").setSystem("http://hl7.org/fhir/v3/ActCode").setDisplay("newborn")); - break; - } - - //Discharge Location - EncounterHospitalizationComponent ehc = new EncounterHospitalizationComponent(); - CodeableConcept discharge = new CodeableConcept(); - switch(getDischargeLocation()) { - case "HOME": - case "HOME WITH HOME IV PROVIDR": - case "HOME HEALTH CARE": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("home").setDisplay("Home"); - break; - case "HOSPICE-MEDICAL FACILITY": - case "HOSPICE-HOME": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("hosp").setDisplay("Hospice"); - break; - case "REHAB/DISTINCT PART HOSP": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("rehab").setDisplay("Rehabilitation"); - break; - case "DISC-TRAN CANCER/CHLDRN H": - case "OTHER FACILITY": - case "DISC-TRAN TO FEDERAL HC": - case "SHORT TERM HOSPITAL": - case "ICF": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("other-hcf").setDisplay("Other healthcare facility"); - break; - case "DISCH-TRAN TO PSYCH HOSP": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("psy").setDisplay("Psychiatric hospital"); - break; - case "DEAD/EXPIRED": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("exp").setDisplay("Expired"); - break; - case "LEFT AGAINST MEDICAL ADVI": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("aadvice").setDisplay("Left against advice"); - break; - case "LONG TERM CARE HOSPITAL": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("long").setDisplay("Long-term care"); - break; - case "SNF": - case "SNF-MEDICAID ONLY CERTIF": - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("snf").setDisplay("Skilled nursing factory"); - break; - default: - discharge.addCoding().setSystem("http://hl7.org/fhir/discharge-disposition").setCode("oth").setDisplay("Other"); - break; - - } - ehc.setDischargeDisposition(discharge); - - //Admit Source from Admission location - CodeableConcept cal = new CodeableConcept(); - - switch(this.admissionLocation) { - case "PHYS REFERRAL/NORMAL DELI": - case "HMO REFERRAL/SICK": - cal.addCoding().setCode("mp").setDisplay("Medical Practitioner/physician referral").setSystem("http://hl7.org/fhir/admit-source"); - break; - case "TRSF WITHIN THIS FACILITY": - cal.addCoding().setCode("other").setDisplay("Other").setSystem("http://hl7.org/fhir/admit-source"); - break; - case "TRANSFER FROM SKILLED NUR": - cal.addCoding().setCode("nursing").setDisplay("From nursing home").setSystem("http://hl7.org/fhir/admit-source"); - break; - case "** INFO NOT AVAILABLE **": - cal.setText("Not available"); - break; - case "CLINIC REFERRAL/PREMATURE": - case "TRANSFER FROM HOSP/EXTRAM": - cal.addCoding().setCode("hosp-trans").setDisplay("Transferred from other hospital").setSystem("http://hl7.org/fhir/admit-source"); - break; - case "TRANSFER FROM OTHER HEALT": - cal.addCoding().setCode("other").setDisplay("Other").setSystem("http://hl7.org/fhir/admit-source"); - break; - case "EMERGENCY ROOM ADMIT": - cal.addCoding().setCode("emd").setDisplay("From accident/emergency department").setSystem("http://hl7.org/fhir/admit-source"); - break; - } - ehc.setAdmitSource(cal); - enc.setHospitalization(ehc); - - - // Give the encounter a temporary UUID so that other resources in - // the transaction can refer to it - enc.setId(IdDt.newRandomUuid()); - - return enc; - } - - /** - * Create all FHIR-"Observation"s for this encounter (Chartevents) - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return List with all FHIR Observations - */ - public List createFhirObservationsFromMimic(String patId, String encId){ - List obs = new ArrayList(); - - for(MChartevent event : this.events) { - obs.add(event.getFhirObservation(patId, encId)); - } - - return obs; - } - - /** - * Create all FHIR-"Observation"s for this encounter (Labevents) - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return List with all FHIR Observations - */ - public List createFhirLabObservationsFromMimic(String patId, String encId){ - List obs = new ArrayList(); - - for(MLabevent event : this.labevents) { - obs.add(event.getFhirObservation(patId, encId)); - } - - return obs; - } - - - /** - * Create all FHIR-"Observation"s for this encounter (Noteevents) - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return List with all FHIR Observations - */ - public List createFhirNoteObservationsFromMimic(String patId, String encId){ - List obs = new ArrayList(); - - for(MNoteevent event : this.noteevents) { - Observation observation = event.getFhirObservation(patId, encId); - - obs.add(observation); - } - - return obs; - } - - /** - * Create all FHIR-"Procedure"s for each Procedure for this mimic admission - * @param patId Patient-FHIR-Resource-Id - * @return List with all FHIR-Procedures - */ - public List createFhirProceduresFromMimic(String patId) { - - List procedures = new ArrayList(); - for(MProcedure p : this.procedures) { - procedures.add(p.getFhirProcedure(patId, getAdmissionId())); - } - return procedures; - } - - /** - * Create all FHIR-"Medication"s for this encounter - * @return List with all FHIR Medication - */ - public List createFhirMedicationsFromMimic() { - - List medications = new ArrayList(); - for(MPrescription p : this.prescriptions) { - medications.add(p.getFhirMedication()); - } - return medications; - } - - /** - * Create all FHIR-"MedicationAdministration"s for this encounter - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return List with all MedicationAdministration - */ - public List createFhirMedAdminsFromMimic(String patId, String encId) { - - List administrations = new ArrayList(); - - int index = 0; - for(MPrescription p : this.prescriptions) { - administrations.add(p.getFhirMedAdministration(patId, encId, index++)); - } - return administrations; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MCaregiver.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MCaregiver.java deleted file mode 100755 index 6468edb..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MCaregiver.java +++ /dev/null @@ -1,154 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus; -import org.hl7.fhir.dstu3.model.Practitioner; -import org.hl7.fhir.dstu3.model.PractitionerRole; - -import ca.uhn.fhir.model.primitive.IdDt; - -/** - * Represents one row in mimiciii.caregivers - * @author Stefanie Ververs - * - */ -public class MCaregiver { - private int caregiverId; - private String label; - private String description; - - public int getCaregiverId() { - return caregiverId; - } - public void setCaregiverId(int caregiverId) { - this.caregiverId = caregiverId; - } - public String getLabel() { - return label; - } - public void setLabel(String label) { - this.label = label; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - - /** - * Create FHIR-"Practitioner" from this caregivers' data - * @return FHIR-Practitioner - */ - public Practitioner getFhirRepresentation() { - Practitioner p = new Practitioner(); - - //Id - p.addIdentifier().setSystem("http://www.imi-mimic.de/practitioner").setValue(Integer.toString(caregiverId)); - - //Name - p.addName().setFamily("Caregiver " + caregiverId); - - //Narrative - p.getText().setStatus(NarrativeStatus.GENERATED); - p.getText().setDivAsString("
Caregiver with Id " + caregiverId + "
"); - - // temporary UUID - p.setId(IdDt.newRandomUuid()); - - return p; - } - - /** - * Create FHIR-"PractitionerRole" from this caregivers' data - * @return FHIR-PractitionerRole - */ - public PractitionerRole getFhirRepresentationRole() { - PractitionerRole role = new PractitionerRole(); - - //Id - role.addIdentifier().setSystem("http://www.imi-mimic.de/pracRole").setValue(Integer.toString(caregiverId)); - - //code (~Role) - CodeableConcept cc = new CodeableConcept(); - - String descriptionToCheck = description; - if(descriptionToCheck == null) { - descriptionToCheck = label; - } - if(descriptionToCheck != null) { - switch(descriptionToCheck) { - - case "RN": //Research Nurse - case "Research Assistant": - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("researcher").setDisplay("Researcher"); - break; - case "Pharmacist": - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("pharmacist").setDisplay("Pharmacist"); - break; - case "Administrator": - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("ict").setDisplay("ICT professional"); - break; - case "IMD": //expected to be MDs - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("doctor").setDisplay("Doctor"); - break; - default: - //check Label, because description not clear - if(label != null) { - switch(label) { - case "Admin": - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("ict").setDisplay("ICT professional"); - break; - case "RN": - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("researcher").setDisplay("Researcher"); - break; - case "Res": //Resident/Fellow/PA/NP - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("nurse").setDisplay("Nurse"); - break; - case "md": - case "Md": - case "MD": - case "MD,PhD": - case "Mds": - case "MDs": - case "MDS": - cc.addCoding().setSystem("http://hl7.org/fhir/practitioner-role").setCode("doctor").setDisplay("Doctor"); - break; - default: - role = null; //if not one of the provided roles in Valueset -> no role - break; - } - }else - { - role = null; - } - break; - } - } - else { - role = null; - } - - if(role != null) { - role.addCode(cc); - } - - return role; - } - -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MChartevent.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MChartevent.java deleted file mode 100755 index 344b223..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MChartevent.java +++ /dev/null @@ -1,157 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.Date; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.DateTimeType; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.dstu3.model.Quantity; -import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; - -/** - * Represents one row in mimiciii.chartevents - * @author Stefanie Ververs - * - */ -public class MChartevent { - //Rekord-Datum - private Date recordDate; - - //CareGiver - private int careGiverId; - - //Type - private String measurementType; - - //Value + ValueNum - private String value; - - //Unit - private String unit; - - private double numValue; - - private boolean hasNumVal; - - public boolean hasNumVal() { - return hasNumVal; - } - - public void setHasNumVal(boolean hasNumVal) { - this.hasNumVal = hasNumVal; - } - - public Date getRecordDate() { - return recordDate; - } - - public void setRecordDate(Date recordDate) { - this.recordDate = recordDate; - } - - public int getCareGiverId() { - return careGiverId; - } - - public void setCareGiverId(int careGiverId) { - this.careGiverId = careGiverId; - } - - public String getMeasurementType() { - return measurementType; - } - - public void setMeasurementType(String measurementType) { - this.measurementType = measurementType; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public double getNumValue() { - return numValue; - } - - public void setNumValue(double numValue) { - this.hasNumVal = true; - this.numValue = numValue; - } - - public String getUnit() { - return unit; - } - - public void setUnit(String unit) { - this.unit = unit; - } - - /** - * Create FHIR-"Observation"-resource from this data - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return FHIR-Observation - */ - public Observation getFhirObservation(String patId, String encId) { - Observation observation = new Observation(); - - observation.setStatus(ObservationStatus.FINAL); - - //Expect all chartevents to be vital signs - observation.addCategory().addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("vital_signs").setDisplay("Vital Signs"); - - //Type of Observation - //D_Items in Mimic doesn't relate the measurement types to any coding system or terminology - // => Representation as plain text - CodeableConcept cc = new CodeableConcept(); - cc.setText(this.getMeasurementType()); - observation.setCode(cc); - - //Pat-Reference - observation.setSubject(new Reference(patId)); - - //Enc-Reference - observation.setContext(new Reference(encId)); - - //Record-Date - observation.setEffective(new DateTimeType(this.getRecordDate())); - - //Performer will be set later - - //Actual result - if(this.hasNumVal()) { - Quantity value = new Quantity(); - value.setValue(this.getNumValue()); - value.setUnit(this.getUnit()); - - observation.setValue(value); - } - else - { - observation.setValue(new StringType(this.getValue())); - //no units in data - } - return observation; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MDiagnose.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MDiagnose.java deleted file mode 100755 index 6e87c33..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MDiagnose.java +++ /dev/null @@ -1,91 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Condition; -import org.hl7.fhir.dstu3.model.Reference; - -import ca.uhn.fhir.model.primitive.IdDt; - -/** - * Represents one diagnose in diagnoses_icd joined with d_icd_diagnoses - * @author Stefanie Ververs - * - */ -public class MDiagnose { - private String icd9Code; - private String shortTitle; - private String longTitle; - private int seqNumber; - - public int getSeqNumber() { - return seqNumber; - } - public void setSeqNumber(int seqNumber) { - this.seqNumber = seqNumber; - } - public String getIcd9Code() { - return icd9Code; - } - public void setIcd9Code(String icd9Code) { - this.icd9Code = icd9Code; - } - public String getShortTitle() { - return shortTitle; - } - public void setShortTitle(String shortTitle) { - this.shortTitle = shortTitle; - } - public String getLongTitle() { - return longTitle; - } - public void setLongTitle(String longTitle) { - this.longTitle = longTitle; - } - - /** - * Create FHIR-"Condition"-Resource for this data - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-Resource-Id - * @return FHIR-Condition - */ - public Condition getFhirCondition(String patId, String encId) { - Condition cond = new Condition(); - - //Patient - cond.setSubject(new Reference(patId)); - - //Identifier - cond.addIdentifier().setSystem("http://www.imi-mimic.de/diags").setValue(encId + "_" + this.seqNumber); - - //Context -> Encounter - //cond.setContext(new Reference(encId)); - - //Diagnose itself (Code + Text) - CodeableConcept diagnoseCode = new CodeableConcept(); - diagnoseCode.addCoding().setSystem("http://hl7.org/fhir/sid/icd-9-cm").setCode(this.getIcd9Code()) - .setDisplay(this.getLongTitle()); - - cond.setCode(diagnoseCode); - - // Give the condition a temporary UUID so that other resources in - // the transaction can refer to it - cond.setId(IdDt.newRandomUuid()); - - return cond; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MLabevent.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MLabevent.java deleted file mode 100755 index cf9e3db..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MLabevent.java +++ /dev/null @@ -1,194 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.Date; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.DateTimeType; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.dstu3.model.Quantity; -import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; - -/** - * Represents one row in mimiciii.labevents - * @author Stefanie Ververs - * - */ -public class MLabevent { - //Rekord-Datum - private Date acquisitionDate; - - //Type - private String measurementType; - - //Value + ValueNum - private String value; - - private double numValue; - - private boolean hasNumVal; - - private boolean abnormal; - - private String fluid; - - private String loinc; - - public String getFluid() { - return fluid; - } - - public void setFluid(String fluid) { - this.fluid = fluid; - } - - public String getLoinc() { - return loinc; - } - - public void setLoinc(String loinc) { - this.loinc = loinc; - } - - public boolean isAbnormal() { - return abnormal; - } - - public void setAbnormal(boolean abnormal) { - this.abnormal = abnormal; - } - - public boolean hasNumVal() { - return hasNumVal; - } - - public void setHasNumVal(boolean hasNumVal) { - this.hasNumVal = hasNumVal; - } - - //Unit - private String unit; - - public Date getAcquisitionDate() { - return acquisitionDate; - } - - public void setAcquisitionDate(Date recordDate) { - this.acquisitionDate = recordDate; - } - - public String getMeasurementType() { - return measurementType; - } - - public void setMeasurementType(String measurementType) { - this.measurementType = measurementType; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public double getNumValue() { - return numValue; - } - - public void setNumValue(double numValue) { - this.hasNumVal = true; - this.numValue = numValue; - } - - public String getUnit() { - return unit; - } - - public void setUnit(String unit) { - this.unit = unit; - } - - /** - * Create FHIR-"Observation" resources for this data - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return FHIR-Observation - */ - public Observation getFhirObservation(String patId, String encId) { - Observation observation = new Observation(); - - observation.setStatus(ObservationStatus.FINAL); - - //all laboratory - observation.addCategory().addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("laboratory").setDisplay("Laboratory"); - - CodeableConcept cc = new CodeableConcept(); - //Type of Observation - if(this.getLoinc() != null) { - cc.addCoding().setSystem("http://loinc.org").setCode(this.getLoinc()); - cc.setText(this.getMeasurementType()); - } - else { - //Representation as plain text if no loinc code available - cc.setText(this.getMeasurementType()); - } - observation.setCode(cc); - - - //Pat-Reference - observation.setSubject(new Reference(patId)); - - //Enc-Reference - observation.setContext(new Reference(encId)); - - //Record-Date - observation.setEffective(new DateTimeType(this.getAcquisitionDate())); - - //Performer is not available - - //Actual result - if(this.hasNumVal()) { - Quantity value = new Quantity(); - value.setValue(this.getNumValue()); - value.setUnit(this.getUnit()); - - observation.setValue(value); - } - else - { - String value = this.getValue(); - //Unit added with "()" - if(this.getUnit() != null && this.getUnit().length() > 0) { - value += " (" + this.getUnit() + ")"; - } - observation.setValue(new StringType(value)); - } - - //Interpretation (from "flag") - if(this.isAbnormal()) { - cc = new CodeableConcept(); - cc.addCoding().setSystem("http://hl7.org/fhir/v2/0078").setCode("A").setDisplay("Abnormal"); - observation.setInterpretation(cc); - } - - return observation; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MNoteevent.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MNoteevent.java deleted file mode 100755 index e27418f..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MNoteevent.java +++ /dev/null @@ -1,135 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.Date; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.DateTimeType; -import org.hl7.fhir.dstu3.model.Observation; -import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; - -import de.uzl.itcr.mimic2fhir.tools.Helper; - -/** - * Represents one row in mimiciii.noteevents - * @author Stefanie Ververs - * - */ -public class MNoteevent { - private Date chartdate; - private String category; - private String description; - private int caregiverId; - private String text; - private boolean hasError; - - public boolean getHasError() { - return hasError; - } - public void setHasError(boolean hasError) { - this.hasError = hasError; - } - public Date getChartdate() { - return chartdate; - } - public void setChartdate(Date chartdate) { - this.chartdate = chartdate; - } - public String getCategory() { - return category; - } - public void setCategory(String category) { - this.category = category; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - public int getCaregiverId() { - return caregiverId; - } - public void setCaregiverId(int caregiverId) { - this.caregiverId = caregiverId; - } - public String getText() { - return text; - } - public void setText(String text) { - this.text = Helper.CleanInvalidXmlChars(text, " "); - } - - /** - * Create FHIR-"Observation" resources for this data - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return FHIR-Observation - */ - public Observation getFhirObservation(String patId, String encId) { - Observation observation = new Observation(); - - if(this.getHasError()) { - observation.setStatus(ObservationStatus.ENTEREDINERROR); - } - else{ - observation.setStatus(ObservationStatus.FINAL); - } - - //Not sure if observation is correct for (all) notes - - //"Type" of Observation - CodeableConcept cc = new CodeableConcept(); - //Representation as plain text - cc.setText(this.getDescription()); - observation.setCode(cc); - - //Category is only possible for some: - switch(this.getCategory()) - { - case "Echo": - //imaging - observation.addCategory().addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("imaging").setDisplay("Imaging"); - break; - case "ECG": - case "Respiratory": - observation.addCategory().addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("procedure").setDisplay("Procedure"); - break; - case "Social Work": - observation.addCategory().addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("social-history").setDisplay("Social History"); - break; - case "Pharmacy": - case "Rehab Services": - observation.addCategory().addCoding().setSystem("http://hl7.org/fhir/observation-category").setCode("therapy").setDisplay("Therapy"); - break; - } - - //Indication for Noteevent -> No Value, but comment - observation.setComment(this.getText()); - - //Pat-Reference - observation.setSubject(new Reference(patId)); - - //Enc-Reference - observation.setContext(new Reference(encId)); - - //Record-Date - observation.setEffective(new DateTimeType(this.getChartdate())); - return observation; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MPatient.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MPatient.java deleted file mode 100755 index 77e72c9..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MPatient.java +++ /dev/null @@ -1,376 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.DateTimeType; -import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; -import org.hl7.fhir.dstu3.model.HumanName.NameUse; -import org.hl7.fhir.dstu3.model.Patient; - -import ca.uhn.fhir.model.primitive.IdDt; - -/** - * FHIR-Patient with data from mimic3, one row in mimiciii.patients - * @author Stefanie Ververs - * - */ -public class MPatient { - - public MPatient() { - admissions = new ArrayList(); - } - - public void addAdmission(MAdmission adm) { - admissions.add(adm); - } - - private List admissions; - - public List getAdmissions() { - return admissions; - } - - private String patientSubjectId; - public String getPatientSubjectId() { - return patientSubjectId; - } - - public void setPatientSubjectId(String patientSubjectId) { - this.patientSubjectId = patientSubjectId; - } - - public Date getBirthDate() { - return birthDate; - } - - public void setBirthDate(Date birthDate) { - this.birthDate = birthDate; - } - - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } - - public Date getDeathDate() { - return deathDate; - } - - public void setDeathDate(Date deathDate) { - this.deathDate = deathDate; - } - - private Date birthDate; - private String gender; - private Date deathDate; - - /** - * Create FHIR-"Patient"-resource from this data - * @return FHIR-Patient - */ - public Patient createFhirFromMimic() { - Patient pMimic = new Patient(); - - //ID: - pMimic.addIdentifier().setSystem("http://www.imi-mimic.de/patients").setValue(patientSubjectId); - - //Name : Patient_ID - pMimic.addName().setUse(NameUse.OFFICIAL).setFamily("Patient_" + patientSubjectId); - - //Date of Birth - pMimic.setBirthDate(birthDate); - - //Date of Death - if(deathDate != null) { - pMimic.setDeceased(new DateTimeType(deathDate)); - } - - //Gender - switch(gender) { - case "M": - pMimic.setGender(AdministrativeGender.MALE); - break; - case "F": - pMimic.setGender(AdministrativeGender.FEMALE); - break; - default: - pMimic.setGender(AdministrativeGender.UNKNOWN); - } - - if(admissions.size() > 0) { - //from first admission - MAdmission firstAdm = admissions.get(0); - - //Marital Status - - CodeableConcept cc = new CodeableConcept(); - - if(firstAdm.getMaritalStatus() != null){ - switch(firstAdm.getMaritalStatus()) { - case "MARRIED": - cc.addCoding().setCode("M").setSystem("http://hl7.org/fhir/v3/MaritalStatus").setDisplay("Married"); - break; - case "SINGLE": - cc.addCoding().setCode("S").setSystem("http://hl7.org/fhir/v3/MaritalStatus").setDisplay("Never Married"); - break; - case "WIDOWED": - cc.addCoding().setCode("W").setSystem("http://hl7.org/fhir/v3/MaritalStatus").setDisplay("Widowed"); - break; - case "DIVORCED": - cc.addCoding().setCode("D").setSystem("http://hl7.org/fhir/v3/MaritalStatus").setDisplay("Divorced"); - break; - case "SEPARATED": - cc.addCoding().setCode("L").setSystem("http://hl7.org/fhir/v3/MaritalStatus").setDisplay("Legally Separated"); - break; - default: - cc.addCoding().setCode("UNK").setSystem("http://hl7.org/fhir/v3/MaritalStatus").setDisplay("Unknown"); - } - pMimic.setMaritalStatus(cc); - } - - //Language - if(firstAdm.getLanguage() != null) { - CodeableConcept lc = new CodeableConcept(); - //Languages sometimes guessed - no dictionary or something in mimic.. - switch(firstAdm.getLanguage()) { - case "*DUT": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("nl").setDisplay("Dutch"); - break; - case "URDU": - case "*URD": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ur").setDisplay("Urdu"); - break; - case "*NEP": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ne").setDisplay("Nepali"); - break; - case "TAGA": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("tl").setDisplay("Tagalog"); - break; - case "*TOY": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("toy").setDisplay("Topoiyo"); - break; - case "*RUS": - case "RUSS": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ru").setDisplay("Russian"); - break; - case "ENGL": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("en").setDisplay("English"); - break; - case "*ARM": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("hy").setDisplay("Armenian"); - break; - case "CANT": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("yue").setDisplay("Cantonese"); - break; - case "LAOT": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("tyl").setDisplay("Thu Lao"); - break; - case "*MOR": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("mor").setDisplay("Moro"); - break; - case "*FUL": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ff").setDisplay("Fulah"); - break; - case "*ROM": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ro").setDisplay("Romanian"); - break; - case "*TOI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("toi").setDisplay("Tonga"); - break; - case "BENG": - case "*BEN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("bn").setDisplay("Bengali"); - break; - case "**TO": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("to").setDisplay("Tonga"); - break; - case "PERS": - case "*PER": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("fa").setDisplay("Persian"); - break; - case "*TEL": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("te").setDisplay("Telugu"); - break; - case "*YID": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ji").setDisplay("Yiddish"); - break; - case "*CDI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("cdi").setDisplay("Chodri"); - break; - case "JAPA": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("jp").setDisplay("Japanese"); - break; - case "ALBA": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("sq").setDisplay("Albanian"); - break; - case "ARAB": - case "*ARA": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ar").setDisplay("Arabic"); - break; - case "ITAL": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("it").setDisplay("Italian"); - break; - case "*TAM": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("taq").setDisplay("Tamasheq"); - break; - case "*SPA": - case "SPAN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("es").setDisplay("Spanish"); - break; - case "*BOS": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("bs").setDisplay("Bosnian"); - break; - case "*AMH": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("am").setDisplay("Amharic"); - break; - case "SOMA": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("so").setDisplay("Somali"); - break; - case "CAPE": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("cap").setDisplay("Chipaya"); - break; - case "*PUN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("pa").setDisplay("Punjabi"); - break; - case "POLI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("pl").setDisplay("Polish"); - break; - case "*CHI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("zh").setDisplay("Chinese"); - break; - case "*BUR": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("my").setDisplay("Burmese"); - break; - case "*CAN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("can").setDisplay("Chambri"); - break; - case "*YOR": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("yox").setDisplay("Yoron"); - break; - case "*KHM": - case "CAMB": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("km").setDisplay("Central Khmer"); - break; - case "AMER": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("en").setDisplay("English"); - break; - case "*LIT": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("lt").setDisplay("Lithuanian"); - break; - case "*IBO": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ibn").setDisplay("Ibino"); - break; - case "KORE": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ko").setDisplay("Korean"); - break; - case "*FIL": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("fil").setDisplay("Filipino"); - break; - case "THAI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("th").setDisplay("Thai"); - break; - case "**SH": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("sh").setDisplay("Serbo-Croatian"); - break; - case "FREN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("fr").setDisplay("French"); - break; - case "*FAR": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("far").setDisplay("Fataleka"); - break; - case "*CRE": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("crp").setDisplay("Creoles and pidgins"); - break; - case "HIND": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("hi").setDisplay("Hindi"); - break; - case "*HUN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("hu").setDisplay("Hungarian"); - break; - case "ETHI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("eth").setDisplay("Ethiopian Sign Language"); - break; - case "VIET": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("vi").setDisplay("Vietnamese"); - break; - case "*MAN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("man").setDisplay("Mandingo"); - break; - case "GERM": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("de").setDisplay("German"); - break; - case "*PHI": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("phi").setDisplay("Philippine languages"); - break; - case "TURK": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("tr").setDisplay("Turkish"); - break; - case "*DEA": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("mjl").setDisplay("Mandeali"); - break; - case "PTUN": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ptu").setDisplay("Bambam"); - break; - case "GREE": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("el").setDisplay("Modern Greek"); - break; - case "MAND": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("cmn").setDisplay("Mandarin Chinese"); - break; - case "HAIT": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("ht").setDisplay("Haitian"); - break; - case "SERB": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("sr").setDisplay("Serbian"); - break; - case "*BUL": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("bg").setDisplay("Bulgarian"); - break; - case "*LEB": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("leb").setDisplay("Lala-Bisa"); - break; - case "*GUJ": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("gu").setDisplay("Gujarati"); - break; - case "PORT": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("pt").setDisplay("Portugese"); - break; - case "* BE": - lc.addCoding().setSystem("http://hl7.org/fhir/ValueSet/languages").setCode("be").setDisplay("Belarusian"); - break; - default: - lc.addCoding().setCode(firstAdm.getLanguage()); - } - pMimic.addCommunication().setLanguage(lc); - } - } - - - // Give the patient a temporary UUID so that other resources in - // the transaction can refer to it - pMimic.setId(IdDt.newRandomUuid()); - - return pMimic; - } - -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MPrescription.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MPrescription.java deleted file mode 100755 index 6d11181..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MPrescription.java +++ /dev/null @@ -1,415 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Medication; -import org.hl7.fhir.dstu3.model.Medication.MedicationIngredientComponent; - -import ca.uhn.fhir.model.primitive.IdDt; -import de.uzl.itcr.mimic2fhir.tools.RxNormConcept; -import de.uzl.itcr.mimic2fhir.tools.RxNormLookup; - -import org.hl7.fhir.dstu3.model.MedicationAdministration; -import org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationDosageComponent; -import org.hl7.fhir.dstu3.model.MedicationAdministration.MedicationAdministrationStatus; -import org.hl7.fhir.dstu3.model.Period; -import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.SimpleQuantity; - -/** - * Represents one row in mimiciii.prescriptions - * @author Stefanie Ververs - * - */ -public class MPrescription { - private Date start; - private Date end; - private String drugtype; - private String drug; - private String drugNamePoe; - private String drugNameGeneric; - private String formularyDrugCd; - //Generic Sequence Number - private String gsn; - //National Drug Code - private String ndc; - private String prodStrength; - private String doseValRx; - private String doseUnitRx; - private String formValDisp; - private String formUnitDisp; - - private String route; - - public Date getStart() { - return start; - } - - public void setStart(Date start) { - this.start = start; - } - - public Date getEnd() { - return end; - } - - public void setEnd(Date end) { - this.end = end; - } - - public String getDrugtype() { - return drugtype; - } - - public void setDrugtype(String drugtype) { - this.drugtype = drugtype; - } - - public String getDrug() { - return drug; - } - - public void setDrug(String drug) { - this.drug = drug; - } - - public String getDrugNamePoe() { - return drugNamePoe; - } - - public void setDrugNamePoe(String drugNamePoe) { - this.drugNamePoe = drugNamePoe; - } - - public String getDrugNameGeneric() { - return drugNameGeneric; - } - - public void setDrugNameGeneric(String drugNameGeneric) { - this.drugNameGeneric = drugNameGeneric; - } - - public String getFormularyDrugCd() { - return formularyDrugCd; - } - - public void setFormularyDrugCd(String formularyDrugCd) { - this.formularyDrugCd = formularyDrugCd; - } - - public String getGsn() { - return gsn; - } - - public void setGsn(String gsn) { - this.gsn = gsn; - } - - public String getNdc() { - return ndc; - } - - public void setNdc(String ndc) { - this.ndc = ndc; - } - - public String getProdStrength() { - return prodStrength; - } - - public void setProdStrength(String prodStrength) { - this.prodStrength = prodStrength; - } - - public String getDoseValRx() { - return doseValRx; - } - - public void setDoseValRx(String doseValRx) { - this.doseValRx = doseValRx; - } - - public String getDoseUnitRx() { - return doseUnitRx; - } - - public void setDoseUnitRx(String doseUnitRx) { - this.doseUnitRx = doseUnitRx; - } - - public String getFormValDisp() { - return formValDisp; - } - - public void setFormValDisp(String formValDisp) { - this.formValDisp = formValDisp; - } - - public String getFormUnitDisp() { - return formUnitDisp; - } - - public void setFormUnitDisp(String formUnitDisp) { - this.formUnitDisp = formUnitDisp; - } - - public String getRoute() { - return route; - } - - public void setRoute(String route) { - this.route = route; - } - - /** - * Create FHIR-"Medication"-resource - * @return FHIR-Medication - */ - public Medication getFhirMedication() { - Medication m = new Medication(); - - //RxNorm - List rxNorm = null; - String existingCode = null; - if(this.ndc != null && this.ndc.compareTo("0") != 0) { - //we do have a NDC: - existingCode = this.ndc; - rxNorm = RxNormLookup.getInstance().getRxNormForNdc(this.ndc); - } - - if(rxNorm == null && this.gsn != null) { - //no result for ndc, but gsn -> try again - if(existingCode == null) { - existingCode = this.gsn; - } - - String[] gsnSingles = this.gsn.split(" "); - //Multiple GSN-Codes possible - take all.. - rxNorm = new ArrayList(); - for(String gsnSingle : gsnSingles) - { - rxNorm.addAll(RxNormLookup.getInstance().getRxNormForGsn(gsnSingle.trim())); - } - } - - CodeableConcept cc = new CodeableConcept(); - if(rxNorm != null && !rxNorm.isEmpty()) { - for(RxNormConcept rx : rxNorm) { - cc.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode(rx.getCui()).setDisplay(rx.getName()); - } - } - else { - if((rxNorm == null || rxNorm.isEmpty()) && this.formularyDrugCd != null) { - //seem to be some mnemonic codes - if(existingCode == null) { - existingCode = this.formularyDrugCd; - } - cc.addCoding().setCode(this.formularyDrugCd); //maybe add a system - }else { - if(existingCode == null) { - existingCode = this.drug + "(Text Only)"; - } - cc.setText(this.drug); - cc.addCoding().setCode(existingCode); - } - } - cc.setText(this.drug); - m.setCode(cc); - - //ingredient --> prod strength? - if(this.getProdStrength() != null) { - CodeableConcept ci = new CodeableConcept(); - ci.setText(this.getProdStrength()); - m.addIngredient(new MedicationIngredientComponent(ci)); - } - - m.setId(IdDt.newRandomUuid()); - - return m; - } - - /** - * Create FHIR-"MedicationAdministration"-resource from this data - * @param patId Patient-FHIR-Resource-Id - * @param encId Encounter-FHIR-Resource-Id - * @return FHIR-MedicationAdministration - */ - public MedicationAdministration getFhirMedAdministration(String patId, String encId, int seqNum) { - MedicationAdministration ma = new MedicationAdministration(); - - ma.addIdentifier().setSystem("http://www.imi-mimic.de/prescriptions").setValue(encId + "_" + seqNum); - - ma.setStatus(MedicationAdministrationStatus.COMPLETED); - - ma.setSubject(new Reference(patId)); - ma.setContext(new Reference(encId)); - - ma.setEffective(new Period().setEnd(end).setStart(start)); - - MedicationAdministrationDosageComponent mad = new MedicationAdministrationDosageComponent(); - - if(this.route != null) { - CodeableConcept route = new CodeableConcept(); - switch(this.route) { - case "IV": - case "IV BOLUS": - case "IV DRIP": - case "IVPCA": - case "IVS": - case "PB": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intravenous route").setCode("47625008"); - break; - case "PO": - case "PO/OG": - case "ORAL": - case "PO OR ENTERAL TUBE": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Oral Route").setCode("26643006"); - break; - case "PO/NG": - case "NG/OG": - case "NG": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Nasogastric route").setCode("127492001"); - break; - case "PR": - case "RECTAL": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Per rectum").setCode("37161004"); - break; - case "INTRAPERICARDIAL": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intrapericardial route").setCode("445771006"); - break; - case "RIGHT EYE": - case "LEFT EYE": - case "BOTH EYES": - case "OS": - case "OD": - case "OU": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Ophthalmic route").setCode("54485002"); - break; - case "SC": - case "SUBCUT": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Subcutaneous route").setCode("34206005"); - break; - case "IH": - case "AERO": - case "INHALATION": - case "NEB": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Respiratory tract route").setCode("447694001"); - break; - case "ID": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intradermal use").setCode("372464004"); - break; - case "LEFT EAR": - case "RIGHT EAR": - case "BOTH EARS": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Otic route").setCode("10547007"); - break; - case "IC": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intracardiac use").setCode("372460008"); - break; - case "IN": - case "NAS": - case "NU": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Nasal route").setCode("46713006"); - break; - case "IM": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intramuscular route").setCode("78421000"); - break; - case "BUCCAL": - case "BU": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Buccal route").setCode("54471007"); - break; - case "TP": //topic - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Topical route").setCode("6064005"); - break; - case "ED": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Epidural route").setCode("404820008"); - break; - case "TD": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Transdermal route ").setCode("45890007"); - break; - case "IT": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intrathecal route").setCode("72607000"); - break; - case "SL": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Sublingual route").setCode("37839007"); - break; - case "G TUBE": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Gastrostomy route").setCode("127490009"); - break; - case "VG": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Per vagina").setCode("16857009"); - break; - case "IP": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intraperitoneal route").setCode("38239002"); - break; - case "J TUBE": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Jejunostomy route").setCode("127491008"); - break; - case "ET": - route.addCoding().setSystem("http://snomed.info/sct").setDisplay("Intratracheal route").setCode("404818005"); - break; - default: - route.setText(this.route); - break; - } - mad.setRoute(route); - } - - //Dosage: - //Create text if possible: - String doseText = ""; - if(this.getDoseValRx() != null && this.getDoseUnitRx() != null) { - doseText = this.getDoseValRx() + " " + this.getDoseUnitRx(); - } - - if(this.getFormValDisp() != null && this.getFormUnitDisp() != null) { - if(doseText.length() > 0) { - doseText += " (" + this.getFormValDisp() + " " + this.getFormUnitDisp() + ")"; - }else - { - doseText = this.getFormValDisp() + " " + this.getFormUnitDisp(); - } - } - - if(doseText.length() > 0) { - mad.setText(doseText); - } - - //doseVal -> 30, doseUnit -> mg; - //Amount of medication per dose -> given at one event - double sqValue = 0.0; - try { - sqValue = Double.parseDouble(this.getDoseValRx()); - mad.setDose((SimpleQuantity) new SimpleQuantity().setValue(sqValue).setUnit(this.getDoseUnitRx())); - }catch(NumberFormatException nfe) { - - } - catch(NullPointerException xpe) { - - } - //rate -> Speed - ma.setDosage(mad); - - return ma; - } - - -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MProcedure.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MProcedure.java deleted file mode 100755 index 1bbd0aa..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MProcedure.java +++ /dev/null @@ -1,93 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Procedure; -import org.hl7.fhir.dstu3.model.Reference; -import org.hl7.fhir.dstu3.model.Procedure.ProcedureStatus; - -import ca.uhn.fhir.model.primitive.IdDt; - -/** - * Represents one row in mimiciii.procedures_icd joined with d_icd_procedures - * @author Stefanie Ververs - * - */ -public class MProcedure { - private String icd9Code; - private String shortTitle; - private String longTitle; - private int seqNumber; - public String getIcd9Code() { - return icd9Code; - } - public void setIcd9Code(String icd9Code) { - this.icd9Code = icd9Code; - } - public String getShortTitle() { - return shortTitle; - } - public void setShortTitle(String shortTitle) { - this.shortTitle = shortTitle; - } - public String getLongTitle() { - return longTitle; - } - public void setLongTitle(String longTitle) { - this.longTitle = longTitle; - } - public int getSeqNumber() { - return seqNumber; - } - public void setSeqNumber(int seqNumber) { - this.seqNumber = seqNumber; - } - - /** - * Create FHIR-"Procedure" from this data - * @param patId Patient-FHIR-Resource-Id - * @return FHIR-Procedure - */ - public Procedure getFhirProcedure(String patId, String encId) { - Procedure proc = new Procedure(); - - //Patient - proc.setSubject(new Reference(patId)); - - //Identifier - proc.addIdentifier().setSystem("http://www.imi-mimic.de/procs").setValue(encId + "_" + this.seqNumber); - - //Context -> Encounter - //cond.setContext(new Reference(encId)); - - //State - proc.setStatus(ProcedureStatus.COMPLETED); - - //Procedure itself (Code + Text) - CodeableConcept procedureCode = new CodeableConcept(); - procedureCode.addCoding().setSystem("http://hl7.org/fhir/sid/icd-9-cm").setCode(this.getIcd9Code()) - .setDisplay(this.getLongTitle()); - - proc.setCode(procedureCode); - - // Give the procedure a temporary UUID so that other resources in - // the transaction can refer to it - proc.setId(IdDt.newRandomUuid()); - - return proc; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MTransfer.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MTransfer.java deleted file mode 100755 index 101b786..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MTransfer.java +++ /dev/null @@ -1,91 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import java.util.Date; - -/** - * Represents one row in mimiciii.transfers - * @author Stefanie Ververs - * - */ -public class MTransfer { - private String eventType; - private String prevUnit; - private String currUnit; - private int prevWard; - private int currWard; - private Date intime; - private Date outtime; - private double lengthOfStay; - private String transferId; - - public String getTransferId() { - return transferId; - } - public void setTransferId(String transferId) { - this.transferId = transferId; - } - public String getEventType() { - return eventType; - } - public void setEventType(String eventType) { - this.eventType = eventType; - } - public String getPrevUnit() { - return prevUnit; - } - public void setPrevUnit(String prevUnit) { - this.prevUnit = prevUnit; - } - public String getCurrUnit() { - return currUnit; - } - public void setCurrUnit(String currUnit) { - this.currUnit = currUnit; - } - public int getPrevWard() { - return prevWard; - } - public void setPrevWard(int prevWard) { - this.prevWard = prevWard; - } - public int getCurrWard() { - return currWard; - } - public void setCurrWard(int currWard) { - this.currWard = currWard; - } - public Date getIntime() { - return intime; - } - public void setIntime(Date intime) { - this.intime = intime; - } - public Date getOuttime() { - return outtime; - } - public void setOuttime(Date outtime) { - this.outtime = outtime; - } - public double getLengthOfStay() { - return lengthOfStay; - } - public void setLengthOfStay(double lengthOfStay) { - this.lengthOfStay = lengthOfStay; - } - -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/model/MWard.java b/src/main/java/de.uzl.itcr/mimic2fhir/model/MWard.java deleted file mode 100755 index 619e99e..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/model/MWard.java +++ /dev/null @@ -1,91 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.model; - -import org.hl7.fhir.dstu3.model.CodeableConcept; -import org.hl7.fhir.dstu3.model.Location; - -import ca.uhn.fhir.model.primitive.IdDt; - -/** - * Represents one ward as location (from transfers) - * @author Stefanie Ververs - * - */ -public class MWard { - private int wardId; - private String careUnit; - - public String getCareUnit() { - return careUnit; - } - public void setCareUnit(String careUnit) { - if(careUnit == null) { - this.careUnit = "NORMAL"; - } - else { - this.careUnit = careUnit; - } - } - - public int getWardId() { - return wardId; - } - public void setWardId(int wardId) { - this.wardId = wardId; - } - public String getWardName() { - return "Ward " + wardId + " (" + careUnit + ")"; - } - - /** - * Create FHIR-"Location" - * @return FHIR-Location - */ - public Location getFhirLocation() { - Location loc = new Location(); - - loc.addIdentifier().setSystem("http://www.imi-mimic.de/wards").setValue(this.wardId + "_" + careUnit); - - loc.setName(getWardName()); - - CodeableConcept cc = new CodeableConcept(); - switch(careUnit) { - case "NORMAL": - case "NWARD": //Neonatal ward - cc.addCoding().setCode("HU").setSystem("http://hl7.org/fhir/v3/RoleCode").setDisplay("Hospital unit"); - break; - case "CCU": //Coronary care unit - cc.addCoding().setCode("CCU").setSystem("http://hl7.org/fhir/v3/RoleCode").setDisplay("Coronary care unit"); - break; - case "CSRU": //Cardiac surgery recovery unit - case "MICU": //Medical intensive care unit - case "SICU": //Surgical intensive care unit - case "TSICU": //Trauma/surgical intensive care unit - cc.addCoding().setCode("ICU").setSystem("http://hl7.org/fhir/v3/RoleCode").setDisplay("Intensive care unit"); - break; - case "NICU": //Neonatal intensive care unit - cc.addCoding().setCode("PEDNICU").setSystem("http://hl7.org/fhir/v3/RoleCode").setDisplay("Pediatric neonatal intensive care unit"); - break; - - } - loc.setType(cc); - - loc.setId(IdDt.newRandomUuid()); - - return loc; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/queue/Receiver.java b/src/main/java/de.uzl.itcr/mimic2fhir/queue/Receiver.java deleted file mode 100755 index 1ecd00d..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/queue/Receiver.java +++ /dev/null @@ -1,159 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.queue; - -import com.rabbitmq.client.ConnectionFactory; -import com.rabbitmq.client.Connection; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.TimeoutException; - -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; - -import com.rabbitmq.client.AMQP; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Consumer; -import com.rabbitmq.client.DefaultConsumer; -import com.rabbitmq.client.Envelope; - -import de.uzl.itcr.mimic2fhir.OutputMode; -import de.uzl.itcr.mimic2fhir.work.FHIRComm; - -/** - * RabbitMQ consumer class for receiving and processing bundles - * @author Stefanie Ververs - * - */ -public class Receiver { - private final static String QUEUE_NAME = "BundleQ"; - private Channel channel; - private FHIRComm fhirConnector; - private OutputMode outputMode; - private Connection connection; - - /** - * Constructor - creates new channel connection - */ - public Receiver() { - ConnectionFactory factory = new ConnectionFactory(); - factory.setHost("localhost"); - try { - connection = factory.newConnection(); - channel = connection.createChannel(); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - /** - * Set the Fhir-Communication class - * @param fhirCom - */ - public void setFhirConnector(FHIRComm fhirCom) { - this.fhirConnector = fhirCom; - } - - - /** - * Set the outputMode (how to process bundles) - * @param outputMode - */ - public void setOutputMode(OutputMode outputMode) { - this.outputMode = outputMode; - } - - - /** - * Start listening (and receiving) messages - */ - public void receive() { - try { - channel.queueDeclare(QUEUE_NAME, false, false, false, null); - - Consumer consumer = new DefaultConsumer(channel) { - @Override - public void handleDelivery(String consumerTag, Envelope envelope, - AMQP.BasicProperties properties, byte[] body) - throws IOException { - - //bundle xml from json message data - InputStream is = new ByteArrayInputStream(body); - JsonReader jsonReader = Json.createReader(is); - JsonObject json = jsonReader.readObject(); - jsonReader.close(); - - String number = json.getString("number"); - String bundleXml = json.getString("bundle"); - - if(bundleXml.equals("END")) { - //End this queue.. - channel.basicCancel(consumerTag); - try { - channel.close(); - connection.close(); - } catch (TimeoutException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - else { - //process bundle - try { - performAction(number, bundleXml); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - } - }; - channel.basicConsume(QUEUE_NAME, true, consumer); - - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - private void performAction(String number, String bundle) { - - //Perform action for bundle - switch(outputMode) { - case PRINT_CONSOLE: - fhirConnector.printBundleAsXml(fhirConnector.getBundleFromString(bundle)); - break; - case PRINT_FILE: - fhirConnector.printBundleAsXmlToFile(number, fhirConnector.getBundleFromString(bundle)); - break; - case PRINT_BOTH: - fhirConnector.printBundleAsXml(fhirConnector.getBundleFromString(bundle)); - fhirConnector.printBundleAsXmlToFile(number, fhirConnector.getBundleFromString(bundle)); - break; - case PUSH_SERVER: - fhirConnector.bundleToServer(fhirConnector.getBundleFromString(bundle)); - break; - } - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/queue/Sender.java b/src/main/java/de.uzl.itcr/mimic2fhir/queue/Sender.java deleted file mode 100755 index 0faaee2..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/queue/Sender.java +++ /dev/null @@ -1,80 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.queue; - -import com.rabbitmq.client.Connection; - -import java.io.IOException; -import java.util.concurrent.TimeoutException; - -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.ConnectionFactory; - -/** - * Publisher class for sending bundle message to RabbitMQ - * @author Stefanie Ververs - * - */ -public class Sender { - private final static String QUEUE_NAME = "BundleQ"; - private Channel channel; - private Connection connection; - - /** - * Constructor - creates new channel connection - */ - public Sender() { - ConnectionFactory factory = new ConnectionFactory(); - factory.setHost("localhost"); - try { - connection = factory.newConnection(); - channel = connection.createChannel(); - channel.queueDeclare(QUEUE_NAME, false, false, false, null); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Send message to queue - * @param message json message with number and bundle data - */ - public void send(String message) { - try { - channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - /** - * Close channel connection - */ - public void close() { - try { - this.channel.close(); - this.connection.close(); - } catch (IOException | TimeoutException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/tools/Helper.java b/src/main/java/de.uzl.itcr/mimic2fhir/tools/Helper.java deleted file mode 100755 index 78accb2..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/tools/Helper.java +++ /dev/null @@ -1,34 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.tools; - -public class Helper { - - /** - * Source: https://stackoverflow.com/questions/9710185/how-to-deal-with-invalid-characters-in-a-ws-output-when-using-cxf - * From xml spec valid chars: - * #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] - * any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. - * @param text The String to clean - * @param replacement The string to be substituted for each match - * @return The resulting String - */ - public static String CleanInvalidXmlChars(String text, String replacement) { - String re = "[^\\x09\\x0A\\x0D\\x20-\\xD7FF\\xE000-\\xFFFD\\x10000-x10FFFF]"; - String newText = text.replaceAll(re, replacement); - return newText; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/tools/RxNormConcept.java b/src/main/java/de.uzl.itcr/mimic2fhir/tools/RxNormConcept.java deleted file mode 100755 index 275dc68..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/tools/RxNormConcept.java +++ /dev/null @@ -1,40 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.tools; - -/** - * Represents a RxNorm-Concept with CUI and associated name - * @author Stefanie Ververs - * - */ -public class RxNormConcept { - private String cui; - private String name; - public String getCui() { - return cui; - } - public void setCui(String cui) { - this.cui = cui; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - - -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/tools/RxNormLookup.java b/src/main/java/de.uzl.itcr/mimic2fhir/tools/RxNormLookup.java deleted file mode 100755 index 3a60d7f..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/tools/RxNormLookup.java +++ /dev/null @@ -1,203 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.tools; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonString; - -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; - -/** - * Provide RxNorm-Lookup for NDC (National Drug Code) and GSN (Generic Sequence Number) - * Singleton: Use getInstance to get working object - * @author Stefanie Ververs - * - */ -public class RxNormLookup { - - private HashMap> rdxLookupNdc; - private HashMap> rdxLookupGsn; - - protected RxNormLookup() { - rdxLookupNdc = new HashMap>(); - rdxLookupGsn = new HashMap>(); - } - - /** - * Get RxNormConcepts for a NDC - * @param ndc National Drug Code - * @return List of RxNorm-Concept - */ - public List getRxNormForNdc(String ndc) { - if(rdxLookupNdc.containsKey(ndc)) { - return rdxLookupNdc.get(ndc); - }else { - List rdxNorm = findRxNormForNdc(ndc); - if(rdxNorm != null) { - rdxLookupNdc.put(ndc, rdxNorm); - return rdxNorm; - } - } - return null; - } - - /** - * Get RxNormConcepts for a GSN - * @param gsn Generic Sequence Number - * @return List of RxNorm-Concept - */ - public List getRxNormForGsn(String gsn) { - if(rdxLookupGsn.containsKey(gsn)) { - return rdxLookupGsn.get(gsn); - }else { - List rdxNorm = findRxNormForGsn(gsn); - if(rdxNorm != null) { - rdxLookupGsn.put(gsn, rdxNorm); - return rdxNorm; - } - } - return null; - } - - private List findRxNormForGsn(String gsn) { - String url = "https://rxnav.nlm.nih.gov/REST/rxcui.json?idtype=GCN_SEQNO&id=" + gsn; - return findRxNorm(url); - } - - private List findRxNormForNdc(String ndc) { - String url = "https://rxnav.nlm.nih.gov/REST/rxcui.json?idtype=NDC&id=" + ndc; - return findRxNorm(url); - } - - private List findRxNorm(String url) { - //use of RxNorm REST API https://rxnav.nlm.nih.gov/REST - - CloseableHttpClient httpclient = HttpClients.createDefault(); - - List rxNormList = new ArrayList(); - - HttpGet httpGet = new HttpGet(url); - - CloseableHttpResponse response = null; - try { - //GET - response = httpclient.execute(httpGet); - - //Response -> JSON Object - HttpEntity entity = response.getEntity(); - String jsonResponse = EntityUtils.toString(entity); - InputStream is = new ByteArrayInputStream( jsonResponse.getBytes() ); - - JsonReader jsonReader = Json.createReader(is); - JsonObject respObject = jsonReader.readObject(); - jsonReader.close(); - - JsonArray ids = respObject.getJsonObject("idGroup").getJsonArray("rxnormId"); - if(ids != null && !ids.isEmpty()) { - for(JsonString rxNorm : ids.getValuesAs(JsonString.class)) { - RxNormConcept rc = new RxNormConcept(); - rc.setCui(rxNorm.getString()); - //get Name: Separate Call - rc.setName(getNameForCui(rc.getCui())); - rxNormList.add(rc); - } - } - - EntityUtils.consume(entity); - } - catch(Exception ex){ - ex.printStackTrace(); - } - finally { - if(response != null) { - try { - response.close(); - } - catch(Exception ex) - {} - } - } - return rxNormList; - - } - - private String getNameForCui(String cui) { - CloseableHttpClient httpclient = HttpClients.createDefault(); - - String name = null; - String url = "https://rxnav.nlm.nih.gov/REST/rxcui/" + cui + "/property.json?propName=RxNorm%20Name"; - HttpGet httpGet = new HttpGet(url); - - CloseableHttpResponse response = null; - try { - //GET - response = httpclient.execute(httpGet); - - //Response -> JSON Object - HttpEntity entity = response.getEntity(); - String jsonResponse = EntityUtils.toString(entity); - InputStream is = new ByteArrayInputStream( jsonResponse.getBytes() ); - - JsonReader jsonReader = Json.createReader(is); - JsonObject respObject = jsonReader.readObject(); - jsonReader.close(); - - name = respObject.getJsonObject("propConceptGroup").getJsonArray("propConcept").get(0).asJsonObject().getString("propValue"); - - EntityUtils.consume(entity); - } - catch(Exception ex){ - ex.printStackTrace(); - } - finally { - if(response != null) { - try { - response.close(); - } - catch(Exception ex) - {} - } - } - return name; - } - - private static RxNormLookup instance = null; - - /** - * Singleton-Pattern: Get object reference to work with - * @return - */ - public static RxNormLookup getInstance() { - if(instance == null) { - instance = new RxNormLookup(); - } - return instance; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/work/BundleControl.java b/src/main/java/de.uzl.itcr/mimic2fhir/work/BundleControl.java deleted file mode 100755 index afa03d8..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/work/BundleControl.java +++ /dev/null @@ -1,133 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.work; - -import org.hl7.fhir.dstu3.model.Bundle; -import org.hl7.fhir.dstu3.model.Resource; -import org.hl7.fhir.dstu3.model.Bundle.BundleType; -import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; - -/** - * Handles bundle operations - * @author Stefanie Ververs - * - */ -public class BundleControl { - private Bundle transactionBundle; - private int numberOfResorces= 0; - private int internalBundleNumber = 0; - - /** - * creates a new transaction bundle - */ - public BundleControl() { - //new Bundle - transactionBundle = new Bundle(); - transactionBundle.setType(BundleType.TRANSACTION); - internalBundleNumber = 1; - } - - /** - * Number of resources currently present in bundle - * @return number of resources - */ - public int getNumberOfResorces() { - return numberOfResorces; - } - - /** - * Internal bundle number (how often bundle "reset"?) - * @return internal bundle number - */ - public int getInternalBundleNumber() { - return internalBundleNumber; - } - - /** - * Reset internal bundle number to 1 - */ - public void resetInternalBundleNumber() { - internalBundleNumber = 1; - } - - /** - * Reset bundle for "new" bundle with zero resources - */ - public void resetBundle() { - transactionBundle = new Bundle(); - transactionBundle.setType(BundleType.TRANSACTION); - numberOfResorces = 0; - internalBundleNumber++; - } - - /** - * Get the current bundle - * @return current bundle - */ - public Bundle getTransactionBundle() { - return transactionBundle; - } - - /** - * Add fhir resource without UUID to current bundle - * @param rToAdd fhir-resource to add - */ - public void addResourceToBundle(Resource rToAdd) - { - transactionBundle.addEntry() - .setResource(rToAdd) - .getRequest() - .setUrl(rToAdd.fhirType()) - .setMethod(HTTPVerb.POST); - - numberOfResorces++; - - } - - /** - * Add fhir resource with UUID to current bundle - * @param rToAdd fhir-resource to add - */ - public void addUUIDResourceToBundle(Resource rToAdd){ - transactionBundle.addEntry() - .setFullUrl(rToAdd.getId()) - .setResource(rToAdd) - .getRequest() - .setUrl(rToAdd.fhirType()) - .setMethod(HTTPVerb.POST); - - numberOfResorces++; - - } - - /** - * Conditional Create: - * Add fhir resource with UUID to current bundle and set condition (create if none exist) - * @param rToAdd fhir-resource to add - * @param condition search-condition to match - */ - public void addUUIDResourceWithConditionToBundle(Resource rToAdd, String condition) { - transactionBundle.addEntry() - .setFullUrl(rToAdd.getId()) - .setResource(rToAdd) - .getRequest() - .setUrl(rToAdd.fhirType()) - .setIfNoneExist(condition) - .setMethod(HTTPVerb.POST); - - numberOfResorces++; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/work/Config.java b/src/main/java/de.uzl.itcr/mimic2fhir/work/Config.java deleted file mode 100755 index d850d7c..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/work/Config.java +++ /dev/null @@ -1,318 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.work; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import javax.json.Json; -import javax.json.JsonObject; -import javax.json.JsonReader; - -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; - -/** - * Configuration for the transformation - * Contains Server, DB and other access information for mimiciii-postgres-db as well as fhir server - * @author Stefanie Ververs - * - */ -public class Config { - //private: FHIR-options - private String fhirServer; - private String fhirxmlFilePath; - - //private: FHIR-Server-Auth - private String ldapUser; - private String ldapPwd; - private String token; - private String authServer; - - private boolean authRequired; - - //private: POSTGRES-options - private String postgresServer; - private String userPostgres; - private String passPostgres; - private String portPostgres; - private String schemaPostgres; - private String dbnamePostgres; - - /** - * Path for FHIR-Server - * @return FHIRServer-Path - */ - public String getFhirServer() { - return fhirServer; - } - - /** - * Set FHIR-Server - * @param fhirServer FHIR-Server to be used - */ - public void setFhirServer(String fhirServer) { - this.fhirServer = fhirServer; - } - - /** - * Get LdapUser for Token-Request - * @return LdapUser - */ - public String getLdapUser() { - return ldapUser; - } - - /** - * Set LdapUser for Token-Request - * @param ldapUser - */ - public void setLdapUser(String ldapUser) { - this.ldapUser = ldapUser; - } - - /** - * Get LdapPassword for Token-Request - * @return LdapPassword - */ - public String getLdapPwd() { - return ldapPwd; - } - - /** - * Set LdapPassword for Token-Request - * @param ldapPwd - */ - public void setLdapPwd(String ldapPwd) { - this.ldapPwd = ldapPwd; - } - - /** - * Get Bearer-Token for Auth for this config - * @return Bearer-Token - */ - public String getToken() { - if(token == null || token.length() == 0) - { - token = getTokenFromAuthServer(); - } - return token; - } - - /** - * Set BearerToken for Auth, if received otherwise - * @param token - */ - public void setToken(String token) { - this.token = token; - } - - /** - * Get ServerPath for Token-Request - * @return serverPath - */ - public String getAuthServer() { - return authServer; - } - - /** - * Set ServerPath for Token-Request - * @param authServer - */ - public void setAuthServer(String authServer) { - this.authServer = authServer; - } - - /** - * Does the Fhir-Server require authentication? - * @return - */ - public boolean isAuthRequired() { - return authRequired; - } - - /** - * Set if the Fhir-Server requires authentication - * @param authRequired - */ - public void setAuthRequired(boolean authRequired) { - this.authRequired = authRequired; - } - - /** - * Get Postgres-DB-Server (e.g. localhost) - * @return Postgres-DB-Server - */ - public String getPostgresServer() { - return postgresServer; - } - - /** - * Set Postgres-DB-Server (e.g. localhost) - * @param postgresServer Server where postgres is installed - */ - public void setPostgresServer(String postgresServer) { - this.postgresServer = postgresServer; - } - - /** - * Postgres-DB-User (typically postgres) - * @return Postgres-DB-User - */ - public String getUserPostgres() { - return userPostgres; - } - - /** - * Set Postgres-DB-User (typically postgres) - * @param userPostgres Postgres-DB-user - */ - public void setUserPostgres(String userPostgres) { - this.userPostgres = userPostgres; - } - - /** - * Postgres-DB-password for user - * @return Postgres-DB-password for user - */ - public String getPassPostgres() { - return passPostgres; - } - - /** - * Set Postgres-DB-password for user - * @param passPostgres Postgres-DB-password for user - */ - public void setPassPostgres(String passPostgres) { - this.passPostgres = passPostgres; - } - - /** - * Postgres-DB Port - * @return Postgres-DB Port - */ - public String getPortPostgres() { - return portPostgres; - } - - /** - * Set Postgres-DB Port - * @param portPostgres Postgres-DB Port - */ - public void setPortPostgres(String portPostgres) { - this.portPostgres = portPostgres; - } - - /** - * Path (only folder) where FHIR-Bundle-XML is saved - * Name will be "bundle#.xml" - * @return Path - */ - public String getFhirxmlFilePath() { - return fhirxmlFilePath; - } - - /** - * Set Path (only folder) where FHIR-Bundle-XML should be saved - * @param fhirxmlFilePath the path (only folder) - */ - public void setFhirxmlFilePath(String fhirxmlFilePath) { - this.fhirxmlFilePath = fhirxmlFilePath; - } - - /** - * Get Mimic-Database-Name (e.g. mimic) - * @return DB-Name - */ - public String getDbnamePostgres() { - return dbnamePostgres; - } - - /** - * Set Mimic-Database-Name (e.g. mimic) - * @param dbnamePostgres Mimic-DB-Name - */ - public void setDbnamePostgres(String dbnamePostgres) { - this.dbnamePostgres = dbnamePostgres; - } - - /** - * Get Mimic-Database-Schema-Name (e.g. mimiciii) - * @return DB-Schema - */ - public String getSchemaPostgres() { - return schemaPostgres; - } - - /** - * Set Mimic-Database-Schema-Name (e.g. mimiciii) (if used) - * @param schemaPostgres DB-Schema - */ - public void setSchemaPostgres(String schemaPostgres) { - this.schemaPostgres = schemaPostgres; - } - - - private String getTokenFromAuthServer() { - String token = ""; - - CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(this.authServer); - CloseableHttpResponse response = null; - try { - //Datagram - StringEntity input = new StringEntity("{\"user\":\"" + this.ldapUser + "\",\"password\":\"" + this.ldapPwd + "\"}"); - - input.setContentType("application/json"); - httpPost.setEntity(input); - - //POST - response = httpclient.execute(httpPost); - - //Response -> JSON Object -> get Token - HttpEntity entity2 = response.getEntity(); - String jsonResponse = EntityUtils.toString(entity2); - InputStream is = new ByteArrayInputStream( jsonResponse.getBytes() ); - - JsonReader jsonReader = Json.createReader(is); - JsonObject tokenObject = jsonReader.readObject(); - jsonReader.close(); - - //Token in form "Bearer " -> we need only second part - token = tokenObject.getJsonObject("data").getString("token").split(" ")[1]; - - EntityUtils.consume(entity2); - } - catch(Exception ex){ - System.out.println(ex.getMessage()); - } - finally { - if(response != null) { - try { - response.close(); - } - catch(Exception ex) - {} - } - } - return token; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/work/ConnectDB.java b/src/main/java/de.uzl.itcr/mimic2fhir/work/ConnectDB.java deleted file mode 100755 index 669c765..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/work/ConnectDB.java +++ /dev/null @@ -1,542 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.work; - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.HashMap; - -import de.uzl.itcr.mimic2fhir.model.MAdmission; -import de.uzl.itcr.mimic2fhir.model.MCaregiver; -import de.uzl.itcr.mimic2fhir.model.MChartevent; -import de.uzl.itcr.mimic2fhir.model.MDiagnose; -import de.uzl.itcr.mimic2fhir.model.MLabevent; -import de.uzl.itcr.mimic2fhir.model.MNoteevent; -import de.uzl.itcr.mimic2fhir.model.MPatient; -import de.uzl.itcr.mimic2fhir.model.MPrescription; -import de.uzl.itcr.mimic2fhir.model.MProcedure; -import de.uzl.itcr.mimic2fhir.model.MTransfer; -import de.uzl.itcr.mimic2fhir.model.MWard; - -/** - * Connection, access and querys to postgresDB - * @author Stefanie Ververs - * - */ -public class ConnectDB { - private Config configuration; - private Connection connection = null; - - /** - * Create new DB-Connection with Config-Object - * @param configuration - */ - public ConnectDB(Config configuration) { - - this.configuration = configuration; - //Do some stuff to do DB-Connection.. - - try { - Class.forName("org.postgresql.Driver"); - - } catch (ClassNotFoundException e) { - - e.printStackTrace(); - return; - } - - this.connection = null; - - //Schema-Construction, if necessary: - String schema = ""; - if(this.configuration.getSchemaPostgres() != null && this.configuration.getSchemaPostgres().length() > 0) { - schema = "?currentSchema=" + this.configuration.getSchemaPostgres(); - } - - try { - connection = DriverManager.getConnection( - "jdbc:postgresql://" + this.configuration.getPostgresServer() + ":" - + this.configuration.getPortPostgres() + "/" - + this.configuration.getDbnamePostgres() + schema, - this.configuration.getUserPostgres(), - this.configuration.getPassPostgres()); - - } catch (SQLException e) { - e.printStackTrace(); - return; - - } - } - - /** - * How many patients in MIMICIII.Patients? - * @return number of patients - */ - public int getNumberOfPatients() { - String query = "SELECT COUNT(*) FROM PATIENTS"; - int count = 0; - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - count = rs.getInt(1); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return count; - } - - /** - * Get first patient in Mimic-Patients-Table - * @return filled MPatient-Object - */ - public MPatient getFirstPatient() { - String query = "SELECT * FROM PATIENTS ORDER BY ROW_ID LIMIT 1"; - return getOnePatientFromDb(query); - } - - /** - * Get patient by rowId - * @param rowId rowId of patient in patients-Table - * @return filled MPatient-Object - */ - public MPatient getPatientByRowId(int rowId) { - String query = "SELECT * FROM PATIENTS WHERE ROW_ID = " + rowId; - return getOnePatientFromDb(query); - } - - private MPatient getOnePatientFromDb(String query) { - - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - if (rs.next()) { - MPatient mPat = new MPatient(); - //SUBJECT_ID - mPat.setPatientSubjectId(rs.getString(2)); - //DOB - mPat.setBirthDate(rs.getDate(4)); - //GENDER - mPat.setGender(rs.getString(3)); - //DOD - mPat.setDeathDate(rs.getDate(5)); - - //Admissions - getPatientAdmissions(mPat); - - return mPat; - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return null; - } - - private void getPatientAdmissions(MPatient pat) { - String query = "SELECT * FROM ADMISSIONS WHERE SUBJECT_ID = " + pat.getPatientSubjectId(); - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - while (rs.next()) { - MAdmission mAdm = new MAdmission(); - mAdm.setAdmissionId(rs.getString(3)); - - //Times - mAdm.setAdmissionTime(rs.getDate(4)); - mAdm.setDischargeTime(rs.getDate(5)); - - //Type - mAdm.setAdmissionType(rs.getString(7)); - - //DschLoc - mAdm.setDischargeLocation(rs.getString(9)); - - mAdm.setMaritalStatus(rs.getString(13)); - mAdm.setLanguage(rs.getString(11)); - mAdm.setReligion(rs.getString(12)); - mAdm.setAdmissionLocation(rs.getString(8)); - - //Diagnoses - getDiagnoses(pat.getPatientSubjectId(), mAdm);; - - //Procedures - getProcedures(pat.getPatientSubjectId(), mAdm); - - //Chartevents - getChartEvents(mAdm, pat.getPatientSubjectId()); - - //Labevents - getLabEvents(mAdm, pat.getPatientSubjectId()); - - //Noteevents - getNoteEvents(mAdm, pat.getPatientSubjectId()); - - //Prescriptions - getPrecriptions(mAdm, pat.getPatientSubjectId()); - - //Transfers - getTransfers(mAdm, pat.getPatientSubjectId()); - - pat.addAdmission(mAdm); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void getChartEvents(MAdmission admission, String patientSubjId) { - String query = "SELECT C.SUBJECT_ID, C.HADM_ID, C.CHARTTIME, C.CGID, C.VALUE, C.VALUENUM, C.VALUEUOM, D.LABEL " + - "FROM CHARTEVENTS C " + - "INNER JOIN D_ITEMS D ON C.ITEMID = D.ITEMID " + - "WHERE C.HADM_ID= " + admission.getAdmissionId(); - - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - while (rs.next()) { - - //Value = null ausschließen -> kein Wert - if(rs.getObject(5) != null) { - - MChartevent event = new MChartevent(); - - //Rekord-Datum - event.setRecordDate(rs.getDate(3)); - - //CareGiver - event.setCareGiverId(rs.getInt(4)); - - //Type (Item) - event.setMeasurementType(rs.getString(8)); - - //Value + ValueNum - event.setValue(rs.getString(5)); - if(rs.getObject(6) != null) { - event.setNumValue(rs.getDouble(6)); - } - - //Unit - if(rs.getObject(7) != null) { - event.setUnit(rs.getString(7)); - } - - admission.addEvent(event); - - } - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void getLabEvents(MAdmission admission, String patientSubjId) { - String query = "SELECT L.SUBJECT_ID, L.HADM_ID, L.CHARTTIME, L.VALUE, L.VALUENUM, L.VALUEUOM, L.FLAG, D.LABEL, D.FLUID, D.LOINC_CODE " + - "FROM LABEVENTS L " + - "INNER JOIN D_LABITEMS D ON L.ITEMID = D.ITEMID " + - "WHERE L.SUBJECT_ID = " + patientSubjId + " AND L.HADM_ID= " + admission.getAdmissionId(); - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - - while (rs.next()) { - //Value = null ausschließen -> kein Wert - if(rs.getObject(4) != null) { - - MLabevent event = new MLabevent(); - - //Rekord-Datum - event.setAcquisitionDate(rs.getDate(3)); - - //Type (Item) - event.setMeasurementType(rs.getString(8)); - - //Fluid - event.setFluid(rs.getString(9)); - - //Loinc-Code - if(rs.getObject(10) != null) { - event.setLoinc(rs.getString(10)); - } - - //Value + ValueNum - event.setValue(rs.getString(4)); - if(rs.getObject(5) != null) { - event.setNumValue(rs.getDouble(5)); - } - - //Unit - if(rs.getObject(6) != null) { - event.setUnit(rs.getString(6)); - } - - //Flag - //"delta" - might mean both, not considered - if(rs.getObject(7) != null && rs.getString(7) == "abnormal") { - event.setAbnormal(true); - } - - admission.addLabEvent(event); - - } - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void getNoteEvents(MAdmission admission, String patientSubjId) { - String query = "SELECT * " + - "FROM NOTEEVENTS " + - "WHERE SUBJECT_ID = " + patientSubjId + " AND HADM_ID= " + admission.getAdmissionId(); - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - - boolean isError = rs.getString(10) == "1"; - - MNoteevent event = new MNoteevent(); - - event.setHasError(isError); - - //Charttime (incl. date; 5) and Chartdate (4) - two columns.. - if(rs.getObject(5) != null) { - event.setChartdate(rs.getDate(5)); - } - else{ - event.setChartdate(rs.getDate(4)); - } - - //might be null - event.setCaregiverId(rs.getInt(9)); - - event.setCategory(rs.getString(7)); - event.setDescription(rs.getString(8)); - - event.setText(rs.getString(11)); - - admission.addNoteEvent(event); - - } - - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void getDiagnoses(String patId, MAdmission adm) { - String query = "SELECT *" + - " FROM diagnoses_icd d" + - " INNER JOIN d_icd_diagnoses i ON d.icd9_code = i.icd9_code" + - " WHERE d.subject_id = " + patId + "AND d.hadm_id = " + adm.getAdmissionId() + - " ORDER BY d.seq_num"; - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - MDiagnose mDiag = new MDiagnose(); - mDiag.setIcd9Code(rs.getString(5)); - mDiag.setShortTitle(rs.getString(8)); - mDiag.setLongTitle(rs.getString(9)); - mDiag.setSeqNumber(rs.getInt(4)); - - adm.addDiagnose(mDiag); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void getProcedures(String patId, MAdmission adm) { - String query = "SELECT *" + - " FROM procedures_icd p" + - " INNER JOIN d_icd_procedures i ON p.icd9_code = i.icd9_code" + - " WHERE p.subject_id = " + patId + "AND p.hadm_id = " + adm.getAdmissionId() + - " ORDER BY p.seq_num"; - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - MProcedure mProc = new MProcedure(); - mProc.setIcd9Code(rs.getString(5)); - mProc.setShortTitle(rs.getString(8)); - mProc.setLongTitle(rs.getString(9)); - mProc.setSeqNumber(rs.getInt(4)); - - adm.addProcedure(mProc); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Get dictionary with all caregivers - Key: Id, Value: Caregiver-Object - * @return dictionary - */ - public HashMap getCaregivers() - { - String query = "SELECT * FROM caregivers"; - HashMap caregivers = new HashMap(); - - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - MCaregiver cg = new MCaregiver(); - cg.setCaregiverId(rs.getInt(2)); - cg.setLabel(rs.getString(3)); - cg.setDescription(rs.getString(4)); - - caregivers.put(cg.getCaregiverId(),cg); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return caregivers; - } - - private void getPrecriptions(MAdmission admission, String patientSubjId) { - String query = "SELECT * " + - "FROM PRESCRIPTIONS " + - "WHERE SUBJECT_ID = " + patientSubjId + " AND HADM_ID= " + admission.getAdmissionId(); - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - MPrescription pres = new MPrescription(); - - pres.setStart(rs.getDate(5)); - pres.setEnd(rs.getDate(6)); - - pres.setDrugtype(rs.getString(7)); - pres.setDrug(rs.getString(8)); - pres.setDrugNamePoe(rs.getString(9)); - pres.setDrugNameGeneric(rs.getString(10)); - - pres.setFormularyDrugCd(rs.getString(11)); - pres.setGsn(rs.getString(12)); - pres.setNdc(rs.getString(13)); - - pres.setProdStrength(rs.getString(14)); - pres.setDoseValRx(rs.getString(15)); - pres.setDoseUnitRx(rs.getString(16)); - - pres.setFormValDisp(rs.getString(17)); - pres.setFormUnitDisp(rs.getString(18)); - - pres.setRoute(rs.getString(19)); - - admission.addPrescription(pres); - - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void getTransfers(MAdmission admission, String patientSubjId) { - String query = "SELECT * " + - "FROM TRANSFERS " + - "WHERE SUBJECT_ID = " + patientSubjId + " AND HADM_ID= " + admission.getAdmissionId(); - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - int index = 0; - while (rs.next()) { - index++; - MTransfer t = new MTransfer(); - - t.setTransferId(rs.getInt(3) + "-" + index); - - t.setEventType(rs.getString(6)); - - t.setPrevUnit(rs.getString(7)); - t.setCurrUnit(rs.getString(8)); - - t.setPrevWard(rs.getInt(9)); - t.setCurrWard(rs.getInt(10)); - - t.setIntime(rs.getDate(11)); - t.setOuttime(rs.getDate(12)); - - t.setLengthOfStay(rs.getDouble(13)); - - admission.addTransfer(t); - - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Get dictionary with all locations = wards, key = wardId, value: MWard-Object - * @return dictionary - */ - public HashMap getLocations() { - String query = "SELECT DISTINCT curr_wardid, curr_careunit FROM transfers"; - HashMap wards = new HashMap(); - - PreparedStatement statement; - try { - statement = connection.prepareStatement(query); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - MWard ward = new MWard(); - ward.setWardId(rs.getInt(1)); - ward.setCareUnit(rs.getString(2)); - - wards.put(ward.getWardId(),ward); - } - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - return wards; - } -} diff --git a/src/main/java/de.uzl.itcr/mimic2fhir/work/FHIRComm.java b/src/main/java/de.uzl.itcr/mimic2fhir/work/FHIRComm.java deleted file mode 100755 index 3c06f47..0000000 --- a/src/main/java/de.uzl.itcr/mimic2fhir/work/FHIRComm.java +++ /dev/null @@ -1,157 +0,0 @@ -/*********************************************************************** -Copyright 2018 Stefanie Ververs, University of Lübeck - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -/***********************************************************************/ -package de.uzl.itcr.mimic2fhir.work; - -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Date; - -import org.hl7.fhir.dstu3.model.Bundle; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; -import ca.uhn.fhir.rest.client.apache.GZipContentInterceptor; -import ca.uhn.fhir.rest.client.api.IGenericClient; -import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; - -/** - * Communication and Functions for and with FHIR - * @author Stefanie Ververs - * - */ -public class FHIRComm { - private FhirContext ctx; - private IGenericClient client; - - private Config configuration; - - /** - * Create new Fhir-Context with config-Object - * @param config config-Object - */ - public FHIRComm(Config config) { - this.configuration = config; - ctx = FhirContext.forDstu3(); - - // Use the narrative generator - ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); - client = ctx.newRestfulGenericClient(configuration.getFhirServer()); - - if(this.configuration.isAuthRequired()) - { - //Authorization - BearerTokenAuthInterceptor authInterceptor = new BearerTokenAuthInterceptor(this.configuration.getToken()); - client.registerInterceptor(authInterceptor); - } - - // Set how long to block for individual read/write operations (in ms) - ctx.getRestfulClientFactory().setSocketTimeout(1500 * 1000); - - //Gzip output content - client.registerInterceptor(new GZipContentInterceptor()); - } - - /** - * Print bundle as xml to console - * @param transactionBundle bundle to print - */ - public void printBundleAsXml(Bundle transactionBundle) { - System.out.println(getBundleAsString(transactionBundle)); - - } - - /** - * Save FHIR-Ressource-Bundle as xml to location specified in Config - * @param number Number of bundle. Use 0, if no number in file name wanted ("bundle.xml") - * @param transactionBundle bundle to print to file - */ - public void printBundleAsXmlToFile(String number, Bundle transactionBundle) { - try { - String xml = getBundleAsString(transactionBundle); - - String fullFilePath; - if(!number.equals("0")) { - fullFilePath = configuration.getFhirxmlFilePath() + "\\bundle" + number + ".xml"; - } - else{ - fullFilePath = configuration.getFhirxmlFilePath() + "\\bundle.xml"; - } - - Path path = Paths.get(fullFilePath); - byte[] strToBytes = xml.getBytes(); - - //Write xml as file - Files.write(path, strToBytes); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - - - /** - * Send complete bundle to fhir-server - * @param transactionBundle bundle to push to server - */ - public void bundleToServer(Bundle transactionBundle) - { - Bundle resp = client.transaction().withBundle(transactionBundle).execute(); - - //Log response - //writeToFile(ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp)); - } - - private void writeToFile(String text) { - try { - - String fullFilePath = configuration.getFhirxmlFilePath() + "\\log" + new Date().getTime() +".xml"; - - Path path = Paths.get(fullFilePath); - byte[] strToBytes = text.getBytes(); - - //Write xml as file - Files.write(path, strToBytes); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - /** - * Get a bundle as xml string representation - * @param bundle bundle to transform into a string - * @return bundle xml string - */ - public String getBundleAsString(Bundle bundle) { - return ctx.newXmlParser() - .setPrettyPrint(true) - .encodeResourceToString(bundle); - } - - /** - * Parse xml string to bundle - * @param bundle bundle as xml string - * @return bundle as Bundle - */ - public Bundle getBundleFromString(String bundle) { - return (Bundle) ctx.newXmlParser() - .setPrettyPrint(true) - .parseResource(bundle); - } - -}