Skip to content

Commit

Permalink
Adds ODD query ability to FindDocuments
Browse files Browse the repository at this point in the history
  • Loading branch information
rcrichton committed Jul 30, 2015
1 parent 7093f7e commit 3d087dc
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ void validate_doc_slots() throws MetadataException {
}

// name multi required number
validate_slot("Document", id, slots, "creationTime", false, !isODD, true);
validate_slot("Document", id, slots, "creationTime", false, !isODD, true);
validate_slot("Document", id, slots, "intendedRecipient", true, false, false);
validate_slot("Document", id, slots, "languageCode", false, true, false);
validate_slot("Document", id, slots, "legalAuthenticator", false, false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ void validateParameters() throws MetadataValidationException {
sqs.validate_parm("$XDSDocumentEntryFormatCode", false, true, true, true, false, (String[])null );
sqs.validate_parm("$XDSDocumentEntryStatus", true, true, true, false, false, (String[])null );
sqs.validate_parm("$XDSDocumentEntryAuthorPerson", false, true, true, false, false, (String[])null );
sqs.validate_parm("$XDSDocumentEntryType", false, true, true, false, false, (String[])null );

if (sqs.has_validation_errors)
throw new MetadataValidationException("Metadata Validation error present");
Expand All @@ -120,6 +121,7 @@ void validateParameters() throws MetadataValidationException {
protected SQCodedTerm format_codes;
protected List<String> status;
protected List<String> author_person;
protected List<String> object_type;

protected SQCodedTerm class_codes;
protected SQCodedTerm type_codes;
Expand Down Expand Up @@ -157,22 +159,29 @@ public String toString() {

void parseParameters() throws XdsInternalException, XdsException, LoggerException {

patient_id = sqs.params.getStringParm ("$XDSDocumentEntryPatientId");
patient_id = sqs.params.getStringParm("$XDSDocumentEntryPatientId");
class_codes = sqs.params.getCodedParm("$XDSDocumentEntryClassCode");
type_codes = sqs.params.getCodedParm("$XDSDocumentEntryTypeCode");
practice_setting_codes = sqs.params.getCodedParm("$XDSDocumentEntryPracticeSettingCode");
creation_time_from = sqs.params.getIntParm ("$XDSDocumentEntryCreationTimeFrom");
creation_time_from = sqs.params.getIntParm("$XDSDocumentEntryCreationTimeFrom");
creation_time_to = sqs.params.getIntParm ("$XDSDocumentEntryCreationTimeTo");
service_start_time_from = sqs.params.getIntParm ("$XDSDocumentEntryServiceStartTimeFrom");
service_start_time_to = sqs.params.getIntParm ("$XDSDocumentEntryServiceStartTimeTo");
service_stop_time_from = sqs.params.getIntParm ("$XDSDocumentEntryServiceStopTimeFrom");
service_stop_time_to = sqs.params.getIntParm ("$XDSDocumentEntryServiceStopTimeTo");
service_stop_time_from = sqs.params.getIntParm("$XDSDocumentEntryServiceStopTimeFrom");
service_stop_time_to = sqs.params.getIntParm("$XDSDocumentEntryServiceStopTimeTo");
hcft_codes = sqs.params.getCodedParm("$XDSDocumentEntryHealthcareFacilityTypeCode");
event_codes = sqs.params.getCodedParm("$XDSDocumentEntryEventCodeList");
conf_codes = sqs.params.getCodedParm("$XDSDocumentEntryConfidentialityCode");
format_codes = sqs.params.getCodedParm("$XDSDocumentEntryFormatCode");
status = sqs.params.getListParm("$XDSDocumentEntryStatus");
author_person = sqs.params.getListParm("$XDSDocumentEntryAuthorPerson");
object_type = sqs.params.getListParm("$XDSDocumentEntryType");

// the default value of object_type is stable documents
if (object_type == null) {
object_type = new ArrayList<String>();
object_type.add(MetadataSupport.XDSDocumentEntry_objectType_stable_uuid);
}


String status_ns_prefix = MetadataSupport.status_type_namespace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
import gov.nist.registry.common2.exception.XdsException;
import gov.nist.registry.common2.registry.Metadata;
import gov.nist.registry.common2.registry.MetadataParser;
import gov.nist.registry.common2.registry.MetadataSupport;
import gov.nist.registry.common2.registry.storedquery.StoredQuerySupport;
import gov.nist.registry.ws.sq.FindDocuments;

import org.apache.axiom.om.OMElement;
import org.openhealthtools.openxds.log.LoggerException;

import java.util.Iterator;

/**
* Implementation specific class for FindDocuments stored query.
* All the logic is in the runImplementation() method.
Expand Down Expand Up @@ -38,17 +42,62 @@ public EbXML21FindDocuments(StoredQuerySupport sqs) throws MetadataValidationExc
*/
public Metadata runImplementation() throws MetadataException, XdsException,
LoggerException {


boolean includeStable = false;
boolean includeODD = false;

for (String type : object_type) {
if (type.equals(MetadataSupport.XDSDocumentEntry_objectType_stable_uuid)) {
includeStable = true;
}
if (type.equals(MetadataSupport.XDSDocumentEntry_objectType_odd_uuid)) {
includeODD = true;
}
}

OMElement finalResult = null;
OMElement oddResult = null;
if (includeODD) {
createQuery(true);
oddResult = eb.query(sqs.return_leaf_class);
finalResult = oddResult;
}

OMElement stableResult = null;
if (includeStable) {
createQuery(false);
stableResult = eb.query(sqs.return_leaf_class);
finalResult = stableResult;
}

if (oddResult != null && stableResult != null) {
// join both result sets
OMElement registryObjectListStable = (OMElement) stableResult.getChildElements().next();
OMElement registryObjectListODD = (OMElement) oddResult.getChildElements().next();
Iterator<OMElement> children = registryObjectListODD.getChildElements();
while (children.hasNext()) {
// add from odd result to stable
registryObjectListStable.addChild(children.next().detach());
}
// set final results as combined results
finalResult = stableResult;
}

return MetadataParser.parseNonSubmission(finalResult);
}

private void createQuery(boolean isODD) throws MetadataException {
eb.init();

if (sqs.return_leaf_class) {
eb.a("SELECT * "); eb.n();
} else {
eb.a("SELECT doc.id "); eb.n();
}
eb.a("FROM ExtrinsicObject doc, ExternalIdentifier patId"); eb.n();
eb.a("FROM ExtrinsicObject doc, ExternalIdentifier patId");
eb.n();
if (class_codes != null) eb.a(eb.declareClassifications(class_codes));
if (type_codes != null) eb.a(eb.declareClassifications(type_codes));
if (type_codes != null) eb.a(eb.declareClassifications(type_codes));
if (practice_setting_codes != null) eb.a(eb.declareClassifications(practice_setting_codes));
if (hcft_codes != null) eb.a(eb.declareClassifications(hcft_codes)); // $XDSDocumentEntryHealthcareFacilityTypeCode
if (event_codes != null) eb.a(eb.declareClassifications(event_codes)); // $XDSDocumentEntryEventCodeList
Expand All @@ -67,15 +116,18 @@ public Metadata runImplementation() throws MetadataException, XdsException,
eb.a("WHERE"); eb.n();
eb.a("(doc.id = patId.registryobject AND "); eb.n();
eb.a(" patId.identificationScheme='urn:uuid:58a6f841-87b3-4a3e-92fd-a8ffeff98427' AND "); eb.n();
eb.a(" patId.value = '"); eb.a(patient_id); eb.a("' ) "); eb.n();
eb.a(" patId.value = '"); eb.a(patient_id);
eb.a("' ) "); eb.n();

eb.addCode(class_codes);
eb.addCode(type_codes);
eb.addCode(practice_setting_codes);

eb.addTimes("creationTime", "crTimef", "crTimet", creation_time_from, creation_time_to, "doc");
if (!isODD) {
eb.addTimes("creationTime", "crTimef", "crTimet", creation_time_from, creation_time_to, "doc");
}
eb.addTimes("serviceStartTime", "serStartTimef", "serStartTimet", service_start_time_from, service_start_time_to, "doc");
eb.addTimes("serviceStopTime", "serStopTimef", "serStopTimet", service_stop_time_from, service_stop_time_to, "doc");
eb.addTimes("serviceStopTime", "serStopTimef", "serStopTimet", service_stop_time_from, service_stop_time_to, "doc");

eb.addCode(hcft_codes);
eb.addCode(event_codes);
Expand All @@ -94,11 +146,12 @@ public Metadata runImplementation() throws MetadataException, XdsException,
}
}

eb.a("AND doc.status IN "); eb.a(status);


return MetadataParser.parseNonSubmission(eb.query(sqs.return_leaf_class));
eb.a("AND doc.status IN "); eb.a(status); eb.n();
if (isODD) {
eb.a("AND doc.objecttype = '" + MetadataSupport.XDSDocumentEntry_objectType_odd_uuid + "'"); eb.n();
} else {
eb.a("AND doc.objecttype = '" + MetadataSupport.XDSDocumentEntry_objectType_stable_uuid + "'"); eb.n();
}
}


}

0 comments on commit 3d087dc

Please sign in to comment.