我正在尝试运行此脚本来解析 XML 文档。当我验证 js 时,我在 for 循环后丢失了 )。我是编程新手,不知道哪里出错了。我已经在最后发布了整个 js 文件。谢谢!
var meds = [];
for (var i = docMedActivities.size(); i--; i >= 0) {
var activity = docMedActivities.get(i);
var material = activity.getConsumable().getManufacturedProduct().getManufacturedMaterial();
meds.push({
name: String(material.getName().getText()),
displayName: String(material.getCode().getDisplayName()),
ndc: String(material.getCode().getTranslations().get(0).getCode()),
doseQty: String(activity.getDoseQuantity().getValue()),
effectiveDateTime: String(activity.getEffectiveTimes().get(0).getLow().getValue()), // 20120502000000+0000
code: String(material.getCode().getCode())
});
}
整个js文件如下:
// Load the CCD Document
var doc = org.openhealthtools.mdht.uml.cda.util.CDAUtil.load(new java.io.ByteArrayInputStream(messageObject.getRawData().getBytes("UTF-8")));
// Get CCD Document Sections to be parsed
var docPatientRole = doc.getRecordTargets().get(0).getPatientRole();
var docPatient = docPatientRole.getPatient();
var docPatientName = docPatient.getNames().get(0);
var docPatientAddress = docPatientRole.getAddrs().get(0);
var docMedSection = doc.getMedicationsSection();
var docMedActivities = docMedSection.getMedicationActivities();
// Patient Identity
var patient = {
firstName: String(docPatientName.getGivens().get(0).getText()),
lastName: String(docPatientName.getFamilies().get(0).getText()),
genderCode: String(docPatient.getAdministrativeGenderCode().getCode()),
dateOfBirth: String(docPatient.getBirthTime().getValue()) // YYYYMMDD
};
// Patient Address
var address = {
addressCity: String(docPatientAddress.getCities().get(0).getText()),
addressState: String(docPatientAddress.getStates().get(0).getText()),
addressPostalCode: String(docPatientAddress.getPostalCodes().get(0).getText())
};
// Patient Medication Activities
var meds = [];
for (var i = docMedActivities.size(); i--; i >= 0) {
var activity = docMedActivities.get(i);
var material = activity.getConsumable().getManufacturedProduct().getManufacturedMaterial();
meds.push({
name: String(material.getName().getText()),
displayName: String(material.getCode().getDisplayName()),
ndc: String(material.getCode().getTranslations().get(0).getCode()),
doseQty: String(activity.getDoseQuantity().getValue()),
effectiveDateTime: String(activity.getEffectiveTimes().get(0).getLow().getValue()), // 20120502000000+0000
code: String(material.getCode().getCode())
});
}
// Populate Channel Map, use JSON so logs are readable
channelMap.put('patient', JSON.stringify(patient, null, 2));
channelMap.put('address', JSON.stringify(address, null, 2));
channelMap.put('meds', JSON.stringify(meds, null, 2));</script>
<type>JavaScript</type>
<data class="map">
<entry>
<string>Script</string>
<string>// Load the CCD Document
var doc = org.openhealthtools.mdht.uml.cda.util.CDAUtil.load(new java.io.ByteArrayInputStream(messageObject.getRawData().getBytes("UTF-8")));
// Get CCD Document Sections to be parsed
var docPatientRole = doc.getRecordTargets().get(0).getPatientRole();
var docPatient = docPatientRole.getPatient();
var docPatientName = docPatient.getNames().get(0);
var docPatientAddress = docPatientRole.getAddrs().get(0);
var docMedSection = doc.getMedicationsSection();
var docMedActivities = docMedSection.getMedicationActivities();
// Patient Identity
var patient = {
firstName: String(docPatientName.getGivens().get(0).getText()),
lastName: String(docPatientName.getFamilies().get(0).getText()),
genderCode: String(docPatient.getAdministrativeGenderCode().getCode()),
dateOfBirth: String(docPatient.getBirthTime().getValue()) // YYYYMMDD
};
// Patient Address
var address = {
addressCity: String(docPatientAddress.getCities().get(0).getText()),
addressState: String(docPatientAddress.getStates().get(0).getText()),
addressPostalCode: String(docPatientAddress.getPostalCodes().get(0).getText())
};
// Patient Medication Activities
var meds = [];
for (var i = docMedActivities.size(); i--; i >= 0) {
var activity = docMedActivities.get(i);
var material = activity.getConsumable().getManufacturedProduct().getManufacturedMaterial();
meds.push({
name: String(material.getName().getText()),
displayName: String(material.getCode().getDisplayName()),
ndc: String(material.getCode().getTranslations().get(0).getCode()),
doseQty: String(activity.getDoseQuantity().getValue()),
effectiveDateTime: String(activity.getEffectiveTimes().get(0).getLow().getValue()), // 20120502000000+0000
code: String(material.getCode().getCode())
});
}
// Populate Channel Map, use JSON so logs are readable
channelMap.put('patient', JSON.stringify(patient, null, 2));
channelMap.put('address', JSON.stringify(address, null, 2));
channelMap.put('meds', JSON.stringify(meds, null, 2));