/** * @see ObsService#getObservationsByPersonAndConcept(Person,Concept) */ @Test public void getObservationsByPersonAndConcept_shouldNotFailWithNullPersonParameter() { ObsService obsService = Context.getObsService(); obsService.getObservationsByPersonAndConcept(null, new Concept(7)); }
List<Obs> obssExit = Context.getObsService().getObservationsByPersonAndConcept(patient, reasonForExit); if (obssExit != null) { if (obssExit.size() > 1) {
/** * @see ObsService#getObservationsByPersonAndConcept(Person,Concept) */ @Test public void getObservationsByPersonAndConcept_shouldGetObservationsMatchingPersonAndQuestion() { ObsService obsService = Context.getObsService(); List<Obs> obss = obsService.getObservationsByPersonAndConcept(new Person(7), new Concept(5089)); Assert.assertEquals(3, obss.size()); Assert.assertEquals(16, obss.get(0).getObsId().intValue()); Assert.assertEquals(10, obss.get(1).getObsId().intValue()); Assert.assertEquals(7, obss.get(2).getObsId().intValue()); }
List<Obs> obssDeath = Context.getObsService().getObservationsByPersonAndConcept(patient, causeOfDeath); if (obssDeath != null) { if (obssDeath.size() > 1) {
Assert.assertEquals(0, obsService.getObservationsByPersonAndConcept(patient, concept).size()); router.processMessage(hl7message); List<Obs> obss = obsService.getObservationsByPersonAndConcept(patient, concept);
cal.set(2008, Calendar.FEBRUARY, 29, 0, 0, 0); Date returnVisitDate = cal.getTime(); List<Obs> returnVisitDateObsForPatient3 = obsService.getObservationsByPersonAndConcept(patient, returnVisitDateConcept); assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient3.size());
cal.set(2008, Calendar.FEBRUARY, 1, 0, 0, 0); Date returnVisitDate = cal.getTime(); List<Obs> returnVisitDateObsForPatient2 = obsService.getObservationsByPersonAndConcept(patient, returnVisitDateConcept); assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient2.size()); List<Obs> contactMethodObsForPatient2 = obsService.getObservationsByPersonAndConcept(patient, contactMethod); assertEquals("There should be a contact method", 1, contactMethodObsForPatient2.size()); Obs firstContactMethodObs = (Obs) contactMethodObsForPatient2.toArray()[0];
/** * @throws HL7Exception * @see HL7Service#processHL7Message(Message) */ @Test public void processHL7Message_shouldSaveHl7MessageToTheDatabase() throws HL7Exception { executeDataSet("org/openmrs/hl7/include/ORUTest-initialData.xml"); HL7Service hl7service = Context.getHL7Service(); Message message = hl7service .parseHL7String("MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||3^^^^||John3^Doe^||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206\r" + "OBX|2|DT|5096^RETURN VISIT DATE^99DCT||20080229|||||||||20080212"); Message result = hl7service.processHL7Message(message); Assert.assertNotNull(result); Concept returnVisitDateConcept = new Concept(5096); Calendar cal = Calendar.getInstance(); cal.set(2008, Calendar.FEBRUARY, 29, 0, 0, 0); List<Obs> returnVisitDateObsForPatient3 = Context.getObsService().getObservationsByPersonAndConcept(new Patient(3), returnVisitDateConcept); assertEquals("There should be a return visit date", 1, returnVisitDateObsForPatient3.size()); }
/** * @see ORUR01Handler#parseObs(Encounter,OBX,OBR,String) */ @Test public void parseObs_shouldAddCommentsToAnObservationGroup() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||23^FOOD CONSTRUCT^99DCT\r" + "NTE|1|L|This is a comment\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||1|||||||||20080206\r" + "NTE|1|L|This should not be considered :-)"; List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(23)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(23)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals("This is a comment", newObservation.getComment()); }
List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497));
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumericAndTheAnswerIsEither0Or1() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||1|||||||||20080206"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(1, newObservation.getValueNumeric().intValue()); }
/** * @see ConceptService#mapConceptProposalToConcept(ConceptProposal,Concept,Locale) */ @Test public void mapConceptProposalToConcept_shouldNotSetValueCodedNameWhenAddConceptIsSelected() { ConceptProposal cp = conceptService.getConceptProposal(2); Assert.assertEquals(OpenmrsConstants.CONCEPT_PROPOSAL_UNMAPPED, cp.getState()); final Concept civilStatusConcept = conceptService.getConcept(4); final int mappedConceptId = 6; Assert.assertTrue(Context.getObsService().getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), civilStatusConcept).isEmpty()); Concept mappedConcept = conceptService.getConcept(mappedConceptId); cp.setObsConcept(civilStatusConcept); cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_CONCEPT); conceptService.mapConceptProposalToConcept(cp, mappedConcept, null); mappedConcept = conceptService.getConcept(mappedConceptId); List<Obs> observations = Context.getObsService().getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), civilStatusConcept); Assert.assertEquals(1, observations.size()); Obs obs = observations.get(0); Assert.assertNull(obs.getValueCodedName()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_NumericForObsIfQuestionDatatypeIsNumeric() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||450|||||||||20080206"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(450, newObservation.getValueNumeric().intValue()); }
List<Obs> obsForPatient = Context.getObsService().getObservationsByPersonAndConcept(patient, question); assertEquals(1, obsForPatient.size()); // there should be 1 obs now for
/** * @see ORUR01Handler#parseObs(Encounter,OBX,OBR,String) */ @Test public void parseObs_shouldAddCommentsToAnObservationFromNTESegments() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|1|NM|5497^CD4, BY FACS^99DCT||1|||||||||20080206\r" + "NTE|1|L|This is a comment"; // the expected question for the obs in the hl7 message has to be // numeric Assert.assertEquals("Numeric", Context.getConceptService().getConcept(5497).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(5497)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals("This is a comment", newObservation.getComment()); }
/** * @see ORUR01Handler#processMessage(Message) */ @Test public void processMessage_shouldSetValue_CodedMatchingABooleanConceptForObsIfTheAnswerIs0Or1AndQuestionDatatypeIsCoded() throws Exception { ObsService os = Context.getObsService(); String hl7string = "MSH|^~\\&|FORMENTRY|AMRS.ELD|HL7LISTENER|AMRS.ELD|20080226102656||ORU^R01|JqnfhKKtouEz8kzTk6Zo|P|2.5|1||||||||16^AMRS.ELD.FORMID\r" + "PID|||7^^^^||Collet^Test^Chebaskwony||\r" + "PV1||O|1^Unknown Location||||1^Super User (1-8)|||||||||||||||||||||||||||||||||||||20080212|||||||V\r" + "ORC|RE||||||||20080226102537|1^Super User\r" + "OBR|1|||1238^MEDICAL RECORD OBSERVATIONS^99DCT\r" + "OBX|2|NM|21^CIVIL STATUS^99DCT||1|||||||||20080206"; // the expected question for the obs in the hl7 message has to be coded Assert.assertEquals("Coded", Context.getConceptService().getConcept(21).getDatatype().getName()); List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); // hacky way to get the newly added obs and make tests on it List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(21)); Obs newObservation = null; for (Obs newObs : newList) { if (!oldList.contains(newObs) && !newObs.isObsGrouping()) { newObservation = newObs; } } Assert.assertEquals(Context.getConceptService().getTrueConcept(), newObservation.getValueCoded()); }
/** * @see ConceptService#mapConceptProposalToConcept(ConceptProposal,Concept,Locale) */ @Test public void mapConceptProposalToConcept_shouldSetValueCodedNameWhenAddSynonymIsSelected() { ConceptProposal cp = conceptService.getConceptProposal(2); Assert.assertEquals(OpenmrsConstants.CONCEPT_PROPOSAL_UNMAPPED, cp.getState()); final Concept civilStatusConcept = conceptService.getConcept(4); final int mappedConceptId = 6; final String finalText = "Weight synonym"; Assert.assertTrue(Context.getObsService().getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), civilStatusConcept).isEmpty()); Concept mappedConcept = conceptService.getConcept(mappedConceptId); mappedConcept.addDescription(new ConceptDescription("some description",Context.getLocale())); cp.setFinalText(finalText); cp.setObsConcept(civilStatusConcept); cp.setState(OpenmrsConstants.CONCEPT_PROPOSAL_SYNONYM); conceptService.mapConceptProposalToConcept(cp, mappedConcept, null); mappedConcept = conceptService.getConcept(mappedConceptId); List<Obs> observations = Context.getObsService().getObservationsByPersonAndConcept(cp.getEncounter().getPatient(), civilStatusConcept); Assert.assertEquals(1, observations.size()); Obs obs = observations.get(0); Assert.assertNotNull(obs.getValueCodedName()); Assert.assertEquals(finalText, obs.getValueCodedName().getName()); }
List<Obs> oldList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18)); Message hl7message = parser.parse(hl7string); router.processMessage(hl7message); List<Obs> newList = os.getObservationsByPersonAndConcept(new Person(7), new Concept(18)); Obs newObservation = null; for (Obs newObs : newList) {
@Override public void testResults(SubmissionResults results) { results.assertNoErrors(); List<Obs> obsList = os.getObservationsByPersonAndConcept(results.getPatient(), cs.getConcept("4200")); List<Obs> obsDeathList = os.getObservationsByPersonAndConcept(results.getPatient(), cs.getConcept("4300")); Assert.assertEquals(obsList.size(),1); Assert.assertEquals(obsDeathList.size(),1); Assert.assertEquals("PATIENT DIED",obsList.get(0).getValueCoded().getDisplayString()); Assert.assertEquals(dateAsString(date),dateAsString(obsList.get(0).getObsDatetime())); Assert.assertEquals("STROKE",obsDeathList.get(0).getValueCoded().getDisplayString()); Assert.assertEquals(null,obsList.get(0).getValueText()); }
@Override public void testResults(SubmissionResults results) { results.assertNoErrors(); List<Obs> obsList = os.getObservationsByPersonAndConcept(results.getPatient(), cs.getConcept("4200")); List<Obs> obsDeathList = os.getObservationsByPersonAndConcept(results.getPatient(), cs.getConcept("4300")); Assert.assertEquals(obsList.size(),1); Assert.assertEquals(obsDeathList.size(),1); Assert.assertEquals("PATIENT DIED",obsList.get(0).getValueCoded().getDisplayString()); Assert.assertEquals(dateAsString(date),dateAsString(obsList.get(0).getObsDatetime())); Assert.assertEquals("OTHER NON-CODED",obsDeathList.get(0).getValueCoded().getDisplayString()); Assert.assertEquals("Died from cancer",obsDeathList.get(0).getValueText()); }