[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openmrs-svn
Subject:    [30920] openmrs-modules/chica/branches/hl7 form export/src/org/openmrs/ module/chica: chica hl7 form
From:       svn-noreply () openmrs ! org
Date:       2014-09-24 20:14:12
Message-ID: 20140924201412.E322C401CC () openmrs ! osuosl ! org
[Download RAW message or body]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[30920] openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica: chica hl7 form export  * set up export \
states</title> </head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: \
verdana,arial,helvetica,sans-serif; font-size: 10pt;  } #msg dl a { font-weight: \
bold} #msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: \
bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: \
6px; } #logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em \
0; } #logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg \
h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; } \
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; \
} #logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: \
-1.5em; padding-left: 1.5em; } #logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em \
1em 0 1em; background: white;} #logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid \
#fa0; border-bottom: 1px solid #fa0; background: #fff; } #logmsg table th { \
text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted \
#fa0; } #logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: \
0.2em 0.5em; } #logmsg table thead th { text-align: center; border-bottom: 1px solid \
#fa0; } #logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: \
6px; } #patch { width: 100%; }
#patch h4 {font-family: \
verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
 #patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, \
#patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins \
{background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del \
{background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, \
                .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd>30920</dd>
<dt>Author</dt> <dd>msheley</dd>
<dt>Date</dt> <dd>2014-09-24 20:14:12 +0000 (Wed, 24 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>chica hl7 form export  * set up export states</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#openmrsmoduleschicabrancheshl7formexportsrcorgopenmrsmodulechicaactionLoadHL7ExportQueuejava">openmrs-modules/chica/branches/hl7 \
form export/src/org/openmrs/module/chica/action/LoadHL7ExportQueue.java</a></li> \
<li><a href="#openmrsmoduleschicabrancheshl7formexportsrcorgopenmrsmodulechicahl7mckessonHL7ExportTaskjava">openmrs-modules/chica/branches/hl7 \
form export/src/org/openmrs/module/chica/hl7/mckesson/HL7ExportTask.java</a></li> \
<li><a href="#openmrsmoduleschicabrancheshl7formexportsrcorgopenmrsmodulechicahl7mckessonHL7MessageConstructorjava">openmrs-modules/chica/branches/hl7 \
form export/src/org/openmrs/module/chica/hl7/mckesson/HL7MessageConstructor.java</a></li>
 </ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="openmrsmoduleschicabrancheshl7formexportsrcorgopenmrsmodulechicaactionLoadHL7ExportQueuejava"></a>
 <div class="modfile"><h4>Modified: openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/action/LoadHL7ExportQueue.java (30919 => \
30920)</h4> <pre class="diff"><span>
<span class="info">--- openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/action/LoadHL7ExportQueue.java	2014-09-24 \
                19:18:40 UTC (rev 30919)
+++ openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/action/LoadHL7ExportQueue.java	2014-09-24 \
20:14:12 UTC (rev 30920) </span><span class="lines">@@ -84,7 +84,7 @@
</span><span class="cx"> 					jitExport.setVoided(false);
</span><span class="cx"> 					jitExport.setStatus(INIT);
</span><span class="cx"> \
jitExport.setPatientStateId(patientState.getPatientStateId());; \
</span><del>-					jitExport.setExportType(&quot;JIT&quot;); \
</del><ins>+					jitExport.setExportType(&quot;IMAGE&quot;); </ins><span class="cx"> \
 </span><span class="cx"> 				}
</span><span class="cx"> 			
</span><span class="lines">@@ -101,31 +101,14 @@
</span><span class="cx"> 				exportVitals.setVoided(false);
</span><span class="cx"> 				exportVitals.setStatus(INIT);
</span><span class="cx"> \
exportVitals.setPatientStateId(patientState.getPatientStateId()); \
</span><del>-				exportVitals.setExportType(&quot;VITALS&quot;); \
</del><ins>+				exportVitals.setExportType(&quot;OBS&quot;); </ins><span class="cx"> \
chicaService.saveChicaHL7Export(exportVitals); </span><span class="cx"> 				
</span><del>-			}
-			
-			
-			//Export PWS obs, PWS image,  PSF image
-			if (patientState.getState().getName().equals(&quot;Export POC&quot;)) {
-				
-				ChicaHL7Export exportPWSObs = new ChicaHL7Export();
-				exportPWSObs.setDateInserted(new Date());
-				exportPWSObs.setEncounterId(encounterId);
-				exportPWSObs.setSessionId(sessionId);
-				exportPWSObs.setVoided(false);
-				exportPWSObs.setStatus(INIT);
-				exportPWSObs.setPatientStateId(patientState.getPatientStateId());;
-				exportPWSObs.setExportType(&quot;PWS OBS&quot;);
-				chicaService.saveChicaHL7Export(exportPWSObs);
-			
-			
</del><span class="cx"> 				//Export PSF
</span><span class="cx"> 				
</span><span class="cx"> 				// Find the form instance for the PSF for the encounter \
to see if it was populated using paper or not.   </span><span class="cx"> 				// If \
it was populated through some medium other than paper, there will be no tiff to \
export. </span><del>-				boolean paperImage = true;
</del><ins>+				
</ins><span class="cx"> 				List&lt;PatientState&gt; patientStates = \
chirdlutilbackportsService.getPatientStatesWithFormInstances( </span><span \
class="cx"> 						&quot;PSF&quot;, encounterId); </span><span class="cx"> 				
</span><span class="lines">@@ -144,26 +127,41 @@
</span><span class="cx"> 				
</span><span class="cx"> 					FormInstanceAttributeValue fiav = \
chirdlutilbackportsService.getFormInstanceAttributeValue( </span><span class="cx"> \
formId, formInstanceId, formLocationId, &quot;medium&quot;); </span><ins>+					
</ins><span class="cx"> 					if (fiav != null &amp;&amp; \
!&quot;paper&quot;.equalsIgnoreCase(fiav.getValue())) { </span><del>-						paperImage \
= false; </del><ins>+						ChicaHL7Export exportPSF = new ChicaHL7Export();
+						exportPSF.setDateInserted(new Date());
+						exportPSF.setEncounterId(encounterId);
+						exportPSF.setSessionId(sessionId);
+						exportPSF.setVoided(false);
+						exportPSF.setStatus(INIT);
+						exportPSF.setPatientStateId(patientState.getPatientStateId());
+						exportPSF.setExportType(&quot;IMAGE&quot;);
+						chicaService.saveChicaHL7Export(exportPSF);
</ins><span class="cx"> 					}
</span><span class="cx"> 				
</span><del>-
-				if (paperImage) {
-					ChicaHL7Export exportPSF = new ChicaHL7Export();
-					exportPSF.setDateInserted(new Date());
-					exportPSF.setEncounterId(encounterId);
-					exportPSF.setSessionId(sessionId);
-					exportPSF.setVoided(false);
-					exportPSF.setStatus(INIT);
-					exportPSF.setPatientStateId(patientState.getPatientStateId());
-					exportPSF.setExportType(&quot;PSF IMAGE&quot;);
-					chicaService.saveChicaHL7Export(exportPSF);
-				}
</del><ins>+			}
</ins><span class="cx"> 			
</span><ins>+			
+			//Export PWS obs, PWS image,  PSF image
+			if (patientState.getState().getName().equals(&quot;Export POC&quot;)) {
+				
+				ChicaHL7Export exportPWSObs = new ChicaHL7Export();
+				exportPWSObs.setDateInserted(new Date());
+				exportPWSObs.setEncounterId(encounterId);
+				exportPWSObs.setSessionId(sessionId);
+				exportPWSObs.setVoided(false);
+				exportPWSObs.setStatus(INIT);
+				exportPWSObs.setPatientStateId(patientState.getPatientStateId());;
+				exportPWSObs.setExportType(&quot;OBS&quot;);
+				chicaService.saveChicaHL7Export(exportPWSObs);
+			
+			
+				
+			
</ins><span class="cx"> 				//Export PWS
</span><span class="cx"> 				
</span><del>-				patientStates = \
chirdlutilbackportsService.getPatientStatesWithFormInstances( \
</del><ins>+				List&lt;PatientState&gt; patientStates = \
chirdlutilbackportsService.getPatientStatesWithFormInstances( </ins><span class="cx"> \
&quot;PWS&quot;, encounterId); </span><span class="cx"> 				if (patientStates != null \
&amp;&amp; !patientStates.isEmpty()) { </span><span class="cx"> 					
</span><span class="lines">@@ -178,13 +176,11 @@
</span><span class="cx"> 				}
</span><span class="cx"> 				
</span><span class="cx"> 				//Do not export if medium is not paper
</span><del>-				fiav = chirdlutilbackportsService.getFormInstanceAttributeValue(
</del><ins>+				
+				FormInstanceAttributeValue fiav = \
chirdlutilbackportsService.getFormInstanceAttributeValue( </ins><span class="cx"> \
formId, formInstanceId, formLocationId, &quot;medium&quot;); </span><span class="cx"> \
if (fiav != null &amp;&amp; !&quot;paper&quot;.equalsIgnoreCase(fiav.getValue())) { \
</span><del>-					paperImage = false; </del><span class="cx"> 					
</span><del>-					if (paperImage){
-						
</del><span class="cx"> 						ChicaHL7Export exportpws = new ChicaHL7Export();
</span><span class="cx"> 						exportpws.setDateInserted(new Date());
</span><span class="cx"> 						exportpws.setEncounterId(encounterId);
</span><span class="lines">@@ -192,12 +188,9 @@
</span><span class="cx"> 						exportpws.setVoided(false);
</span><span class="cx"> 						exportpws.setStatus(INIT);
</span><span class="cx"> \
exportpws.setPatientStateId(patientState.getPatientStateId()); \
</span><del>-						exportpws.setExportType(&quot;PWS IMAGE&quot;); \
</del><ins>+						exportpws.setExportType(&quot;IMAGE&quot;); </ins><span class="cx"> \
chicaService.saveChicaHL7Export(exportpws); </span><del>-						
-					}
-
-
</del><ins>+					
</ins><span class="cx"> 				}
</span><span class="cx"> 			}
</span><span class="cx"> 			
</span></span></pre></div>
<a id="openmrsmoduleschicabrancheshl7formexportsrcorgopenmrsmodulechicahl7mckessonHL7ExportTaskjava"></a>
 <div class="modfile"><h4>Modified: openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/hl7/mckesson/HL7ExportTask.java (30919 => \
30920)</h4> <pre class="diff"><span>
<span class="info">--- openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/hl7/mckesson/HL7ExportTask.java	2014-09-24 \
                19:18:40 UTC (rev 30919)
+++ openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/hl7/mckesson/HL7ExportTask.java	2014-09-24 \
20:14:12 UTC (rev 30920) </span><span class="lines">@@ -278,13 +278,28 @@
</span><span class="cx"> 
</span><span class="cx"> 			//construct the message
</span><span class="cx"> 			HL7MessageConstructor constructor = new \
HL7MessageConstructor(configFileLocation); </span><del>-			String message = \
                constructor.createMessage(chicaHl7Export);
-
</del><ins>+			String message = null;
</ins><span class="cx"> 			Date ackDate = null;
</span><ins>+			
+				try {
+					message = constructor.createMessage(chicaHl7Export);
+				} catch (HL7Exception e) {
+					sessionId = chicaHl7Export.getSessionId();
+					chicaHl7Export.setStatus(chicaService.getChicaExportStatusByName(&quot;Message \
Construction Error&quot;)); +					chicaHl7Export.setDateProcessed(new Date());
+					logExportError(&quot;Error during message contruction.&quot;, e, \
openmrsEncounter, sessionId); +					chicaService.saveChicaHL7Export(chicaHl7Export);
+					saveMessageFile(message, encId, &quot;ERROR&quot;);
+					socketHandler.closeSocket();
+					Context.closeSession();
+					return false;
+				}
+			
+			
</ins><span class="cx"> 
</span><span class="cx"> 			// Send Message
</span><ins>+			
</ins><span class="cx"> 			try {
</span><del>-
</del><span class="cx"> \
chicaHl7Export.setStatus(chicaService.getChicaExportStatusByName(&quot;Sending&quot;));
 </span><span class="cx"> 				chicaHl7Export.setDateProcessed(new Date());
</span><span class="cx"> 				chicaService.saveChicaHL7Export(chicaHl7Export);
</span></span></pre></div>
<a id="openmrsmoduleschicabrancheshl7formexportsrcorgopenmrsmodulechicahl7mckessonHL7MessageConstructorjava"></a>
 <div class="modfile"><h4>Modified: openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/hl7/mckesson/HL7MessageConstructor.java (30919 => \
30920)</h4> <pre class="diff"><span>
<span class="info">--- openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/hl7/mckesson/HL7MessageConstructor.java	2014-09-24 \
                19:18:40 UTC (rev 30919)
+++ openmrs-modules/chica/branches/hl7 form \
export/src/org/openmrs/module/chica/hl7/mckesson/HL7MessageConstructor.java	2014-09-24 \
20:14:12 UTC (rev 30920) </span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx"> import org.w3c.dom.Node;
</span><span class="cx"> import org.w3c.dom.NodeList;
</span><span class="cx"> 
</span><ins>+import ca.uhn.hl7v2.HL7Exception;
</ins><span class="cx"> import ca.uhn.hl7v2.app.ApplicationException;
</span><span class="cx"> import ca.uhn.hl7v2.model.DataTypeException;
</span><span class="cx"> import ca.uhn.hl7v2.model.v25.segment.MSH;
</span><span class="lines">@@ -90,10 +91,15 @@
</span><span class="cx">  */
</span><span class="cx"> public class HL7MessageConstructor extends \
org.openmrs.module.sockethl7listener.HL7MessageConstructor { </span><span class="cx"> \
 </span><del>-	String formInstance = null;
</del><span class="cx"> 	private Log log = LogFactory.getLog(this.getClass());
</span><span class="cx"> 	private Properties properties;
</span><span class="cx"> 	private String configFileLocation;
</span><ins>+	private  String EXPORT_TYPE_PRESCREEN_OBS = &quot;PRESCREEN OBS&quot;;
+	private String EXPORT_TYPE_VITALS = &quot;VITALS&quot;;
+	private  String EXPORT_TYPE_ENCOUNTER_OBS = &quot;ENCOUNTER OBS&quot;;
+	private  String EXPORT_TYPE_PSF_IMAGE = &quot;PSF IMAGE&quot;;
+	private  String EXPORT_TYPE_PWS_IMAGE = &quot;PWS IMAGE&quot;;
+	private  String EXPORT_TYPE_JIT_IMAGE = &quot;JIT IMAGE&quot;;
</ins><span class="cx"> 	
</span><span class="cx"> 	public HL7MessageConstructor() {
</span><span class="cx"> 
</span><span class="lines">@@ -112,61 +118,269 @@
</span><span class="cx"> 	}
</span><span class="cx"> 	
</span><span class="cx"> 	
</span><del>-	public PV1 AddSegmentPV1(Encounter enc)  {
-
-		PV1 pv1 = super.AddSegmentPV1(enc);
-		ChirdlUtilBackportsService cubackportsService = \
Context.getService(ChirdlUtilBackportsService.class); </del><ins>+	public String \
createMessage(ChicaHL7Export  export) throws HL7Exception{ +		String message = null;
+		String exportType = export.getExportType();
+		String stateName = null;
</ins><span class="cx"> 	
</span><span class="cx"> 		try {
</span><ins>+			
+			EncounterService encounterService = Context.getEncounterService();
+			ChirdlUtilBackportsService chirdlutilbackportsService = \
Context.getService(ChirdlUtilBackportsService.class); +			
+			// Construct message MSH, PID, and PV1
+			//export get state
+			Encounter encounter = encounterService.getEncounter(export.getEncounterId());
</ins><span class="cx"> 		
</span><ins>+			Patient patient = encounter.getPatient();
+			AddSegmentMSH( encounter, export.getExportType());
+			AddSegmentPID(patient);
+			AddSegmentPV1(encounter);
</ins><span class="cx"> 		
</span><del>-			Location location = enc.getLocation();
-			LocationAttributeValue value = \
                cubackportsService.getLocationAttributeValue(location.getId(), \
                &quot;hl7Name&quot;);
-			if (value != null) {
-				pv1.getAssignedPatientLocation().getPointOfCare().setValue(value.getValue());
-				pv1.getAssignedPatientLocation().getFacility().getNamespaceID().setValue(value.getValue());
                
-			}
</del><ins>+		
+			Integer patientStateId = export.getPatientStateId();
+			PatientState patientState = \
chirdlutilbackportsService.getPatientState(patientStateId); +			stateName = \
patientState.getState().getName(); +		
+			// When we send vitals, we send other PSF obs also.
+			// if vitals, add the obs block
</ins><span class="cx"> 			
</span><ins>+			if (exportType.equals(&quot;IMAGE&quot;)){
+				addOBXForTiff( export);
+			} 
</ins><span class="cx"> 			
</span><del>-		} catch (Exception e) {
-			log.error(Util.getStackTrace(e));
</del><ins>+			if (exportType.equals(&quot;OBS&quot;)){
+				if (stateName.equalsIgnoreCase(&quot;exportVitals&quot;) ){
+					addPreScreenObs(export);
+				}
+				if (stateName.equalsIgnoreCase(&quot;exportPOC&quot;)){
+					addEncounterObs( export);
+				}
+			} 
+		}catch(Exception e){
+			throw new HL7Exception(&quot;Error constructing message for state &quot; + \
stateName   +					+ &quot; exportType  =  &quot; + exportType , 
+					HL7Exception.APPLICATION_INTERNAL_ERROR);
</ins><span class="cx"> 		}
</span><del>-
-
-		return pv1;
-
</del><ins>+		
+		return message;
</ins><span class="cx"> 	}
</span><span class="cx"> 
</span><del>-	public String getFormInstance() {
-		return formInstance;
</del><ins>+	private void addSegmentOBR(Encounter openmrsEncounter,
+			String batteryName, int orderRep) {
+	
+		ConceptService cs = Context.getConceptService();
+	
+		String batteryId = null;
+	
+		if (batteryName != null) {
+			Concept rmrsConcept = cs.getConceptByName(batteryName);
+			if (rmrsConcept == null ){
+				log.error(&quot;Unable to add OBR to export HL7 because the OBR battery name is \
null&quot;); +				return;
+			}
+			batteryId = getRMRSCodeFromConcept(rmrsConcept);
+		}
+		OBR obr = super.AddSegmentOBR(openmrsEncounter, batteryId, batteryName, orderRep);
+		
+	
</ins><span class="cx"> 	}
</span><span class="cx"> 
</span><del>-	public void setFormInstance(String formInstance) {
-		this.formInstance = formInstance;
-	}
-	
-	public void setAssignAuthority(PatientIdentifier pi) {
</del><ins>+	/**
+	 * Add the vitals and other psf observations to the hl7 message. 
+	 * Get list of observations from concepts in the concept sets.
+	 * Get the RMRS name and code for the CHICA concept using ConceptMap
+	 * 
+	 * @param encounter
+	 * @param constructor
+	 * @param chicaHl7Export
+	 * @return
+	 * @throws IOException
+	 */
+	private boolean addPreScreenObs( ChicaHL7Export chicaHl7Export) throws \
HL7Exception{ </ins><span class="cx"> 		
</span><del>-		super.setAssignAuthority(pi);
</del><ins>+		try {
+			AdministrationService adminService = Context.getAdministrationService();
+			EncounterService encounterService = Context.getEncounterService();
+			ConceptService conceptService = Context.getConceptService();
+			ChicaService chicaService = Context.getService(ChicaService.class);
+			ObsService obsService = Context.getObsService();
+			Integer encounterId = chicaHl7Export.getEncounterId();
+			Encounter encounter = encounterService.getEncounter(encounterId);
+			
+	
+			//use concept map table to look up 
+			Concept pedClDataConcept = conceptService.getConceptByName(&quot;PED CL DATA \
CHICA&quot;); +			List&lt;Concept&gt; concepts = \
conceptService.getConceptsByConceptSet(pedClDataConcept); +			List&lt;Encounter&gt; \
encounters = new ArrayList(); +			encounters.add(encounter);
+			List&lt;Obs&gt; pedsClObs = obsService.getObservations(null, encounters, \
concepts, null, null, null, null, null, null, null, null, false); +	
+	
+			//Careweb concepts for allergies uses a different text than vitals and pain obs
+			Concept pedsObsDifferentSet = conceptService.getConceptByName(&quot;MEDICAL \
RECORD FILE OBSERVATIONS CHICA&quot;); +			List&lt;Concept&gt; PSFConcepts = \
conceptService.getConceptsByConceptSet(pedsObsDifferentSet); +			;
+			encounters.add(encounter);
+			List&lt;Obs&gt; psfObs = obsService.getObservations(null, encounters, \
PSFConcepts, null, null, null, null, null, null, null, null, false); +			
+			Properties props =  this.getProperties(configFileLocation);
+			String batteryName = props
+					.getProperty(&quot;vitals_battery_name&quot;);
+			String PSFObsBatteryName = props
+					.getProperty(&quot;general_battery_name&quot;);
+	
+			if ((psfObs == null||psfObs.size() == 0)&amp;&amp;(pedsClObs == null || \
pedsClObs.size() == 0)){ \
+				chicaHl7Export.setStatus(chicaService.getChicaExportStatusByName(&quot;no_obs&quot;));
 +				chicaService.saveChicaHL7Export(chicaHl7Export);
+			}
+			
+			Integer numberOfVitalsOBXSegments = addOBXBlock( encounter, pedsClObs,  \
batteryName, 0); +			Integer numberOfPSFOBsOBXSegments = addOBXBlock( encounter, \
psfObs, PSFObsBatteryName, 1); +		} catch (Exception e) {
+			e.printStackTrace();
+			throw new HL7Exception(&quot;Exception adding obs to export hl7.&quot;);
+		} 
+	
+	
+		return true;
+	
</ins><span class="cx"> 	}
</span><ins>+
+	private boolean addEncounterObs( ChicaHL7Export chicaHl7Export) {
</ins><span class="cx"> 	
</span><del>-	@Override
-public PID AddSegmentPID(Patient pat) {
</del><ins>+		ChicaService chicaService = Context.getService(ChicaService.class);
+		ConceptService conceptService  = Context.getConceptService();
+		EncounterService encounterService = Context.getEncounterService();
+		ObsService obsService = Context.getObsService();
</ins><span class="cx"> 		
</span><span class="cx"> 		try {
</span><del>-			PID pid = super.AddSegmentPID(pat);
-			return pid;
-
</del><ins>+			Concept physicianEncounterConcept = \
conceptService.getConceptByName(&quot;OBS SET PEDS PHYSICIAN ENCOUNTER CHICA&quot;); \
+			List&lt;Concept&gt; concepts = \
conceptService.getConceptsByConceptSet(physicianEncounterConcept); +			Integer \
encounterId = chicaHl7Export.getEncounterId(); +			Encounter encounter = \
encounterService.getEncounter(encounterId); +			List&lt;Encounter&gt; encounters = \
new ArrayList&lt;Encounter&gt;(); +			encounters.add(encounter);
+			List&lt;Obs&gt; physicianEncounterObs = obsService.getObservations(null, \
encounters, concepts, null, null, null, null, null, null, null, null, false); +	
+			if (physicianEncounterObs == null || physicianEncounterObs.size()== 0){
+				chicaHl7Export.setStatus(chicaService
+						.getChicaExportStatusByName(&quot;no_obs&quot;));
+				chicaService.saveChicaHL7Export(chicaHl7Export);
+				return false;
+			}
+	
+			// Create OBR and OBX segments for Vitals
+			int orderRep = 0;
+			Integer numberOfOBXSegments = 0;
+			String batteryName = properties
+					.getProperty(&quot;vitals_battery_name&quot;);
+			String PSFObsBatteryName = properties
+					.getProperty(&quot;general_battery_name&quot;);
+			numberOfOBXSegments = addOBXBlock(
+					encounter, physicianEncounterObs,  batteryName,
+					orderRep);
+			orderRep++;
+			if (numberOfOBXSegments == 0) {
+				chicaHl7Export.setStatus(chicaService
+						.getChicaExportStatusByName(&quot;no_obs&quot;));
+				chicaService.saveChicaHL7Export(chicaHl7Export);
+				
+				return false;
+			}
+			
</ins><span class="cx"> 		} catch (Exception e) {
</span><del>-			log.error(e);
-			return null;
</del><ins>+			log.error(&quot;Exception adding POC observations to hl7.&quot;, e);
</ins><span class="cx"> 		}
</span><del>-
</del><ins>+		return true;
</ins><span class="cx"> 	}
</span><ins>+
+	/**Add the OBR segment and the OBX segments
+	 * @param encounter
+	 * @param obsList
+	 * @param mappings
+	 * @param batteryName
+	 * @param orderRep
+	 * @return
+	 */
+	public int addOBXBlock(Encounter encounter, List&lt;Obs&gt; obsList, String \
batteryName, int orderRep) { </ins><span class="cx"> 	
</span><ins>+		Locale locale = new Locale(&quot;en_US&quot;);
+		String units = &quot;&quot;;
+		String rmrsCode = &quot;&quot;;
+		String rmrsName = null;
+		String hl7Abbreviation = &quot;&quot;;
+		ConceptDatatype conceptDatatype = null;
+		int obsRep = 0;
+		addSegmentOBR( encounter, batteryName, orderRep);
</ins><span class="cx"> 	
</span><del>-	public MSH AddSegmentMSH(Encounter encounter, String typeOfExport ) {
</del><ins>+		for (Obs obs : obsList) {
+			//get the RMRS concept name and code
+			Concept chicaConcept = obs.getConcept();
+			Collection&lt;ConceptMap&gt; maps =  chicaConcept.getConceptMappings();
+			for (ConceptMap map : maps){
+				if (map.getSource().equals(&quot;RMRS&quot;)){
+					rmrsName = map.getSourceCode();
+					break;
+				}
+			}
+			if (rmrsName == null){
+				continue;
+			}
+			Concept rmrsConcept = getRMRSConceptByName(rmrsName);
+			if (rmrsConcept == null){
+				continue;
+			}
+			
+			rmrsCode = getRMRSCodeFromConcept(rmrsConcept);
+			
+			String value = obs.getValueAsString(locale);
+	
+			if (chicaConcept.isNumeric()) {
+				Double obsRounded = null;
+				if (obs.getValueNumeric() != null) {
+					obsRounded = org.openmrs.module.chirdlutil.util.Util
+							.round(Double.valueOf(obs.getValueNumeric()), 1);
+				}
+				if (obsRounded != null) {
+					value = String.valueOf(obsRounded);
+				}
+			}
+			
+			conceptDatatype = rmrsConcept.getDatatype();
+			String sourceCode = &quot;&quot;;
+	
+			if (conceptDatatype != null &amp;&amp; conceptDatatype.isCoded()) {
+				Concept answer = obs.getValueCoded();
+	
+				Collection&lt;ConceptMap&gt; answers = answer.getConceptMappings();
+				ConceptMap map = null;
+				if (answers != null) {
+					Iterator&lt;ConceptMap&gt; it = answers.iterator();
+					if (it.hasNext()) {
+						map = it.next();
+					}
+					if (map != null) {
+						sourceCode = map.getSourceCode();
+					}
+				}
+	
+			}
+			hl7Abbreviation = conceptDatatype.getHl7Abbreviation();
+			units = getUnits(rmrsConcept);
+			Date datetime = obs.getObsDatetime();
+			AddSegmentOBX(encounter,rmrsName, rmrsCode, null, sourceCode,
+					value, units, datetime, hl7Abbreviation, orderRep,
+					obsRep);
+			obsRep++;
+	
+		}
+	
+		return obsRep;
+	}
</ins><span class="cx"> 
</span><ins>+	public MSH AddSegmentMSH(Encounter encounter, String typeOfExport ) {
+	
</ins><span class="cx"> 		MSH msh = super.AddSegmentMSH(encounter);
</span><span class="cx"> 		
</span><span class="cx"> 		try {
</span><span class="lines">@@ -180,7 +394,7 @@
</span><span class="cx"> 			if (typeOfExport != null &amp;&amp;
</span><span class="cx"> 				( typeOfExport.equalsIgnoreCase(&quot;JIT&quot;)
</span><span class="cx"> 				|| typeOfExport.equalsIgnoreCase(&quot;PWS IMAGE&quot;)
</span><del>-				|| typeOfExport.equalsIgnoreCase(&quot;PWS IMAGE&quot;))){
</del><ins>+				|| typeOfExport.equalsIgnoreCase(&quot;PSF IMAGE&quot;))){
</ins><span class="cx"> 				
</span><span class="cx"> 				ourApplication = \
properties.getProperty(&quot;our_image_app&quot;); </span><span class="cx"> 				
</span><span class="lines">@@ -195,11 +409,50 @@
</span><span class="cx"> 		} catch (DataTypeException e) {
</span><span class="cx"> 			log.error(Util.getStackTrace(e));
</span><span class="cx"> 		}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 		return msh;
</span><span class="cx"> 	}
</span><span class="cx"> 
</span><ins>+	@Override
+	public PID AddSegmentPID(Patient pat) {
+			
+			try {
+				PID pid = super.AddSegmentPID(pat);
+				return pid;
</ins><span class="cx"> 	
</span><ins>+			} catch (Exception e) {
+				log.error(e);
+				return null;
+			}
+	
+		}
+
+	public PV1 AddSegmentPV1(Encounter enc)  {
+
+		PV1 pv1 = super.AddSegmentPV1(enc);
+		ChirdlUtilBackportsService cubackportsService = \
Context.getService(ChirdlUtilBackportsService.class); +	
+		try {
+		
+		
+			Location location = enc.getLocation();
+			LocationAttributeValue value = \
cubackportsService.getLocationAttributeValue(location.getId(), &quot;hl7Name&quot;); \
+			if (value != null) { \
+				pv1.getAssignedPatientLocation().getPointOfCare().setValue(value.getValue()); \
+				pv1.getAssignedPatientLocation().getFacility().getNamespaceID().setValue(value.getValue());
 +			}
+			
+			
+		} catch (Exception e) {
+			log.error(Util.getStackTrace(e));
+		}
+
+
+		return pv1;
+
+	}
+
+	
</ins><span class="cx"> 	public OBX AddSegmentOBX(Encounter enc, String name, String \
obsId, String obsSubId, </span><span class="cx"> 			String valueCode, String value, \
String units, Date datetime, </span><span class="cx"> 			String hl7Abbreviation, int \
orderRep, int obsRep) { </span><span class="lines">@@ -223,7 +476,7 @@
</span><span class="cx"> 		return obx;
</span><span class="cx"> 		
</span><span class="cx"> 	}
</span><del>-	
</del><ins>+
</ins><span class="cx"> 	/**
</span><span class="cx"> 	 * Add and OBX segment that contains the base64 encoded \
tiff </span><span class="cx"> 	 * 
</span><span class="lines">@@ -235,65 +488,67 @@
</span><span class="cx"> 	 * @return
</span><span class="cx"> 	 * @throws ApplicationException
</span><span class="cx"> 	 */
</span><del>-	public boolean addOBXForTiff(
-			HL7MessageConstructor constructor,
-			Encounter encounter, FormInstance formInstance,
-			Hashtable&lt;String, String&gt; mappings, Properties hl7Properties)
</del><ins>+	public void addOBXForTiff( ChicaHL7Export export) throws HL7Exception
</ins><span class="cx"> 			 {
</span><del>-
</del><ins>+	
</ins><span class="cx"> 		FormService formService = Context.getFormService();
</span><ins>+		EncounterService encounterService = Context.getEncounterService();
</ins><span class="cx"> 		ChirdlUtilBackportsService backportsService = Context
</span><span class="cx"> 				.getService(ChirdlUtilBackportsService.class);
</span><span class="cx"> 		boolean obxcreated = false;
</span><span class="cx"> 		String filename = &quot;&quot;;
</span><span class="cx"> 		String encodedForm = &quot;&quot;;
</span><del>-
</del><ins>+		Integer patientStateId = export.getPatientStateId();
+		PatientState state = backportsService.getPatientState(patientStateId);
+		
</ins><span class="cx"> 		try {
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			
</span><del>-			Integer formId = formInstance.getFormId();
</del><ins>+			Integer formId = state.getFormId();
</ins><span class="cx"> 			Form form = formService.getForm(formId);
</span><del>-			Integer encounterId = encounter.getEncounterId();
</del><ins>+			Integer encounterId = export.getEncounterId();
+			Encounter encounter = encounterService.getEncounter(encounterId);
+			
</ins><span class="cx"> 			Integer locationTagId = \
getLocationTagIdByEncounter(encounterId); </span><span class="cx"> 			Integer \
locationId = encounter.getLocation().getId(); </span><del>-			Integer formInstanceId \
                = formInstance.getFormInstanceId();
-			Integer formLocationId = formInstance.getLocationId();
-
</del><ins>+			Integer formInstanceId = state.getFormInstanceId();
+			Integer formLocationId = state.getLocationId();
+	
</ins><span class="cx"> 			if (formId == null || locationTagId == null
</span><span class="cx"> 					|| formLocationId == null || formInstanceId == null) {
</span><del>-				return false;
</del><ins>+				return;
</ins><span class="cx"> 			}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			String formDir = IOUtil
</span><span class="cx"> \
.formatDirectoryName(org.openmrs.module.chirdlutilbackports.util.Util </span><span \
class="cx"> 							.getFormAttributeValue(formId, &quot;imageDirectory&quot;, \
</span><span class="cx"> 									locationTagId, formLocationId)); </span><del>-
</del><ins>+	
</ins><span class="cx"> 			if (formDir == null || formDir.equals(&quot;&quot;)) {
</span><del>-				return false;
</del><ins>+				return ;
</ins><span class="cx"> 			}
</span><span class="cx"> 			filename = formLocationId + &quot;-&quot; + formId + \
&quot;-&quot; + formInstanceId; </span><del>-
</del><ins>+	
</ins><span class="cx"> 			// This FilenameFilter will get ALL tifs starting with the \
filename </span><span class="cx"> 			// including of rescan versions nnn_1.tif, \
nnn_2.tif, etc </span><span class="cx"> 			FilenameFilter filtered = new \
FileListFilter(filename, &quot;tif&quot;); </span><span class="cx"> 			File dir = new \
File(formDir); </span><span class="cx"> 			File[] files = dir.listFiles(filtered);
</span><span class="cx"> 			if (files == null || files.length == 0) {
</span><del>-				return false;
</del><ins>+				return;
</ins><span class="cx"> 			}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			// FileDateComparator will list in order with newest file \
first. </span><span class="cx"> 			Arrays.sort(files, new FileDateComparator());
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			encodedForm = encodeForm(files[0]);
</span><span class="cx"> 			if (encodedForm == null) {
</span><span class="cx"> 				log.error(form + &quot;Form image not found for export.  \
Filename: &quot; + filename); </span><del>-				return false;
</del><ins>+				return;
</ins><span class="cx"> 			}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			// get rmrs name , code, text from form attributes.
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			String RMRSName = &quot;&quot;;
</span><span class="cx"> 			String RMRSCode = &quot;&quot;;
</span><span class="cx"> 			String RMRSText = &quot;&quot;;
</span><span class="lines">@@ -305,46 +560,48 @@
</span><span class="cx"> 							locationId)) != null) {
</span><span class="cx"> 				RMRSName = RMRSNameAttributeValue.getValue();
</span><span class="cx"> 			}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			if ((RMRSCodeAttributeValue = backportsService
</span><span class="cx"> 					.getFormAttributeValue(formId, &quot;RMRSCode&quot;, \
locationTagId, </span><span class="cx"> 							locationId)) != null) {
</span><span class="cx"> 				RMRSCode = RMRSCodeAttributeValue.getValue();
</span><span class="cx"> 			}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			if ((RMRSTextAttributeValue = backportsService
</span><span class="cx"> 					.getFormAttributeValue(formId, &quot;RMRSText&quot;, \
locationTagId, </span><span class="cx"> 							locationId)) != null) {
</span><span class="cx"> 				RMRSText = RMRSTextAttributeValue.getValue();
</span><span class="cx"> 			}
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			// Add the OBR and OBX segments
</span><del>-
</del><ins>+	
</ins><span class="cx"> 			int obsRep = 0;
</span><span class="cx"> 			int orderRep = 0;
</span><span class="cx"> 			String OBXValueDataType = &quot;ED&quot;;
</span><del>-			String attachmentConceptName = hl7Properties
</del><ins>+			String attachmentConceptName = properties
</ins><span class="cx"> 					.getProperty(&quot;attachment_battery_name&quot;);
</span><del>-			String attachmentText = hl7Properties
</del><ins>+			String attachmentText = properties
</ins><span class="cx"> 					.getProperty(&quot;attachment_text&quot;);
</span><span class="cx"> 			OBR obr = super.AddSegmentOBR(encounter, RMRSCode, \
RMRSName, orderRep); </span><del>-			constructor.AddSegmentOBX(encounter, \
attachmentConceptName, RMRSText, null, </del><ins>+			AddSegmentOBX(encounter, \
attachmentConceptName, RMRSText, null, </ins><span class="cx"> 					null, \
attachmentText, null, </span><span class="cx"> 					encounter.getEncounterDatetime(), \
&quot;ST&quot;, orderRep, obsRep); </span><del>-			OBX resultOBX = \
constructor.AddSegmentOBX(encounter, RMRSName, RMRSCode, null, \
</del><ins>+			AddSegmentOBX(encounter, RMRSName, RMRSCode, null, </ins><span \
class="cx"> 					&quot;&quot;, encodedForm, &quot;&quot;, \
encounter.getEncounterDatetime(), </span><span class="cx"> 					OBXValueDataType, \
orderRep, obsRep + 1); </span><del>-
-			if (resultOBX != null) {
-				obxcreated = true;
-			}
-
</del><ins>+	
</ins><span class="cx"> 		} catch (Exception e) {
</span><span class="cx"> 			log.error(&quot;Exception adding OBR/OBX for tiff image. \
&quot; , e); </span><ins>+			throw new HL7Exception(&quot;Exception adding OBR/OBX \
for tiff image.&quot;); </ins><span class="cx"> 		}
</span><ins>+	
+		return ;
+	
+	}
</ins><span class="cx"> 
</span><del>-		return obxcreated;
-
</del><ins>+	public void setAssignAuthority(PatientIdentifier pi) {
+		
+		super.setAssignAuthority(pi);
</ins><span class="cx"> 	}
</span><span class="cx"> 	
</span><span class="cx"> 	/**
</span><span class="lines">@@ -434,180 +691,7 @@
</span><span class="cx"> 
</span><span class="cx"> 	}
</span><span class="cx"> 	
</span><del>-	
</del><span class="cx"> 
</span><del>-	
-	/**Add the OBR segment and the OBX segments
-	 * @param encounter
-	 * @param obsList
-	 * @param mappings
-	 * @param batteryName
-	 * @param orderRep
-	 * @return
-	 */
-	public int addOBXBlock(Encounter encounter, List&lt;Obs&gt; obsList, String \
                batteryName, int orderRep) {
-
-		Locale locale = new Locale(&quot;en_US&quot;);
-		ConceptService conceptService = Context.getConceptService();
-		String units = &quot;&quot;;
-		String rmrsCode = &quot;&quot;;
-		String rmrsName = null;
-		String hl7Abbreviation = &quot;&quot;;
-		ConceptDatatype conceptDatatype = null;
-		int obsRep = 0;
-		addSegmentOBR( encounter, batteryName, orderRep);
-
-		for (Obs obs : obsList) {
-			//get the RMRS concept name and code
-			Concept chicaConcept = obs.getConcept();
-			Collection&lt;ConceptMap&gt; maps =  chicaConcept.getConceptMappings();
-			for (ConceptMap map : maps){
-				if (map.getSource().equals(&quot;RMRS&quot;)){
-					rmrsName = map.getSourceCode();
-					break;
-				}
-			}
-			if (rmrsName == null){
-				continue;
-			}
-			Concept rmrsConcept = getRMRSConceptByName(rmrsName);
-			if (rmrsConcept == null){
-				continue;
-			}
-			
-			rmrsCode = getRMRSCodeFromConcept(rmrsConcept);
-			
-			String value = obs.getValueAsString(locale);
-
-			if (chicaConcept.isNumeric()) {
-				Double obsRounded = null;
-				if (obs.getValueNumeric() != null) {
-					obsRounded = org.openmrs.module.chirdlutil.util.Util
-							.round(Double.valueOf(obs.getValueNumeric()), 1);
-				}
-				if (obsRounded != null) {
-					value = String.valueOf(obsRounded);
-				}
-			}
-			
-			conceptDatatype = rmrsConcept.getDatatype();
-			String sourceCode = &quot;&quot;;
-
-			if (conceptDatatype != null &amp;&amp; conceptDatatype.isCoded()) {
-				Concept answer = obs.getValueCoded();
-
-				Collection&lt;ConceptMap&gt; answers = answer.getConceptMappings();
-				ConceptMap map = null;
-				if (answers != null) {
-					Iterator&lt;ConceptMap&gt; it = answers.iterator();
-					if (it.hasNext()) {
-						map = it.next();
-					}
-					if (map != null) {
-						sourceCode = map.getSourceCode();
-					}
-				}
-
-			}
-			hl7Abbreviation = conceptDatatype.getHl7Abbreviation();
-			units = getUnits(rmrsConcept);
-			Date datetime = obs.getObsDatetime();
-			AddSegmentOBX(encounter,rmrsName, rmrsCode, null, sourceCode,
-					value, units, datetime, hl7Abbreviation, orderRep,
-					obsRep);
-			obsRep++;
-
-		}
-
-		return obsRep;
-	}
-
-
-	
-
-	private List&lt;Obs&gt; getObsListByBattery(Encounter encounter,
-			Hashtable&lt;String, String&gt; table, String batteryName) {
-
-		ConceptService conceptService = Context.getConceptService();
-		ObsService obsService = Context.getObsService();
-		List&lt;Concept&gt; concepts = new ArrayList&lt;Concept&gt;();
-		List&lt;Obs&gt; obsList = null;
-
-		try {
-
-			Enumeration&lt;String&gt; en = table.keys();
-			while (en.hasMoreElements()) {
-				String chicaConceptName = (String) en.nextElement();
-				Concept chicaConcept = conceptService
-						.getConceptByName(chicaConceptName);
-				if (chicaConcept != null
-						&amp;&amp; checkConceptSet(chicaConcept, batteryName)) {
-					concepts.add(chicaConcept);
-				}
-
-			}
-
-			if (concepts.size() &gt; 0) {
-				List&lt;org.openmrs.Encounter&gt; encounters = new \
                ArrayList&lt;org.openmrs.Encounter&gt;();
-				encounters.add(encounter);
-
-				obsList = obsService.getObservations(null, encounters,
-						concepts, null, null, null, null, null, null, null,
-						null, false);
-			}
-		} catch (Exception e) {
-			log.error(&quot;Error collecting obs list from concept map.&quot;);
-		}
-
-		return obsList;
-
-	}
-
-	private List&lt;Obs&gt; loadObsLists(Encounter encounter,
-			Hashtable&lt;String, String&gt; mappings, String batteryName) {
-
-		ConceptService conceptService = Context.getConceptService();
-		ObsService obsService = Context.getObsService();
-		List&lt;Obs&gt; obsList = null;
-		
-		
-
-		try {
-			if (batteryName == null || batteryName.equals(&quot;&quot;)) {
-				return null;
-			}
-			List&lt;Concept&gt; concepts = new ArrayList&lt;Concept&gt;();
-			List&lt;org.openmrs.Encounter&gt; encounters = new \
                ArrayList&lt;org.openmrs.Encounter&gt;();
-			List&lt;Person&gt; patients = new ArrayList&lt;Person&gt;();
-
-			encounters.add(encounter);
-			patients.add(encounter.getPatient());
-
-			Enumeration&lt;String&gt; en = mappings.keys();
-			while (en.hasMoreElements()) {
-				String chicaConceptName = (String) en.nextElement();
-				Concept chicaConcept = conceptService
-						.getConceptByName(chicaConceptName);
-				if (chicaConcept != null
-						&amp;&amp; checkConceptSet(chicaConcept, batteryName)) {
-					concepts.add(chicaConcept);
-				}
-			}
-
-			if (concepts.size() &gt; 0) {
-				obsList = obsService.getObservations(patients, encounters,
-						concepts, null, null, null, null, null, null, null,
-						null, false);
-			}
-
-		} catch (Exception e) {
-			log.error(&quot;Error collecting obs list from concept map.&quot;);
-		}
-
-		return obsList;
-
-	}
-
</del><span class="cx"> 	private Concept getRMRSConceptByName(String rmrsname) {
</span><span class="cx"> 
</span><span class="cx"> 		ConceptService cs = Context.getConceptService();
</span><span class="lines">@@ -674,266 +758,6 @@
</span><span class="cx"> 		return units;
</span><span class="cx"> 	}
</span><span class="cx"> 
</span><del>-	private boolean checkConceptSet(Concept conceptToTest, String \
                batteryName) {
-		boolean match = false;
-		ConceptService cs = Context.getConceptService();
-
-		if (conceptToTest == null || batteryName == null
-				|| batteryName.equals(&quot;&quot;)) {
-			return false;
-		}
-
-		Concept concept = cs.getConceptByName(batteryName + &quot; CHICA&quot;);
-
-		Concept batteryConcept = new Concept();
-		if (concept.isSet()) {
-			batteryConcept = concept;
-		}
-		Collection&lt;ConceptSet&gt; allConceptsInBattery = cs
-				.getConceptSetsByConcept(batteryConcept);
-		for (ConceptSet conceptSet : allConceptsInBattery) {
-
-			if (conceptToTest.getConceptId().equals(
-					conceptSet.getConcept().getConceptId())) {
-				match = true;
-				continue;
-			}
-
-		}
-
-		return match;
-
-	}
-
-	/**
-	 * Add the vitals and other psf observations to the hl7 message. 
-	 * Get list of observations from concepts in the concept sets.
-	 * Get the RMRS name and code for the CHICA concept using ConceptMap
-	 * 
-	 * @param encounter
-	 * @param constructor
-	 * @param chicaHl7Export
-	 * @return
-	 * @throws IOException
-	 */
-	private boolean addPreScreenObs(Encounter encounter, ChicaHL7Export chicaHl7Export)
-					throws IOException {
-		
-		AdministrationService adminService = Context.getAdministrationService();
-		ConceptService conceptService = Context.getConceptService();
-		ChicaService chicaService = Context.getService(ChicaService.class);
-		ObsService obsService = Context.getObsService();
-
-		
-
-		//use concept map table to look up 
-		Concept pedClDataConcept = conceptService.getConceptByName(&quot;PED CL DATA \
                CHICA&quot;);
-		List&lt;Concept&gt; concepts = \
                conceptService.getConceptsByConceptSet(pedClDataConcept);
-		List&lt;Encounter&gt; encounters = new ArrayList();
-		encounters.add(encounter);
-		List&lt;Obs&gt; pedsClObs = obsService.getObservations(null, encounters, concepts, \
                null, null, null, null, null, null, null, null, false);
-
-
-		//Careweb concepts for allergies uses a different text than vitals and pain obs
-		Concept pedsObsDifferentSet = conceptService.getConceptByName(&quot;MEDICAL RECORD \
                FILE OBSERVATIONS CHICA&quot;);
-		List&lt;Concept&gt; PSFConcepts = \
                conceptService.getConceptsByConceptSet(pedsObsDifferentSet);
-		;
-		encounters.add(encounter);
-		List&lt;Obs&gt; psfObs = obsService.getObservations(null, encounters, PSFConcepts, \
                null, null, null, null, null, null, null, null, false);
-		
-		Properties props =  this.getProperties(configFileLocation);
-		String batteryName = props
-				.getProperty(&quot;vitals_battery_name&quot;);
-		String PSFObsBatteryName = props
-				.getProperty(&quot;general_battery_name&quot;);
-
-		if ((psfObs == null||psfObs.size() == 0)&amp;&amp;(pedsClObs == null || \
                pedsClObs.size() == 0)){
-			chicaHl7Export.setStatus(chicaService.getChicaExportStatusByName(&quot;no_obs&quot;));
                
-			chicaService.saveChicaHL7Export(chicaHl7Export);
-		}
-		
-		Integer numberOfVitalsOBXSegments = addOBXBlock( encounter, pedsClObs,  \
                batteryName, 0);
-		Integer numberOfPSFOBsOBXSegments = addOBXBlock( encounter, psfObs, \
                PSFObsBatteryName, 1);
-
-
-		return true;
-
-	}
-
-	private boolean addEncounterOBX(Encounter encounter, ChicaHL7Export chicaHl7Export) \
                {
-
-		AdministrationService adminService = Context.getAdministrationService();
-		ChicaService chicaService = Context.getService(ChicaService.class);
-		ConceptService conceptService  = Context.getConceptService();
-		ObsService obsService = Context.getObsService();
-		
-		try {
-			Concept physicianEncounterConcept = conceptService.getConceptByName(&quot;OBS SET \
                PEDS PHYSICIAN ENCOUNTER CHICA&quot;);
-			List&lt;Concept&gt; concepts = \
                conceptService.getConceptsByConceptSet(physicianEncounterConcept);
-			List&lt;Encounter&gt; encounters = new ArrayList();
-			encounters.add(encounter);
-			List&lt;Obs&gt; physicianEncounterObs = obsService.getObservations(null, \
                encounters, concepts, null, null, null, null, null, null, null, null, \
                false);
-
-			if (physicianEncounterObs == null || physicianEncounterObs.size()== 0){
-				chicaHl7Export.setStatus(chicaService
-						.getChicaExportStatusByName(&quot;no_obs&quot;));
-				chicaService.saveChicaHL7Export(chicaHl7Export);
-				return false;
-			}
-
-			// Create OBR and OBX segments for Vitals
-			int orderRep = 0;
-			Integer numberOfOBXSegments = 0;
-			Properties props =  this.getProperties(configFileLocation);
-			String batteryName = properties
-					.getProperty(&quot;vitals_battery_name&quot;);
-			String PSFObsBatteryName = properties
-					.getProperty(&quot;general_battery_name&quot;);
-			numberOfOBXSegments = addOBXBlock(
-					encounter, physicianEncounterObs,  batteryName,
-					orderRep);
-			orderRep++;
-			if (numberOfOBXSegments == 0) {
-				chicaHl7Export.setStatus(chicaService
-						.getChicaExportStatusByName(&quot;no_obs&quot;));
-				chicaService.saveChicaHL7Export(chicaHl7Export);
-				
-				return false;
-			}
-			
-		} catch (Exception e) {
-			log.error(&quot;Exception adding POC observations to hl7.&quot;, e);
-		}
-		return true;
-	}
-	
-	private void addSegmentOBR(Encounter openmrsEncounter,
-			String batteryName, int orderRep) {
-
-		ConceptService cs = Context.getConceptService();
-
-		String batteryId = null;
-
-		if (batteryName != null) {
-			Concept rmrsConcept = cs.getConceptByName(batteryName);
-			if (rmrsConcept == null ){
-				log.error(&quot;Unable to add OBR to export HL7 because the OBR battery name is \
                null&quot;);
-				return;
-			}
-			batteryId = getRMRSCodeFromConcept(rmrsConcept);
-		}
-		OBR obr = super.AddSegmentOBR(openmrsEncounter, batteryId, batteryName, orderRep);
-		
-
-	}
-	
-	public String createMessage(ChicaHL7Export  export){
-		String message = null;
-
-		ChicaService chicaService = Context.getService(ChicaService.class);
-		EncounterService encounterService = Context.getEncounterService();
-		ChirdlUtilBackportsService chirdlutilbackportsService = \
                Context.getService(ChirdlUtilBackportsService.class);
-		ATDService atdService = Context.getService(ATDService.class);
-		Integer encounterId = export.getEncounterId();
-		String exportType = export.getExportType();
-
-		// Construct message MSH, PID, and PV1
-		//export get state
-		Encounter encounter = encounterService.getEncounter(export.getEncounterId());
-
-		Patient patient = encounter.getPatient();
-		AddSegmentMSH( encounter, export.getExportType());
-		AddSegmentPID(patient);
-		AddSegmentPV1(encounter);
-
-
-		Integer patientStateId = export.getPatientStateId();
-		PatientState patientState = \
                chirdlutilbackportsService.getPatientState(patientStateId);
-		String state = patientState.getState().getName();
-
-		// When we send vitals, we send other PSF obs also.
-		// if vitals, add the obs block
-
-		if (exportType == &quot;PSF OBS&quot; || exportType == &quot;VITALS&quot; ){
-			try {
-				addPreScreenObs(encounter, export);
-			} catch (IOException e) {
-				// TODO Auto-generated catch block
-				e.printStackTrace();
-			}
-		}
-
-		if (exportType == &quot;PWS OBS&quot;){
-			addEncounterOBX(encounter, export);
-		}
-		
-		if (exportType == &quot;PWS IMAGE&quot;){
-			//get the form instance
-			//get the map from global property
-		}
-		if (exportType == &quot;PWS IMAGE&quot;){
-
-		}
-		if (exportType == &quot;PWS IMAGE&quot;){
-
-		}
-		if (exportType == &quot;PWS JIT&quot;){
-
-		}
-
-		//if state = exportpsf, exportpws, exportjit, get the form instance
-		FormInstance formInstance = patientState.getFormInstance();
-		//if not null send to constructor to add tiff encoded to message
-		//if null then error
-
-		/*state.getName();
-		if (state.getName().equals(&quot;exportVitals&quot;)){
-
-			if (!addObs(openmrsEncounter, constructor, export)) {
-				return true;
-			}
-		}
-
-
-
-		try {
-			constructor.addOBXBlock(export);
-		} catch (ImageNotFoundException e) {
-
-		}
-
-		//add obs based on state
-		stance add the form tiff as an OBX
-			// segment
-			FormInstance formInstance = getFormInstance(exportMapValue);
-
-			// encode and add tiff as an obs.
-			if (formInstance == null
-					|| (formInstance != null &amp;&amp; !addOBXForTiff(constructor,
-							openmrsEncounter, formInstance, null,
-							hl7Properties))) {
-				logExportError(&quot;Image_not_found&quot;, null, openmrsEncounter, sessionId);
-				ChicaHL7ExportStatus status = chicaService
-						.getChicaExportStatusByName(&quot;Image_not_found&quot;);
-				chicaHl7Export.setStatus(status);
-				chicaService.saveChicaHL7Export(chicaHl7Export);
-				return true;
-			}
-		}
-
-		String message = constructor.getMessage();
-		if (message == null || message.trim().equals(&quot;&quot;)) {
-			chicaHl7Export.setStatus(chicaService
-					.getChicaExportStatusByName(&quot;Construction Error&quot;));
-			chicaHl7Export.setDateProcessed(new Date());
-			chicaService.saveChicaHL7Export(chicaHl7Export);
-			this.logExportError(&quot;HL7 message text is null or empty&quot;, null, \
                openmrsEncounter,
-					sessionId);
-			return true; // go to next message
-		}*/
-		return message;
-	}
-	
</del><span class="cx"> 	public Properties getProperties(String filename) {
</span><span class="cx"> 		try {
</span><span class="cx"> 
</span><span class="lines">@@ -951,6 +775,8 @@
</span><span class="cx"> 		}
</span><span class="cx"> 		return null;
</span><span class="cx"> 	}
</span><ins>+
+
</ins><span class="cx"> 	
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>

<p></p>

-- <br />
-- OpenMRS Subversion Commits: <a \
href="http://go.openmrs.org/svn">http://go.openmrs.org/svn</a><br /> Posting is not \
                allowed - please join dev@openmrs.org for discussion.<br />
Unsubscribe: svn+unsubscribe@openmrs.org<br />

<p></p>

To unsubscribe from this group and stop receiving emails from it, send an email to <a \
href="mailto:svn+unsubscribe@openmrs.org">svn+unsubscribe@openmrs.org</a>.<br />


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic