List of usage examples for org.joda.time.format DateTimeFormatter parseDateTime
public DateTime parseDateTime(String text)
From source file:org.graylog2.indexer.ranges.RebuildIndexRangesJob.java
License:Open Source License
private static int getTimestampOfMessage(SearchHit msg) { Object field = msg.getSource().get("timestamp"); if (field == null) { throw new RuntimeException("Document has no field timestamp."); }/*w w w. j a va 2 s .c o m*/ DateTimeFormatter formatter = DateTimeFormat.forPattern(Tools.ES_DATE_FORMAT).withZoneUTC(); DateTime dt = formatter.parseDateTime(field.toString()); return (int) (dt.getMillis() / 1000); }
From source file:org.graylog2.search.SearchQueryParser.java
License:Open Source License
private DateTime parseDate(String value) { for (DateTimeFormatter formatter : DATE_TIME_FORMATTERS) { try {/*from ww w.j av a 2 s . c o m*/ return formatter.parseDateTime(value); } catch (IllegalArgumentException e) { // Try next one } } // It's probably not a date... throw new IllegalArgumentException("Unable to parse date: " + value); }
From source file:org.graylog2.syslog4j.server.impl.event.structured.StructuredSyslogServerEvent.java
License:Open Source License
protected void parseDate() { // skip VERSION field int i = this.message.indexOf(' '); this.message = this.message.substring(i + 1); // parse the date i = this.message.indexOf(' '); if (i > -1) { String dateString = this.message.substring(0, i).trim(); try {/*from w w w . j av a2 s .c o m*/ DateTimeFormatter formatter = getDateTimeFormatter(); this.dateTime = formatter.parseDateTime(dateString); this.date = this.dateTime.toDate(); this.message = this.message.substring(dateString.length() + 1); } catch (Exception e) { // Not structured date format, try super one super.parseDate(); } } }
From source file:org.groggy.elasticsearch.river.injector.InjectorRiverConfig.java
License:Apache License
/** * Setup a configuration. /*ww w . j a va 2 s . c om*/ * @param settings the settings */ public InjectorRiverConfig(Map<String, Object> settings) { isRiver = XContentMapValues.nodeBooleanValue(settings.get("is-river"), true); totalMessageNumber = XContentMapValues.nodeIntegerValue(settings.get("load_total_messages"), 0); esRiverBulkSize = XContentMapValues.nodeIntegerValue(settings.get("es_river_bulk_size"), 5000); esDocumentIdPrefix = XContentMapValues.nodeStringValue(settings.get("es_document_id_prefix"), ""); esDocumentType = XContentMapValues.nodeStringValue(settings.get("es_type"), "groggy"); tickInterval = getTimeValue("load_tick_interval", 1, settings); interMessageDelay = getTimeValue("load_inter_message_delay", 0, settings); interBulkDelay = getTimeValue("load_inter_bulk_delay", 0, settings); statsOutputInterval = getTimeValue("load_stats_publish_interval", 10000, settings); String startTime = XContentMapValues.nodeStringValue(settings.get("load_start_time"), null); if (startTime != null) { String timeFormat = XContentMapValues.nodeStringValue(settings.get("load_start_time_format"), "yyyy.MM.dd"); DateTimeFormatter fmt = DateTimeFormat.forPattern(timeFormat); DateTime start = fmt.parseDateTime(startTime); this.clock = new Clock(start, (int) tickInterval); } else { this.clock = new Clock(new DateTime(), (int) tickInterval); } /** * take the required elasticsearch index. The input string is somthing like * "logstash-%{yyy.MM.dd}", or "logstash-%{yyyy.MM.dd.hh}". * Form that we compute this.index as "logstash-" and a DateTimeFormat corresponding * to the "yyy.MM.dd" part. */ String _index = XContentMapValues.nodeStringValue(settings.get("es_index"), null); if (_index != null) { String regex = "%\\{(.*?)\\}"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(_index); if (matcher.find()) { String dateFormat = matcher.group(1); this.esIndex = _index.replaceAll(regex, ""); this.indexTimeFormatter = DateTimeFormat.forPattern(dateFormat); } else { this.esIndex = _index; this.indexTimeFormatter = null; } } else { this.esIndex = null; this.indexTimeFormatter = null; } @SuppressWarnings("unchecked") List<Map<String, Object>> template = (List<Map<String, Object>>) settings.get("es_fields"); itemKey = new String[template.size()]; itemValue = new Value[template.size()]; int itemsIndex = 0; int outsideRiverCount = 0; for (int i = 0; i < template.size(); i++) { Map<String, Object> item = template.get(i); itemKey[itemsIndex] = (String) item.get("key"); boolean includeOutsideRiver = XContentMapValues.nodeBooleanValue(item.get("include-outside-river"), false); switch ((String) item.get("type")) { case "data": itemValue[itemsIndex] = new Data((String) item.get("value")); break; case "ipv4": itemValue[itemsIndex] = new Ipv4((String) item.get("format")); break; case "counter": { int min = XContentMapValues.nodeIntegerValue(item.get("min"), 0); int max = XContentMapValues.nodeIntegerValue(item.get("max"), 0); itemValue[itemsIndex] = new Count(min, max); } break; case "random": { int min = XContentMapValues.nodeIntegerValue(item.get("min"), 0); int max = XContentMapValues.nodeIntegerValue(item.get("max"), 0); itemValue[itemsIndex] = new RandomInt(min, max); } break; case "timestamp": String format = XContentMapValues.nodeStringValue(item.get("format"), null); itemValue[itemsIndex] = new Timestamper(clock, format); break; default: throw new IllegalArgumentException("unknown template item type " + (String) item.get("type")); } if (includeOutsideRiver) { itemValue[itemsIndex].includeOutsideRiver(); outsideRiverCount++; } itemsIndex++; } completeSources = new Object[itemsIndex * 2]; publishedSources = new Object[outsideRiverCount * 2]; }
From source file:org.iexhub.connectors.PDQQueryManager.java
License:Apache License
/** * @param livingSubjectBirthTime//from w w w.ja va 2 s.c om * @param dateOfBirth * @return */ private PRPAMT201306UV02LivingSubjectBirthTime setLivingSubjectBirthTime( PRPAMT201306UV02LivingSubjectBirthTime livingSubjectBirthTime, String dateOfBirth) { DateTimeFormatter formatter = DateTimeFormat.forPattern("MM/dd/yyyy"); DateTime dt = formatter.parseDateTime(dateOfBirth); StringBuilder timeBuilder = new StringBuilder(); timeBuilder.append(dt.getYear()); timeBuilder.append((dt.getMonthOfYear() < 10) ? ("0" + dt.getMonthOfYear()) : dt.getMonthOfYear()); timeBuilder.append((dt.getDayOfMonth() < 10) ? ("0" + dt.getDayOfMonth()) : dt.getDayOfMonth()); IVLTS date = new IVLTS(); date.setValue(timeBuilder.toString()); livingSubjectBirthTime.getValue().add(date); ST birthTimeSemanticsText = new ST(); birthTimeSemanticsText.getContent().add("LivingSubject.birthTime"); livingSubjectBirthTime.setSemanticsText(birthTimeSemanticsText); return livingSubjectBirthTime; }
From source file:org.iexhub.connectors.PIXManager.java
License:Apache License
/** * @param fhirPatientResource// www . j a v a 2s. c om * @return * @throws IOException */ public MCCIIN000002UV01 registerPatient(Patient fhirPatientResource) throws IOException { String dateOfBirth = (fhirPatientResource.getBirthDate() != null) ? fhirPatientResource.getBirthDateElement().getValueAsString() : null; String gender = (fhirPatientResource.getGender() == null) ? "" : (fhirPatientResource.getGender() .compareToIgnoreCase(AdministrativeGenderEnum.MALE.getCode()) == 0) ? "M" : ((fhirPatientResource.getGender() .compareToIgnoreCase(AdministrativeGenderEnum.FEMALE.getCode()) == 0) ? "F" : ((fhirPatientResource.getGender().compareToIgnoreCase( AdministrativeGenderEnum.OTHER.getCode()) == 0) ? "UN" : "")); if ((fhirPatientResource.getName().get(0).getFamilyAsSingleString() == null) || (fhirPatientResource.getName().get(0).getFamilyAsSingleString().length() == 0)) { throw new FamilyNameParamMissingException("FamilyName parameter is required"); } PRPAIN201301UV02 pRPA_IN201301UV02 = new PRPAIN201301UV02(); // ITS version... pRPA_IN201301UV02.setITSVersion("XML_1.0"); // ID... II messageId = new II(); messageId.setRoot(iExHubDomainOid); messageId.setExtension(UUID.randomUUID().toString()); pRPA_IN201301UV02.setId(messageId); // Creation time... DateTime dt = new DateTime(DateTimeZone.UTC); TS creationTime = new TS(); StringBuilder creationTimeBuilder = new StringBuilder(); creationTimeBuilder.append(dt.getYear()); creationTimeBuilder.append((dt.getMonthOfYear() < 10) ? ("0" + dt.getMonthOfYear()) : dt.getMonthOfYear()); creationTimeBuilder.append((dt.getDayOfMonth() < 10) ? ("0" + dt.getDayOfMonth()) : dt.getDayOfMonth()); creationTimeBuilder.append((dt.getHourOfDay() < 10) ? ("0" + dt.getHourOfDay()) : dt.getHourOfDay()); creationTimeBuilder .append((dt.getMinuteOfHour() < 10) ? ("0" + dt.getMinuteOfHour()) : dt.getMinuteOfHour()); creationTimeBuilder .append((dt.getSecondOfMinute() < 10) ? ("0" + dt.getSecondOfMinute()) : dt.getSecondOfMinute()); creationTime.setValue(creationTimeBuilder.toString()); pRPA_IN201301UV02.setCreationTime(creationTime); // Interaction ID... II interactionId = new II(); interactionId.setRoot("2.16.840.1.113883.1.6"); interactionId.setExtension("PRPA_IN201301UV02"); pRPA_IN201301UV02.setInteractionId(interactionId); // Processing code... CS processingCode = new CS(); processingCode.setCode("P"); pRPA_IN201301UV02.setProcessingCode(processingCode); // Processing mode code... CS processingModeCode = new CS(); processingModeCode.setCode("T"); pRPA_IN201301UV02.setProcessingModeCode(processingModeCode); // Accept ack code... CS acceptAckCode = new CS(); acceptAckCode.setCode("AL"); pRPA_IN201301UV02.setAcceptAckCode(acceptAckCode); // Create receiver... MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver(); receiver.setTypeCode(CommunicationFunctionType.RCV); MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device(); receiverDevice.setClassCode(EntityClassDevice.DEV); receiverDevice.setDeterminerCode("INSTANCE"); II receiverDeviceId = new II(); receiverDeviceId.setRoot(receiverApplicationName); receiverDevice.getId().add(receiverDeviceId); MCCIMT000100UV01Agent asAgent = new MCCIMT000100UV01Agent(); asAgent.getClassCode().add("AGNT"); MCCIMT000100UV01Organization representedOrganization = new MCCIMT000100UV01Organization(); representedOrganization.setDeterminerCode("INSTANCE"); representedOrganization.setClassCode("ORG"); II representedOrganizationId = new II(); representedOrganizationId.setRoot(PIXManager.receiverApplicationRepresentedOrganization); representedOrganization.getId().add(representedOrganizationId); asAgent.setRepresentedOrganization( objectFactory.createMCCIMT000100UV01AgentRepresentedOrganization(representedOrganization)); receiverDevice.setAsAgent(objectFactory.createMCCIMT000100UV01DeviceAsAgent(asAgent)); receiver.setDevice(receiverDevice); pRPA_IN201301UV02.getReceiver().add(receiver); // Create sender... MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender(); sender.setTypeCode(CommunicationFunctionType.SND); MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device(); senderDevice.setClassCode(EntityClassDevice.DEV); senderDevice.setDeterminerCode("INSTANCE"); II senderDeviceId = new II(); senderDeviceId.setRoot(PIXManager.iExHubSenderDeviceId); senderDevice.getId().add(senderDeviceId); MCCIMT000100UV01Agent senderAsAgent = new MCCIMT000100UV01Agent(); senderAsAgent.getClassCode().add("AGNT"); MCCIMT000100UV01Organization senderRepresentedOrganization = new MCCIMT000100UV01Organization(); senderRepresentedOrganization.setDeterminerCode("INSTANCE"); senderRepresentedOrganization.setClassCode("ORG"); II senderRepresentedOrganizationId = new II(); senderRepresentedOrganizationId.setRoot(PIXManager.iExHubDomainOid); senderRepresentedOrganization.getId().add(senderRepresentedOrganizationId); senderAsAgent.setRepresentedOrganization( objectFactory.createMCCIMT000100UV01AgentRepresentedOrganization(senderRepresentedOrganization)); senderDevice.setAsAgent(objectFactory.createMCCIMT000100UV01DeviceAsAgent(senderAsAgent)); sender.setDevice(senderDevice); pRPA_IN201301UV02.setSender(sender); PRPAIN201301UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201301UV02MFMIMT700701UV01Subject1(); // Create Registration Event... PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent(); registrationEvent.getClassCode().add("REG"); registrationEvent.getMoodCode().add("EVN"); registrationEvent.getNullFlavor().add("NA"); CS statusCode = new CS(); statusCode.setCode("active"); registrationEvent.setStatusCode(statusCode); PRPAIN201301UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201301UV02MFMIMT700701UV01Subject2(); subject1.setTypeCode(ParticipationTargetSubject.SBJ); // Create Patient... PRPAMT201301UV02Patient patient = new PRPAMT201301UV02Patient(); patient.getClassCode().add("PAT"); CS patientStatusCode = new CS(); patientStatusCode.setCode("active"); patient.setStatusCode(patientStatusCode); // Create PatientPerson... PRPAMT201301UV02Person patientPerson = new PRPAMT201301UV02Person(); // Other ID's specified... II constructedPatientId = null; if (fhirPatientResource.getIdentifier() != null) { for (IdentifierDt fhirId : fhirPatientResource.getIdentifier()) { if ((fhirId.getUse() != null) && (fhirId.getUse().equals(IdentifierUseEnum.OFFICIAL.getCode()))) { // This is the official identifier constructedPatientId = new II(); if ((fhirId.getSystem() == null) || (fhirId.getSystem().length() == 0)) { throw new PatientIdParamMissingException("Patient ID system missing"); } constructedPatientId.setRoot((fhirId.getSystem().toLowerCase().startsWith(uriPrefix)) ? fhirId.getSystem().replace(uriPrefix, "") : fhirId.getSystem()); constructedPatientId.setExtension(fhirId.getValue()); constructedPatientId.setAssigningAuthorityName(PIXManager.iExHubAssigningAuthority); patient.getId().add(constructedPatientId); } else { PRPAMT201301UV02OtherIDs asOtherId = new PRPAMT201301UV02OtherIDs(); asOtherId.getClassCode().add("SD"); II otherId = new II(); otherId.setRoot(fhirId.getSystemElement().getValueAsString()); otherId.setExtension(fhirId.getValue()); asOtherId.getId().add(otherId); COCTMT150002UV01Organization scopingOrg = new COCTMT150002UV01Organization(); scopingOrg.setClassCode("ORG"); scopingOrg.setDeterminerCode("INSTANCE"); II scopingOrgId = new II(); scopingOrgId.setRoot(fhirId.getSystemElement().getValueAsString()); scopingOrg.getId().add(scopingOrgId); asOtherId.setScopingOrganization(scopingOrg); patientPerson.getAsOtherIDs().add(asOtherId); } } } patientPerson.getName().add(populatePersonName(fhirPatientResource.getName().get(0))); if ((gender != null) && (gender.length() > 0)) { CE adminGenderCode = new CE(); adminGenderCode.setCode(gender); adminGenderCode.setCodeSystem("2.16.840.1.113883.5.1"); patientPerson.setAdministrativeGenderCode(adminGenderCode); } else { CE adminGenderCode = new CE(); adminGenderCode.getNullFlavor().add("UNK"); adminGenderCode.setCodeSystem("2.16.840.1.113883.5.1"); patientPerson.setAdministrativeGenderCode(adminGenderCode); } patientPerson.getClassCode().add("PSN"); patientPerson.setDeterminerCode("INSTANCE"); if ((fhirPatientResource.getTelecom() != null) && (!fhirPatientResource.getTelecom().isEmpty())) { for (ContactPointDt contactPoint : fhirPatientResource.getTelecom()) { // Add if telecom value is present only if (contactPoint.getValue() != null && !contactPoint.getValue().isEmpty()) { TEL contactPartyTelecom = new TEL(); contactPartyTelecom.setValue(contactPoint.getValue()); patientPerson.getTelecom().add(contactPartyTelecom); } } } if (dateOfBirth != null) { // Try several formats for date parsing... DateTimeFormatter formatter = null; DateTime birthDateTime = null; try { formatter = DateTimeFormat.forPattern("MM/dd/yyyy"); birthDateTime = formatter.parseDateTime(dateOfBirth); } catch (Exception e) { try { formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); birthDateTime = formatter.parseDateTime(dateOfBirth); } catch (Exception e2) { throw e2; } } StringBuilder birthDateBuilder = new StringBuilder(); birthDateBuilder.append(birthDateTime.getYear()); birthDateBuilder.append((birthDateTime.getMonthOfYear() < 10) ? ("0" + birthDateTime.getMonthOfYear()) : birthDateTime.getMonthOfYear()); birthDateBuilder.append((birthDateTime.getDayOfMonth() < 10) ? ("0" + birthDateTime.getDayOfMonth()) : birthDateTime.getDayOfMonth()); TS birthTime = new TS(); birthTime.setValue(birthDateBuilder.toString()); patientPerson.setBirthTime(birthTime); } JAXBElement<PRPAMT201301UV02Person> patientPersonElement = objectFactory .createPRPAMT201301UV02PatientPatientPerson(patientPerson); patient.setPatientPerson(patientPersonElement); // Create ProviderOrganization - set IExHub as provider if no careProvider specified in FHIR patient resource parameter... COCTMT150003UV03Organization providerOrganization = new COCTMT150003UV03Organization(); providerOrganization.setDeterminerCode("INSTANCE"); providerOrganization.setClassCode("ORG"); if ((fhirPatientResource.getCareProvider() != null) && (!fhirPatientResource.getCareProvider().isEmpty())) { for (ResourceReferenceDt resourceRef : fhirPatientResource.getCareProvider()) { if (resourceRef.getResource().getClass() == Organization.class) { Organization careProvider = (Organization) resourceRef.getResource(); // Provider ID II providerId = new II(); providerId.setRoot((careProvider.getId().getValueAsString().startsWith("#")) ? careProvider.getId().getValueAsString().substring(1) : careProvider.getId().getValueAsString()); providerOrganization.getId().add(providerId); // Provider name if ((careProvider.getName() != null) && (careProvider.getName().length() > 0)) { ON providerName = new ON(); providerName.getContent().add(careProvider.getName()); providerOrganization.getName().add(providerName); } // Create Contact Party if FHIR organization contacts are present... for (Contact fhirOrganizationContact : careProvider.getContact()) { COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty(); contactParty.setClassCode(RoleClassContact.CON); // Contact telecom(s) if ((fhirOrganizationContact.getTelecom() != null) && (!fhirOrganizationContact.getTelecom().isEmpty())) { for (ContactPointDt contactPoint : fhirOrganizationContact.getTelecom()) { TEL contactPartyTelecom = new TEL(); contactPartyTelecom.setValue(contactPoint.getValue()); contactParty.getTelecom().add(contactPartyTelecom); } } // Contact name if ((fhirOrganizationContact.getName() != null) && (!fhirOrganizationContact.getName().isEmpty())) { COCTMT150003UV03Person contactPerson = new COCTMT150003UV03Person(); contactPerson.getName().add(populatePersonName(fhirOrganizationContact.getName())); contactParty.setContactPerson( objectFactory.createCOCTMT150003UV03ContactPartyContactPerson(contactPerson)); } // Contact address(es) if ((careProvider.getAddress() != null) && (!careProvider.getAddress().isEmpty())) { for (AddressDt fhirAddr : careProvider.getAddress()) { contactParty.getAddr().add(populatePatientAddress(fhirAddr)); } } providerOrganization.getContactParty().add(contactParty); } } } } else { II providerId = new II(); providerId.setRoot(providerOrganizationOid); providerOrganization.getId().add(providerId); ON providerName = new ON(); providerName.getContent().add(providerOrganizationName); providerOrganization.getName().add(providerName); COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty(); contactParty.setClassCode(RoleClassContact.CON); TEL contactPartyTelecom = new TEL(); contactPartyTelecom.setValue(providerOrganizationContactTelecom); contactParty.getTelecom().add(contactPartyTelecom); providerOrganization.getContactParty().add(contactParty); } patient.setProviderOrganization(providerOrganization); subject1.setPatient(patient); registrationEvent.setSubject1(subject1); // Create Custodian info... MFMIMT700701UV01Custodian custodian = new MFMIMT700701UV01Custodian(); custodian.getTypeCode().add("CST"); COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity(); assignedEntity.setClassCode("ASSIGNED"); II assignedEntityId = new II(); assignedEntityId.setRoot(iExHubDomainOid); assignedEntity.getId().add(assignedEntityId); COCTMT090003UV01Organization assignedOrganization = new COCTMT090003UV01Organization(); assignedOrganization.setDeterminerCode("INSTANCE"); assignedOrganization.setClassCode("ORG"); EN organizationName = new EN(); organizationName.getContent().add("IHE Portal"); assignedOrganization.getName().add(organizationName); assignedEntity.setAssignedOrganization( objectFactory.createCOCTMT090003UV01AssignedEntityAssignedOrganization(assignedOrganization)); custodian.setAssignedEntity(assignedEntity); registrationEvent.setCustodian(custodian); // Set Subject info... subject.getTypeCode().add("SUBJ"); subject.setRegistrationEvent(registrationEvent); PRPAIN201301UV02MFMIMT700701UV01ControlActProcess controlAct = new PRPAIN201301UV02MFMIMT700701UV01ControlActProcess(); CD controlActProcessCode = new CD(); controlActProcessCode.setCode("PRPA_TE201301UV02"); controlActProcessCode.setCodeSystem("2.16.840.1.113883.1.6"); controlAct.setCode(controlActProcessCode); controlAct.setClassCode(ActClassControlAct.CACT); controlAct.setMoodCode(XActMoodIntentEvent.EVN); controlAct.getSubject().add(subject); pRPA_IN201301UV02.setControlActProcess(controlAct); logIti44AuditMsg(constructedPatientId.getExtension() + "^^^&" + constructedPatientId.getRoot() + "&" + PIXManager.iExHubAssigningAuthority); UUID logMsgId = null; if (logPixRequestMessages) { logMsgId = UUID.randomUUID(); OMElement requestElement = pixManagerStub.toOM(pRPA_IN201301UV02, pixManagerStub .optimizeContent(new javax.xml.namespace.QName("urn:hl7-org:v3", "PRPA_IN201301UV02")), new javax.xml.namespace.QName("urn:hl7-org:v3", "PRPA_IN201301UV02")); Files.write(Paths.get(logOutputPath + logMsgId.toString() + "_PIXRegisterPatientRequest.xml"), requestElement.toString().getBytes()); } MCCIIN000002UV01 response = pixManagerStub.pIXManager_PRPA_IN201301UV02(pRPA_IN201301UV02); if (logPixResponseMessages) { OMElement responseElement = pixManagerStub.toOM(response, pixManagerStub .optimizeContent(new javax.xml.namespace.QName("urn:hl7-org:v3", "MCCI_IN000002UV01")), new javax.xml.namespace.QName("urn:hl7-org:v3", "MCCI_IN000002UV01")); Files.write(Paths .get(logOutputPath + ((logMsgId == null) ? UUID.randomUUID().toString() : logMsgId.toString()) + "_PIXRegisterPatientResponse.xml"), responseElement.toString().getBytes()); } return response; }
From source file:org.iexhub.connectors.PIXManager.java
License:Apache License
/** * @param givenName/*from w w w. jav a 2 s . c o m*/ * @param familyName * @param middleName * @param dateOfBirth * @param gender * @param patientId * @return * @throws IOException */ public MCCIIN000002UV01 registerPatient(String givenName, String familyName, String middleName, String dateOfBirth, String gender, String patientId) throws IOException { if ((familyName == null) || (familyName.length() == 0)) { throw new FamilyNameParamMissingException("FamilyName parameter is required"); } PRPAIN201301UV02 pRPA_IN201301UV02 = new PRPAIN201301UV02(); // ITS version... pRPA_IN201301UV02.setITSVersion("XML_1.0"); // ID... II messageId = new II(); messageId.setRoot(iExHubDomainOid); messageId.setExtension(UUID.randomUUID().toString()); pRPA_IN201301UV02.setId(messageId); // Creation time... DateTime dt = new DateTime(DateTimeZone.UTC); TS creationTime = new TS(); StringBuilder creationTimeBuilder = new StringBuilder(); creationTimeBuilder.append(dt.getYear()); creationTimeBuilder.append((dt.getMonthOfYear() < 10) ? ("0" + dt.getMonthOfYear()) : dt.getMonthOfYear()); creationTimeBuilder.append((dt.getDayOfMonth() < 10) ? ("0" + dt.getDayOfMonth()) : dt.getDayOfMonth()); creationTimeBuilder.append((dt.getHourOfDay() < 10) ? ("0" + dt.getHourOfDay()) : dt.getHourOfDay()); creationTimeBuilder .append((dt.getMinuteOfHour() < 10) ? ("0" + dt.getMinuteOfHour()) : dt.getMinuteOfHour()); creationTimeBuilder .append((dt.getSecondOfMinute() < 10) ? ("0" + dt.getSecondOfMinute()) : dt.getSecondOfMinute()); creationTime.setValue(creationTimeBuilder.toString()); pRPA_IN201301UV02.setCreationTime(creationTime); // Interaction ID... II interactionId = new II(); interactionId.setRoot("2.16.840.1.113883.1.6"); interactionId.setExtension("PRPA_IN201301UV02"); pRPA_IN201301UV02.setInteractionId(interactionId); // Processing code... CS processingCode = new CS(); processingCode.setCode("P"); pRPA_IN201301UV02.setProcessingCode(processingCode); // Processing mode code... CS processingModeCode = new CS(); processingModeCode.setCode("T"); pRPA_IN201301UV02.setProcessingModeCode(processingModeCode); // Accept ack code... CS acceptAckCode = new CS(); acceptAckCode.setCode("AL"); pRPA_IN201301UV02.setAcceptAckCode(acceptAckCode); // Create receiver... MCCIMT000100UV01Receiver receiver = new MCCIMT000100UV01Receiver(); receiver.setTypeCode(CommunicationFunctionType.RCV); MCCIMT000100UV01Device receiverDevice = new MCCIMT000100UV01Device(); receiverDevice.setClassCode(EntityClassDevice.DEV); receiverDevice.setDeterminerCode("INSTANCE"); II receiverDeviceId = new II(); receiverDeviceId.setRoot(receiverApplicationName); receiverDevice.getId().add(receiverDeviceId); MCCIMT000100UV01Agent asAgent = new MCCIMT000100UV01Agent(); asAgent.getClassCode().add("AGNT"); MCCIMT000100UV01Organization representedOrganization = new MCCIMT000100UV01Organization(); representedOrganization.setDeterminerCode("INSTANCE"); representedOrganization.setClassCode("ORG"); II representedOrganizationId = new II(); representedOrganizationId.setRoot(PIXManager.receiverApplicationRepresentedOrganization); representedOrganization.getId().add(representedOrganizationId); asAgent.setRepresentedOrganization( objectFactory.createMCCIMT000100UV01AgentRepresentedOrganization(representedOrganization)); receiverDevice.setAsAgent(objectFactory.createMCCIMT000100UV01DeviceAsAgent(asAgent)); receiver.setDevice(receiverDevice); pRPA_IN201301UV02.getReceiver().add(receiver); // Create sender... MCCIMT000100UV01Sender sender = new MCCIMT000100UV01Sender(); sender.setTypeCode(CommunicationFunctionType.SND); MCCIMT000100UV01Device senderDevice = new MCCIMT000100UV01Device(); senderDevice.setClassCode(EntityClassDevice.DEV); senderDevice.setDeterminerCode("INSTANCE"); II senderDeviceId = new II(); senderDeviceId.setRoot(PIXManager.iExHubSenderDeviceId); senderDevice.getId().add(senderDeviceId); MCCIMT000100UV01Agent senderAsAgent = new MCCIMT000100UV01Agent(); senderAsAgent.getClassCode().add("AGNT"); MCCIMT000100UV01Organization senderRepresentedOrganization = new MCCIMT000100UV01Organization(); senderRepresentedOrganization.setDeterminerCode("INSTANCE"); senderRepresentedOrganization.setClassCode("ORG"); II senderRepresentedOrganizationId = new II(); senderRepresentedOrganizationId.setRoot(PIXManager.iExHubDomainOid); senderRepresentedOrganization.getId().add(senderRepresentedOrganizationId); senderAsAgent.setRepresentedOrganization( objectFactory.createMCCIMT000100UV01AgentRepresentedOrganization(senderRepresentedOrganization)); senderDevice.setAsAgent(objectFactory.createMCCIMT000100UV01DeviceAsAgent(senderAsAgent)); sender.setDevice(senderDevice); pRPA_IN201301UV02.setSender(sender); PRPAIN201301UV02MFMIMT700701UV01Subject1 subject = new PRPAIN201301UV02MFMIMT700701UV01Subject1(); // Create Registration Event... PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent registrationEvent = new PRPAIN201301UV02MFMIMT700701UV01RegistrationEvent(); registrationEvent.getClassCode().add("REG"); registrationEvent.getMoodCode().add("EVN"); registrationEvent.getNullFlavor().add("NA"); CS statusCode = new CS(); statusCode.setCode("active"); registrationEvent.setStatusCode(statusCode); PRPAIN201301UV02MFMIMT700701UV01Subject2 subject1 = new PRPAIN201301UV02MFMIMT700701UV01Subject2(); subject1.setTypeCode(ParticipationTargetSubject.SBJ); // Create Patient... PRPAMT201301UV02Patient patient = new PRPAMT201301UV02Patient(); patient.getClassCode().add("PAT"); II constructedPatientId = new II(); constructedPatientId.setRoot(PIXManager.patientIdAssigningAuthority); constructedPatientId.setExtension(UUID.randomUUID().toString()); constructedPatientId.setAssigningAuthorityName(PIXManager.iExHubAssigningAuthority); patient.getId().add(constructedPatientId); CS patientStatusCode = new CS(); patientStatusCode.setCode("active"); patient.setStatusCode(patientStatusCode); // Create PatientPerson... PRPAMT201301UV02Person patientPerson = new PRPAMT201301UV02Person(); // // Other ID's specified... // if (fhirIdentifiers != null) // { // for (IdentifierDt fhirId : fhirIdentifiers) // { // PRPAMT201301UV02OtherIDs asOtherId = new PRPAMT201301UV02OtherIDs(); // asOtherId.getClassCode().add("SD"); // II otherId = new II(); // otherId.setRoot(fhirId.getSystemElement().getValueAsString()); // otherId.setExtension(fhirId.getValue()); // asOtherId.getId().add(otherId); // // COCTMT150002UV01Organization scopingOrg = new COCTMT150002UV01Organization(); // scopingOrg.setClassCode("ORG"); // scopingOrg.setDeterminerCode("INSTANCE"); // II scopingOrgId = new II(); // scopingOrgId.setRoot(fhirId.getSystemElement().getValueAsString()); // scopingOrg.getId().add(scopingOrgId); // asOtherId.setScopingOrganization(scopingOrg); // // patientPerson.getAsOtherIDs().add(asOtherId); // } // } EnFamily enFamily = null; if ((familyName != null) && (familyName.length() > 0)) { enFamily = new EnFamily(); enFamily.getContent().add(familyName); } EnGiven enGiven = null; if ((givenName != null) && (givenName.length() > 0)) { enGiven = new EnGiven(); if ((middleName != null) && (middleName.length() > 0)) { enGiven.getContent().add(givenName + " " + middleName); } else { enGiven.getContent().add(givenName); } } PN patientName = new PN(); patientName.getContent().add(objectFactory.createENFamily(enFamily)); if (enGiven != null) { patientName.getContent().add(objectFactory.createENGiven(enGiven)); } patientPerson.getName().add(patientName); if ((gender != null) && (gender.length() > 0)) { CE adminGenderCode = new CE(); adminGenderCode.setCode(gender); adminGenderCode.setCodeSystem("2.16.840.1.113883.5.1"); patientPerson.setAdministrativeGenderCode(adminGenderCode); } else { CE adminGenderCode = new CE(); adminGenderCode.getNullFlavor().add("UNK"); adminGenderCode.setCodeSystem("2.16.840.1.113883.5.1"); patientPerson.setAdministrativeGenderCode(adminGenderCode); } patientPerson.getClassCode().add("PSN"); patientPerson.setDeterminerCode("INSTANCE"); if (dateOfBirth != null) { // Try several formats for date parsing... DateTimeFormatter formatter = null; DateTime birthDateTime = null; try { formatter = DateTimeFormat.forPattern("MM/dd/yyyy"); birthDateTime = formatter.parseDateTime(dateOfBirth); } catch (Exception e) { try { formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); birthDateTime = formatter.parseDateTime(dateOfBirth); } catch (Exception e2) { throw e2; } } StringBuilder birthDateBuilder = new StringBuilder(); birthDateBuilder.append(birthDateTime.getYear()); birthDateBuilder.append((birthDateTime.getMonthOfYear() < 10) ? ("0" + birthDateTime.getMonthOfYear()) : birthDateTime.getMonthOfYear()); birthDateBuilder.append((birthDateTime.getDayOfMonth() < 10) ? ("0" + birthDateTime.getDayOfMonth()) : birthDateTime.getDayOfMonth()); TS birthTime = new TS(); birthTime.setValue(birthDateBuilder.toString()); patientPerson.setBirthTime(birthTime); } JAXBElement<PRPAMT201301UV02Person> patientPersonElement = objectFactory .createPRPAMT201301UV02PatientPatientPerson(patientPerson); patient.setPatientPerson(patientPersonElement); // Create ProviderOrganization... COCTMT150003UV03Organization providerOrganization = new COCTMT150003UV03Organization(); providerOrganization.setDeterminerCode("INSTANCE"); providerOrganization.setClassCode("ORG"); II providerId = new II(); providerId.setRoot(providerOrganizationOid); providerOrganization.getId().add(providerId); ON providerName = new ON(); providerName.getContent().add(providerOrganizationName); providerOrganization.getName().add(providerName); COCTMT150003UV03ContactParty contactParty = new COCTMT150003UV03ContactParty(); contactParty.setClassCode(RoleClassContact.CON); TEL contactPartyTelecom = new TEL(); contactPartyTelecom.setValue(providerOrganizationContactTelecom); contactParty.getTelecom().add(contactPartyTelecom); providerOrganization.getContactParty().add(contactParty); patient.setProviderOrganization(providerOrganization); subject1.setPatient(patient); registrationEvent.setSubject1(subject1); // Create Custodian info... MFMIMT700701UV01Custodian custodian = new MFMIMT700701UV01Custodian(); custodian.getTypeCode().add("CST"); COCTMT090003UV01AssignedEntity assignedEntity = new COCTMT090003UV01AssignedEntity(); assignedEntity.setClassCode("ASSIGNED"); II assignedEntityId = new II(); assignedEntityId.setRoot(iExHubDomainOid); assignedEntity.getId().add(assignedEntityId); COCTMT090003UV01Organization assignedOrganization = new COCTMT090003UV01Organization(); assignedOrganization.setDeterminerCode("INSTANCE"); assignedOrganization.setClassCode("ORG"); EN organizationName = new EN(); organizationName.getContent().add("IHE Portal"); assignedOrganization.getName().add(organizationName); assignedEntity.setAssignedOrganization( objectFactory.createCOCTMT090003UV01AssignedEntityAssignedOrganization(assignedOrganization)); custodian.setAssignedEntity(assignedEntity); registrationEvent.setCustodian(custodian); // Set Subject info... subject.getTypeCode().add("SUBJ"); subject.setRegistrationEvent(registrationEvent); PRPAIN201301UV02MFMIMT700701UV01ControlActProcess controlAct = new PRPAIN201301UV02MFMIMT700701UV01ControlActProcess(); CD controlActProcessCode = new CD(); controlActProcessCode.setCode("PRPA_TE201301UV02"); controlActProcessCode.setCodeSystem("2.16.840.1.113883.1.6"); controlAct.setCode(controlActProcessCode); controlAct.setClassCode(ActClassControlAct.CACT); controlAct.setMoodCode(XActMoodIntentEvent.EVN); controlAct.getSubject().add(subject); pRPA_IN201301UV02.setControlActProcess(controlAct); logIti44AuditMsg( patientId + "^^^&" + PIXManager.iExHubDomainOid + "&" + PIXManager.iExHubAssigningAuthority); UUID logMsgId = null; if (logPixRequestMessages) { logMsgId = UUID.randomUUID(); OMElement requestElement = pixManagerStub.toOM(pRPA_IN201301UV02, pixManagerStub .optimizeContent(new javax.xml.namespace.QName("urn:hl7-org:v3", "PRPA_IN201301UV02")), new javax.xml.namespace.QName("urn:hl7-org:v3", "PRPA_IN201301UV02")); Files.write(Paths.get(logOutputPath + logMsgId.toString() + "_PIXRegisterPatientRequest.xml"), requestElement.toString().getBytes()); } MCCIIN000002UV01 response = pixManagerStub.pIXManager_PRPA_IN201301UV02(pRPA_IN201301UV02); if (logPixResponseMessages) { OMElement responseElement = pixManagerStub.toOM(response, pixManagerStub .optimizeContent(new javax.xml.namespace.QName("urn:hl7-org:v3", "MCCI_IN000002UV01")), new javax.xml.namespace.QName("urn:hl7-org:v3", "MCCI_IN000002UV01")); Files.write(Paths .get(logOutputPath + ((logMsgId == null) ? UUID.randomUUID().toString() : logMsgId.toString()) + "_PIXRegisterPatientResponse.xml"), responseElement.toString().getBytes()); } return response; }
From source file:org.igov.service.business.process.ProcessSubjectService.java
/** * ??//from w w w. ja v a2s .c o m * * @param snID_Process_Activiti * @param sLogin * @param sDatePlan * @param nOrder * @return */ public ProcessSubject setProcessSubject(String snID_Process_Activiti, String sLogin, String sDatePlan, Long nOrder) { DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MM-yyyy"); DateTime dtDatePlan = formatter.parseDateTime(sDatePlan); ProcessSubjectStatus processSubjectStatus = processSubjectStatusDao.findByIdExpected(1L); return processSubjectDao.setProcessSubject(snID_Process_Activiti, sLogin, dtDatePlan, nOrder, processSubjectStatus); }
From source file:org.igov.service.business.process.ProcessSubjectService.java
/** * //from w ww . j a v a 2 s .co m * * @param snID_Process_Activiti * @param sDatePlan * @return */ public ProcessSubject setProcessSubjectDatePlan(String snID_Process_Activiti, String sDatePlan) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); DateTime dtDatePlan = formatter.parseDateTime(sDatePlan); return processSubjectDao.setProcessSubjectDatePlan(snID_Process_Activiti, dtDatePlan); }
From source file:org.ihtsdo.otf.snomed.loader.Rf2SnapshotAuditor.java
License:Apache License
public void audit(String file) { LOGGER.debug("Starting to audit file {}", file); long start = System.currentTimeMillis(); long totalRow = 0; //need to change implementation from super csv to java io as RF2 description has buggy quotes BufferedReader reader = null; try {// w ww . jav a2 s . c o m if (StringUtils.isBlank(file)) { throw new IllegalArgumentException("Please check file supplied."); } else if (file.endsWith(".gz")) { reader = new BufferedReader( new InputStreamReader(new GZIPInputStream(new FileInputStream(file)), "utf-8")); } else { reader = new BufferedReader(new FileReader(file)); } LOGGER.debug("Starting to load file {}", file); String line; beginTx(); int row = -1; DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd"); while ((line = reader.readLine()) != null) { row++; LOGGER.debug("Processing rowNo={} ", row); if (StringUtils.isEmpty(line)) { LOGGER.debug("rowNo={} , {} is empty skipping", row, line); continue; } String[] columns = StringUtils.splitByWholeSeparator(line, "\t"); if (columns != null && columns.length == 9 && row != 0) { if (isReload) { Vertex v = getVertex(g, columns[0]); if (v != null) { LOGGER.debug("Not Processing line={}, rowNo={} as record already loaded", line, row); continue; } } LOGGER.debug("Processing rowNo={} , {}", row, line); Rf2Description desc = new Rf2Description(); //id effectiveTime active moduleId conceptId languageCode typeId term caseSignificanceId desc.setId(columns[0]); desc.setEffectiveTime(fmt.parseDateTime(columns[1])); desc.setActive(columns[2]); desc.setModuleId(columns[3]); desc.setConceptId(columns[4]); desc.setLanguageCode(columns[5]); desc.setTypeId(columns[6]); desc.setTerm(columns[7]); desc.setCaseSignificanceId(columns[8]); if (!isConceptTitleExist(desc)) { auditDescription(desc); } else if (!StringUtils.isEmpty(subType) && subType.equalsIgnoreCase(descMap.get(desc.getTypeId()).toString()) && !isSubTypeRelationExist(desc)) { LOGGER.debug("Processing row {} of subType {}", row, subType); processDescription(desc); } else { LOGGER.debug("Not processing row {} of description id {}", row, desc.getId()); } } else { LOGGER.debug("rowNo={}, {} does not have required columns, skipping", row, line); continue; } commit(row); } LOGGER.info("Commiting remaining data"); g.commit();//remaining operation commit totalRow = row; } catch (IOException e) { g.rollback(); // TODO Auto-generated catch block e.printStackTrace(); throw new RuntimeException("Can not process file", e); } catch (Exception e) { LOGGER.error("Transaction rolledback"); g.rollback(); e.printStackTrace(); throw new RuntimeException(e); } finally { if (reader != null) { try { LOGGER.info("Closing IO resources"); reader.close(); } catch (IOException e) { LOGGER.error("Error closing bean reader"); e.printStackTrace(); } } } LOGGER.info("Total row {} processed in {} minute ", totalRow, ((System.currentTimeMillis() - start) / 60000)); }